@@ -13,7 +13,7 @@ docker run gcr.io/kpt-functions-demo/my-func:dev --help
1313```
1414
1515In order do something useful with a function, we need to compose a [ Pipeline] [ concept-pipeline ] with a
16- Source and a Sink function.
16+ source and a sink function.
1717
1818This guide covers two approaches to running a pipeline of functions:
1919
@@ -24,7 +24,7 @@ You can also use a container-based workflow orchestrator like [Cloud Build][clou
2424
2525## Using ` kpt fn `
2626
27- ` kpt fn ` provides utilities for working with configuration, including running KPT functions.
27+ ` kpt ` CLI provides utilities for working with configuration, including running KPT functions.
2828
2929### Installing ` kpt ` CLI
3030
@@ -112,86 +112,20 @@ kpt fn run --help
112112
113113## Using ` docker run `
114114
115- We can use any Source and Sink function to compose a pipeline. Here, we'll use ` read-yaml ` and ` write-yaml `
116- functions from the [ KPT functions catalog] [ catalog ] .
117-
118- Pull the images:
119-
120- ``` sh
121- docker pull gcr.io/kpt-functions/read-yaml
122- docker pull gcr.io/kpt-functions/write-yaml
123- ```
124-
125- You'll also need some source configuration. You can try this example configuration:
126-
127- ``` sh
128- git clone --depth 1
[email protected] :GoogleContainerTools/kpt-functions-sdk.git
129- cd kpt-functions-sdk/example-configs
130- ```
131-
132- With these tools prepared, construct your pipeline like so:
133-
134- 1 . Run the ` read-yaml ` function and view its output by piping to the ` less ` command:
135-
136- ``` sh
137- docker run -i -u $( id -u) -v $( pwd) :/source gcr.io/kpt-functions/read-yaml -i /dev/null -d source_dir=/source |
138- less
139- ```
140-
141- 1 . Include your function in the pipeline:
142-
143- ``` sh
144- docker run -i -u $( id -u) -v $( pwd) :/source gcr.io/kpt-functions/read-yaml -i /dev/null -d source_dir=/source |
145- docker run -i gcr.io/kpt-functions-demo/my-func:dev |
146- less
147- ```
148-
149- During development, you can run your function directly using ` node ` to avoid having to rebuild
150- the docker image on every change:
151-
152- ``` sh
153- docker run -i -u $( id -u) -v $( pwd) :/source gcr.io/kpt-functions/read-yaml -i /dev/null -d source_dir=/source |
154- node dist/my_func_run.js |
155- less
156- ```
157-
158- 1 . To persist the changes on the file system, pipe the output to the ` write-yaml ` function:
159-
160- ``` sh
161- docker run -i -u $( id -u) -v $( pwd) :/source gcr.io/kpt-functions/read-yaml -i /dev/null -d source_dir=/source |
162- docker run -i gcr.io/kpt-functions-demo/my-func:dev |
163- docker run -i -u $( id -u) -v $( pwd) :/sink gcr.io/kpt-functions/write-yaml -o /dev/null -d sink_dir=/sink -d overwrite=true
164- ```
165-
166- 1 . See the changes made to the configs directory:
167-
168- ``` sh
169- git status
170- ```
171-
172- ### Understanding Docker Flags
173-
174- - ` -u ` : By default, docker containers run as a non-privileged user. Privileged actions, like
175- filesystem access or calls to the network, require escalated access. Note the example usages of
176- ` read-yaml ` , which include ` docker run -u $(id -u) ` , running docker with your user ID.
177- - ` -v ` : Filesystem access requires mounting your container's filesystem onto your local
178- filesystem. For example, the ` read-yaml ` command includes the following: ` -v $(pwd):/source ` . This connects
179- the container's ` /source ` directory to the current directory on your filesystem.
180- - ` -i ` : This flag keeps STDIN open for use in pipelines.
115+ You can run a pipeline of KPT functions using only ` docker run ` .
181116
182117### Example 1
183118
184- In this example, we'll use ` label_namespace.ts ` function (Find the source [ here] [ label-namespace ] ).
185-
186119Begin by running the function with the ` --help ` option:
187120
188121``` sh
189122docker run gcr.io/kpt-functions/label-namespace --help
190123```
191124
192- The ` label_namespace ` function is configured with a ` functionConfig ` of kind ` ConfigMap ` . It takes the keys
193- ` label_name ` and ` label_value ` . The function adds the label ` [label_name]: [label_value] ` to the
194- ` Namespace ` objects in the input.
125+ The ` label_namespace ` function is parameterized with a ` functionConfig ` of kind ` ConfigMap ` . It labels
126+ the ` Namespace ` objects in the input with the given given ` label_name ` and ` label_value ` .
127+
128+ Let's explore different ways of invoking this functions.
195129
196130#### functionConfig from a file
197131
@@ -209,10 +143,10 @@ metadata:
209143EOF
210144```
211145
212- separate from the input configuration data :
146+ For now, let's use a hardcoded input containing two ` Namespace ` and one ` ResourceQuota ` objects :
213147
214148``` sh
215- cat > /tmp/input2 .yaml << EOF
149+ cat > /tmp/input .yaml << EOF
216150apiVersion: v1
217151kind: List
218152items:
@@ -246,42 +180,66 @@ items:
246180EOF
247181```
248182
249- This ` List ` object defines two Namespaces and a ResourceQuota. In a dockerized pipeline of
250- kpt-functions, we'd read the file in via a source function such as ` read-yaml ` .
251- For now, we'll use a bash redirection:
183+ Running the function, you should see the mutated ` List ` printed to stdout:
252184
253185``` sh
254- docker run -i -u $( id -u) -v /tmp/fc.yaml :/tmp/fc.yaml gcr.io/kpt-functions/label-namespace -f /tmp/fc .yaml < /tmp/input2 .yaml
186+ docker run -i -u $( id -u) -v /tmp:/tmp gcr.io/kpt-functions/label-namespace -i /tmp/input .yaml -f /tmp/fc .yaml
255187```
256188
257189#### functionConfig from literal values
258190
259191Key/value parameters can also be assigned inline, like so:
260192
261193``` sh
262- docker run -i gcr.io/kpt-functions/label-namespace -d label_name=color -d label_value=orange < /tmp/input2 .yaml
194+ docker run -i gcr.io/kpt-functions/label-namespace -d label_name=color -d label_value=orange < /tmp/input .yaml
263195```
264196
265197This is functionally equivalent to the ` ConfigMap ` used earlier.
266198
267199> ** Note:** This causes an error if the function takes another kind of ` functionConfig ` .
268200
269- Finally, let's mutate the configuration files by using source and sink functions:
201+ #### Composing a pipeline
202+
203+ We can use any source and sink function to compose a pipeline. Here, we'll use ` read-yaml ` and ` write-yaml `
204+ functions from the [ KPT functions catalog] [ catalog ] .
205+
206+ Pull the images:
207+
208+ ``` sh
209+ docker pull gcr.io/kpt-functions/read-yaml
210+ docker pull gcr.io/kpt-functions/write-yaml
211+ ```
212+
213+ You'll also need some example configuration:
270214
271215``` sh
272- git clone
[email protected] :GoogleContainerTools/kpt-functions-sdk.git
216+ git clone
--depth 1 [email protected] :GoogleContainerTools/kpt-functions-sdk.git
273217cd kpt-functions-sdk/example-configs
218+ ```
274219
275- docker run -i -u $( id -u) -v $( pwd) :/source gcr.io/kpt-functions/read-yaml -i /dev/null -d source_dir=/source |
220+ Finally, let's run the pipeline:
221+
222+ ``` sh
223+ docker run -i -u $( id -u) -v $( pwd) :/source gcr.io/kpt-functions/read-yaml -i /dev/null -d source_dir=/source |
276224docker run -i gcr.io/kpt-functions/label-namespace -d label_name=color -d label_value=orange |
277225docker run -i -u $( id -u) -v $( pwd) :/sink gcr.io/kpt-functions/write-yaml -o /dev/null -d sink_dir=/sink -d overwrite=true
278- ```
226+ ````
279227
280228You should see labels added to ` Namespace` configuration files:
281229
282230` ` ` sh
283231git status
284- ```
232+ ` ` ` `
233+
234+ # ### Understanding Docker Flags
235+
236+ - ` -u` : By default, docker containers run as a non-privileged user. Privileged actions, like
237+ filesystem access or calls to the network, require escalated access. Note the example usages of
238+ ` read-yaml` , which include ` docker run -u $( id -u) ` , running docker with your user ID.
239+ - ` -v` : Filesystem access requires mounting your container' s filesystem onto your local
240+ filesystem. For example, the `read-yaml` command includes the following: `-v $(pwd):/source`. This connects
241+ the container' s ` /source` directory to the current directory on your filesystem.
242+ - ` -i` : This flag keeps STDIN open for use in pipelines.
285243
286244# ## Example 2
287245
0 commit comments