Skip to content

Commit 0c5436c

Browse files
support exec args (#2272)
* support exec args * update book * code review * code review
1 parent 974dd0a commit 0c5436c

File tree

14 files changed

+337
-439
lines changed

14 files changed

+337
-439
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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/'"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.expected
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.16
55
require (
66
github.com/cpuguy83/go-md2man/v2 v2.0.0
77
github.com/go-errors/errors v1.4.0
8+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
89
github.com/igorsobreira/titlecase v0.0.0-20140109233139-4156b5b858ac
910
github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f
1011
github.com/posener/complete/v2 v2.0.1-alpha.12

internal/docs/generated/fndocs/docs.go

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/fnresult/v1alpha2/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type Result struct {
2626
// Image and Exec are mutually exclusive
2727
Image string `yaml:"image,omitempty"`
2828
// 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.
2931
ExecPath string `yaml:"exec,omitempty"`
3032
// TODO(droot): This is required for making structured results subpackage aware.
3133
// Enable this once test harness supports filepath based assertions.

site/book/05-developing-functions/03-developing-in-Typescript.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ Currently supported platforms: amd64 Linux/Mac
9494
```
9595

9696
```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
10098
```
10199

102100
As the name suggests, this function added the given label to all `Namespace`
@@ -142,9 +140,7 @@ Currently supported platforms: amd64 Linux/Mac
142140
1. Run `validate-rolebinding` on `example-configs`.
143141

144142
```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]
148144
```
149145

150146
Look at the changes made by the function:
@@ -219,9 +215,7 @@ Currently supported platforms: amd64 Linux/Mac
219215
1. Run `expand-team-cr` on `example-configs`.
220216

221217
```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"
225219
```
226220

227221
Look at the changes made by the function:

site/reference/cli/fn/eval/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ fn-args:
6565
the key of an already exported environment variable.
6666
6767
--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.
7273
7374
--fn-config:
7475
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
146147
$ kpt fn eval DIR --exec ./my-fn
147148
```
148149

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+
149156
```shell
150157
# execute container my-fn on the resources in DIR directory,
151158
# save structured results in /tmp/my-results dir and write output back to DIR

site/sdk/ts-guide.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,11 @@ runtime.
150150

151151
### Steps
152152

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-
161153
1. Pass the path to the appropriate executable for your OS when running kpt
162154
using the exec runtime.
163155

164156
```shell
165-
$ kpt fn eval DIR --exec ./my_func_run-macos
157+
$ kpt fn eval DIR --exec "node dist/my_func_run.js"
166158
```
167159

168160
## Build and push container images

0 commit comments

Comments
 (0)