File tree Expand file tree Collapse file tree 14 files changed +337
-439
lines changed
e2e/testdata/fn-eval/exec-function-with-args
internal/docs/generated/fndocs
pkg/api/fnresult/v1alpha2
book/05-developing-functions
cmdconfig/commands/cmdeval Expand file tree Collapse file tree 14 files changed +337
-439
lines changed Original file line number Diff line number Diff line change
1
+ diff --git a/resources.yaml b/resources.yaml
2
+ index e8ae6bb..297b99f 100644
3
+ --- a/resources.yaml
4
+ +++ b/resources.yaml
5
+ @@ -15,7 +15,7 @@ apiVersion: apps/v1
6
+ kind: Deployment
7
+ metadata:
8
+ name: nginx-deployment
9
+ - namespace: foo
10
+ + namespace: bar
11
+ spec:
12
+ replicas: 3
13
+ ---
14
+ @@ -23,6 +23,6 @@ apiVersion: custom.io/v1
15
+ kind: Custom
16
+ metadata:
17
+ name: custom
18
+ - namespace: foo
19
+ + namespace: bar
20
+ spec:
21
+ image: nginx:1.2.3
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # Copyright 2021 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ set -eo pipefail
17
+
18
+ kpt fn eval --exec " sed -e 's/foo/bar/'"
Original file line number Diff line number Diff line change
1
+ .expected
Original file line number Diff line number Diff line change
1
+ # Copyright 2021 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ apiVersion : apps/v1
15
+ kind : Deployment
16
+ metadata :
17
+ name : nginx-deployment
18
+ namespace : foo
19
+ spec :
20
+ replicas : 3
21
+ ---
22
+ apiVersion : custom.io/v1
23
+ kind : Custom
24
+ metadata :
25
+ name : custom
26
+ namespace : foo
27
+ spec :
28
+ image : nginx:1.2.3
Original file line number Diff line number Diff line change 5
5
require (
6
6
github.com/cpuguy83/go-md2man/v2 v2.0.0
7
7
github.com/go-errors/errors v1.4.0
8
+ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
8
9
github.com/igorsobreira/titlecase v0.0.0-20140109233139-4156b5b858ac
9
10
github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f
10
11
github.com/posener/complete/v2 v2.0.1-alpha.12
Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ type Result struct {
26
26
// Image and Exec are mutually exclusive
27
27
Image string `yaml:"image,omitempty"`
28
28
// ExecPath is the the absolute os-specific path to the executable file
29
+ // If user provides an executable file with commands, ExecPath should
30
+ // contain the entire input string.
29
31
ExecPath string `yaml:"exec,omitempty"`
30
32
// TODO(droot): This is required for making structured results subpackage aware.
31
33
// Enable this once test harness supports filepath based assertions.
Original file line number Diff line number Diff line change @@ -94,9 +94,7 @@ Currently supported platforms: amd64 Linux/Mac
94
94
```
95
95
96
96
``` shell
97
- $ kpt fn source $CONFIGS \
98
- | node dist/label_namespace_run.js -d label_name=color -d label_value=orange \
99
- | kpt fn sink $CONFIGS
97
+ $ kpt fn eval $CONFIGS --exec " node dist/label_namespace_run.js" -- label_name=color label_value=orange
100
98
```
101
99
102
100
As the name suggests, this function added the given label to all ` Namespace `
@@ -142,9 +140,7 @@ Currently supported platforms: amd64 Linux/Mac
142
140
1 . Run ` validate-rolebinding ` on ` example-configs ` .
143
141
144
142
``` shell
145
- $ kpt fn source $CONFIGS \
146
- | node dist/validate_rolebinding_run.js -d
[email protected] \
147
- | kpt fn sink $CONFIGS
143
+ $ kpt fn
eval $CONFIGS --exec
" node dist/validate_rolebinding_run.js" --
[email protected]
148
144
```
149
145
150
146
Look at the changes made by the function:
@@ -219,9 +215,7 @@ Currently supported platforms: amd64 Linux/Mac
219
215
1 . Run ` expand-team-cr ` on ` example-configs ` .
220
216
221
217
``` shell
222
- $ kpt fn source $CONFIGS \
223
- | node dist/expand_team_cr_run.js \
224
- | kpt fn sink $CONFIGS
218
+ $ kpt fn eval $CONFIGS --exec " node dist/expand_team_cr_run.js"
225
219
```
226
220
227
221
Look at the changes made by the function:
Original file line number Diff line number Diff line change @@ -65,10 +65,11 @@ fn-args:
65
65
the key of an already exported environment variable.
66
66
67
67
--exec:
68
- Path to the local executable binary to execute as a function. `eval` executes
69
- only one function, so do not use `--image` flag with this flag. This is useful
70
- for testing function locally during development. It enables faster dev iterations
71
- by avoiding the function to be published as container image.
68
+ Path to the local executable binary to execute as a function. Quotes are needed
69
+ if the executable requires arguments. `eval` executes only one function, so do
70
+ not use `--image` flag with this flag. This is useful for testing function locally
71
+ during development. It enables faster dev iterations by avoiding the function to
72
+ be published as container image.
72
73
73
74
--fn-config:
74
75
Path to the file containing `functionConfig` for the function.
@@ -146,6 +147,12 @@ $ kpt fn eval DIR -i gcr.io/example.com/my-fn:v1.0.0 -- foo=bar
146
147
$ kpt fn eval DIR --exec ./my-fn
147
148
```
148
149
150
+ ``` shell
151
+ # execute executable my-fn with arguments on the resources in DIR directory and
152
+ # write output back to DIR
153
+ $ kpt fn eval DIR --exec " ./my-fn arg1 arg2"
154
+ ```
155
+
149
156
``` shell
150
157
# execute container my-fn on the resources in DIR directory,
151
158
# save structured results in /tmp/my-results dir and write output back to DIR
Original file line number Diff line number Diff line change @@ -150,19 +150,11 @@ runtime.
150
150
151
151
### Steps
152
152
153
- 1 . Use the pkg CLI to create an executable from your function's distributable
154
- file. For a ` my_fn ` function built using the typescript SDK, this is
155
- ` dist/my_fn_run.js ` .
156
-
157
- ``` shell
158
- $ npx pkg dist/my_func_run.js
159
- ```
160
-
161
153
1 . Pass the path to the appropriate executable for your OS when running kpt
162
154
using the exec runtime.
163
155
164
156
``` shell
165
- $ kpt fn eval DIR --exec . /my_func_run-macos
157
+ $ kpt fn eval DIR --exec " node dist /my_func_run.js "
166
158
```
167
159
168
160
## Build and push container images
You can’t perform that action at this time.
0 commit comments