rename run-fns to run

This commit is contained in:
Phillip Wittrock
2019-11-27 12:40:10 -08:00
parent 7ce1f7e95a
commit 52a5e6ec99
17 changed files with 92 additions and 92 deletions

View File

@@ -41,7 +41,7 @@ items:
- 1 - 1
# this command: # this command:
$ kyaml cat pkg/ --function-config config.yaml --wrap-kind ResourceList | kyaml run-fns xargs -- app $ kyaml cat pkg/ --function-config config.yaml --wrap-kind ResourceList | kyaml run xargs -- app
# is equivalent to this command: # is equivalent to this command:
$ kyaml cat pkg/ --function-config config.yaml --wrap-kind ResourceList | app --flag1=value1 --flag2=value2 2 1 $ kyaml cat pkg/ --function-config config.yaml --wrap-kind ResourceList | app --flag1=value1 --flag2=value2 2 1

View File

@@ -13,8 +13,8 @@ import (
func GetRunFnRunner(name string) *RunFnRunner { func GetRunFnRunner(name string) *RunFnRunner {
r := &RunFnRunner{} r := &RunFnRunner{}
c := &cobra.Command{ c := &cobra.Command{
Use: "run-fns DIR", Use: "run DIR",
Aliases: []string{"run"}, Aliases: []string{"run-fns"},
Short: commands.RunFnsShort, Short: commands.RunFnsShort,
Long: commands.RunFnsLong, Long: commands.RunFnsLong,
Example: commands.RunFnsExamples, Example: commands.RunFnsExamples,

View File

@@ -59,7 +59,7 @@ var ConfigFnLong = `# Configuration Functions API Semantics
generated Resources -- e.g. 1. the function generates a Deployment, but doesn't generated Resources -- e.g. 1. the function generates a Deployment, but doesn't
specify ` + "`" + `cpu` + "`" + `, 2. the user sets the ` + "`" + `cpu` + "`" + ` on the generated Resource, 3. the specify ` + "`" + `cpu` + "`" + `, 2. the user sets the ` + "`" + `cpu` + "`" + ` on the generated Resource, 3. the
function should keep the ` + "`" + `cpu` + "`" + ` when regenerating the Resource a second time. function should keep the ` + "`" + `cpu` + "`" + ` when regenerating the Resource a second time.
- Functions **SHOULD** be usable outside ` + "`" + `kustomize config run-fns` + "`" + ` -- e.g. though pipeline - Functions **SHOULD** be usable outside ` + "`" + `kustomize config run` + "`" + ` -- e.g. though pipeline
mechanisms such as Tekton. mechanisms such as Tekton.
#### Input Format #### Input Format
@@ -126,7 +126,7 @@ var ConfigFnLong = `# Configuration Functions API Semantics
#### Container Environment #### Container Environment
When run by ` + "`" + `kustomize config run-fns` + "`" + `, functions are run in containers with the When run by ` + "`" + `kustomize config run` + "`" + `, functions are run in containers with the
following environment: following environment:
- Network: ` + "`" + `none` + "`" + ` - Network: ` + "`" + `none` + "`" + `
@@ -144,7 +144,7 @@ var ConfigFnLong = `# Configuration Functions API Semantics
` + "`" + `nginx-template.sh` + "`" + ` is a simple bash script which uses a *heredoc* as a templating solution ` + "`" + `nginx-template.sh` + "`" + ` is a simple bash script which uses a *heredoc* as a templating solution
for generating Resources from the functionConfig input fields. for generating Resources from the functionConfig input fields.
The script wraps itself using ` + "`" + `config run-fns wrap -- $0` + "`" + ` which will: The script wraps itself using ` + "`" + `config run wrap -- $0` + "`" + ` which will:
1. Parse the ` + "`" + `ResourceList.functionConfig` + "`" + ` (provided to the container stdin) into env vars 1. Parse the ` + "`" + `ResourceList.functionConfig` + "`" + ` (provided to the container stdin) into env vars
2. Merge the stdout into the original list of Resources 2. Merge the stdout into the original list of Resources
@@ -153,11 +153,11 @@ var ConfigFnLong = `# Configuration Functions API Semantics
4. Format the output 4. Format the output
#!/bin/bash #!/bin/bash
# script must run wrapped by ` + "`" + `kustomize config run-fns wrap` + "`" + ` # script must run wrapped by ` + "`" + `kustomize config run wrap` + "`" + `
# for parsing input the functionConfig into env vars # for parsing input the functionConfig into env vars
if [ -z ${WRAPPED} ]; then if [ -z ${WRAPPED} ]; then
export WRAPPED=true export WRAPPED=true
config run-fns wrap -- $0 config run wrap -- $0
exit $? exit $?
fi fi
@@ -216,7 +216,7 @@ var ConfigFnLong = `# Configuration Functions API Semantics
### Example Function Usage ### Example Function Usage
Following is an example of running the ` + "`" + `kustomize config run-fns` + "`" + ` using the preceding API. Following is an example of running the ` + "`" + `kustomize config run` + "`" + ` using the preceding API.
#### ` + "`" + `nginx.yaml` + "`" + ` (Input) #### ` + "`" + `nginx.yaml` + "`" + ` (Input)
@@ -239,7 +239,7 @@ Following is an example of running the ` + "`" + `kustomize config run-fns` + "`
- ` + "`" + `annotations[config.kubernetes.io/local-config]` + "`" + `: mark this as not a Resource that should - ` + "`" + `annotations[config.kubernetes.io/local-config]` + "`" + `: mark this as not a Resource that should
be applied be applied
#### ` + "`" + `kustomize config run-fns dir/` + "`" + ` (Output) #### ` + "`" + `kustomize config run dir/` + "`" + ` (Output)
` + "`" + `dir/my-instance_deployment.yaml` + "`" + ` contains the Deployment: ` + "`" + `dir/my-instance_deployment.yaml` + "`" + ` contains the Deployment:

View File

@@ -123,7 +123,7 @@ var RunFnsShort = `[Alpha] Reoncile config functions to Resources.`
var RunFnsLong = ` var RunFnsLong = `
[Alpha] Reconcile config functions to Resources. [Alpha] Reconcile config functions to Resources.
run-fns sequentially invokes all config functions in the directly, providing Resources run sequentially invokes all config functions in the directly, providing Resources
in the directory as input to the first function, and writing the output of the last in the directory as input to the first function, and writing the output of the last
function back to the directory. function back to the directory.
@@ -140,7 +140,7 @@ order they appear in the file).
#### Config Functions: #### Config Functions:
Config functions are specified as Kubernetes types containing a metadata.configFn.container.image Config functions are specified as Kubernetes types containing a metadata.configFn.container.image
field. This fields tells run-fns how to invoke the container. field. This fields tells run how to invoke the container.
Example config function: Example config function:
@@ -157,7 +157,7 @@ order they appear in the file).
spec: spec:
configField: configValue configField: configValue
In the preceding example, 'kustomize config run-fns example/' would identify the function by In the preceding example, 'kustomize config run example/' would identify the function by
the metadata.configFn field. It would then write all Resources in the directory to the metadata.configFn field. It would then write all Resources in the directory to
a container stdin (running the gcr.io/example/examplefunction:v1.0.1 image). It a container stdin (running the gcr.io/example/examplefunction:v1.0.1 image). It
would then writer the container stdout back to example/, replacing the directory would then writer the container stdout back to example/, replacing the directory
@@ -166,7 +166,7 @@ order they appear in the file).
See ` + "`" + `kustomize config help docs-fn` + "`" + ` for more details on writing functions. See ` + "`" + `kustomize config help docs-fn` + "`" + ` for more details on writing functions.
` `
var RunFnsExamples = ` var RunFnsExamples = `
kustomize config run-fns example/` kustomize config run example/`
var TreeShort = `[Alpha] Display Resource structure from a directory or stdin.` var TreeShort = `[Alpha] Display Resource structure from a directory or stdin.`
var TreeLong = ` var TreeLong = `

View File

@@ -282,7 +282,7 @@ var ConfigurationBasicsLong = `
var FunctionBasicsShort = `### Synopsis` var FunctionBasicsShort = `### Synopsis`
var FunctionBasicsLong = ` var FunctionBasicsLong = `
` + "`" + `kustomize config` + "`" + ` enables encapsulating function for manipulating Resource ` + "`" + `kustomize config` + "`" + ` enables encapsulating function for manipulating Resource
configuration inside containers, which are run using ` + "`" + `run-fns` + "`" + `. configuration inside containers, which are run using ` + "`" + `run` + "`" + `.
First fetch the kustomize repository, which contains a collection of example First fetch the kustomize repository, which contains a collection of example
functions functions
@@ -299,7 +299,7 @@ var FunctionBasicsLong = `
#### 1: Generate the Resources #### 1: Generate the Resources
` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/template-heredoc-cockroachdb/` + "`" + ` ` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/template-heredoc-cockroachdb/` + "`" + `
directory, and invoke ` + "`" + `run-fns` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory. directory, and invoke ` + "`" + `run` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory.
cd template-heredoc-cockroachdb/ cd template-heredoc-cockroachdb/
@@ -307,12 +307,12 @@ var FunctionBasicsLong = `
kustomize config tree local-resource/ --name --image --replicas kustomize config tree local-resource/ --name --image --replicas
# run the function # run the function
kustomize config run-fns local-resource/ kustomize config run local-resource/
# view the generated Resources # view the generated Resources
kustomize config tree local-resource/ --name --image --replicas kustomize config tree local-resource/ --name --image --replicas
` + "`" + `run-fns` + "`" + ` generated the directory ` + "`" + ` local-resource/config` + "`" + ` containing the generated ` + "`" + `run` + "`" + ` generated the directory ` + "`" + ` local-resource/config` + "`" + ` containing the generated
Resources. Resources.
#### 2. Modify the Generated Resources #### 2. Modify the Generated Resources
@@ -320,14 +320,14 @@ var FunctionBasicsLong = `
- modify the generated Resources by adding an annotation, sidecar container, etc. - modify the generated Resources by adding an annotation, sidecar container, etc.
- modify the ` + "`" + `local-resources/example-use.yaml` + "`" + ` by changing the replicas - modify the ` + "`" + `local-resources/example-use.yaml` + "`" + ` by changing the replicas
re-run ` + "`" + `run-fns` + "`" + `. this will apply the updated replicas to the generated Resources, re-run ` + "`" + `run` + "`" + `. this will apply the updated replicas to the generated Resources,
but keep the fields that you manually added to the generated Resource configuration. but keep the fields that you manually added to the generated Resource configuration.
# run the function # run the function
kustomize config run-fns local-resource/ kustomize config run local-resource/
` + "`" + `run-fns` + "`" + ` facilitates a non-destructive *smart templating* approach that allows templating ` + "`" + `run` + "`" + ` facilitates a non-destructive *smart templating* approach that allows templating
to be composed with manual modifications directly to the template output, as well as to be composed with manual modifications directly to the template output, as well as
composition with other functions which may appy validation or injection of values. composition with other functions which may appy validation or injection of values.
@@ -345,7 +345,7 @@ var FunctionBasicsLong = `
#### 1: Generate the Resources #### 1: Generate the Resources
` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/template-go-nginx/` + "`" + ` ` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/template-go-nginx/` + "`" + `
directory, and invoke ` + "`" + `run-fns` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory. directory, and invoke ` + "`" + `run` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory.
cd template-go-nginx/ cd template-go-nginx/
@@ -353,12 +353,12 @@ var FunctionBasicsLong = `
kustomize config tree local-resource/ --name --image --replicas kustomize config tree local-resource/ --name --image --replicas
# run the function # run the function
kustomize config run-fns local-resource/ kustomize config run local-resource/
# view the generated Resources # view the generated Resources
kustomize config tree local-resource/ --name --image --replicas kustomize config tree local-resource/ --name --image --replicas
` + "`" + `run-fns` + "`" + ` generated the directory ` + "`" + ` local-resource/config` + "`" + ` containing the generated ` + "`" + `run` + "`" + ` generated the directory ` + "`" + ` local-resource/config` + "`" + ` containing the generated
Resources. this time it put the configuration in a single file rather than multiple Resources. this time it put the configuration in a single file rather than multiple
files. The mapping of Resources to files is controlled by the function itself through files. The mapping of Resources to files is controlled by the function itself through
annotations on the generated Resources. annotations on the generated Resources.
@@ -368,11 +368,11 @@ var FunctionBasicsLong = `
- modify the generated Resources by adding an annotation, sidecar container, etc. - modify the generated Resources by adding an annotation, sidecar container, etc.
- modify the ` + "`" + `local-resources/example-use.yaml` + "`" + ` by changing the replicas - modify the ` + "`" + `local-resources/example-use.yaml` + "`" + ` by changing the replicas
re-run ` + "`" + `run-fns` + "`" + `. this will apply the updated replicas to the generated Resources, re-run ` + "`" + `run` + "`" + `. this will apply the updated replicas to the generated Resources,
but keep the fields that you manually added to the generated Resource configuration. but keep the fields that you manually added to the generated Resource configuration.
# run the function # run the function
kustomize config run-fns local-resource/ kustomize config run local-resource/
Just like in the preceding section, the function is implemented using a non-destructive Just like in the preceding section, the function is implemented using a non-destructive
approach which merges the generated Resources into previously generated instances. approach which merges the generated Resources into previously generated instances.
@@ -384,15 +384,15 @@ var FunctionBasicsLong = `
### Validation -- resource reservations ### Validation -- resource reservations
This section uses ` + "`" + `run-fns` + "`" + ` to perform validation rather than generate Resources. This section uses ` + "`" + `run` + "`" + ` to perform validation rather than generate Resources.
#### 1: Run the Validator #### 1: Run the Validator
` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/validator-resource-requests` + "`" + ` ` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/validator-resource-requests` + "`" + `
directory, and invoke ` + "`" + `run-fns` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory. directory, and invoke ` + "`" + `run` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory.
# run the function # run the function
kustomize config run-fns local-resource/ kustomize config run local-resource/
cpu-requests missing for a container in Deployment nginx (example-use.yaml [1]) cpu-requests missing for a container in Deployment nginx (example-use.yaml [1])
Error: exit status 1 Error: exit status 1
Usage: Usage:
@@ -404,19 +404,19 @@ var FunctionBasicsLong = `
and print the name of the file + Resource index. Edit the file and uncomment the resources, and print the name of the file + Resource index. Edit the file and uncomment the resources,
then re-run the functions. then re-run the functions.
kustomize config run-fns local-resource/ kustomize config run local-resource/
The validation now passes. The validation now passes.
### Injection -- resource reservations ### Injection -- resource reservations
This section uses ` + "`" + `run-fns` + "`" + ` to perform injection of field values based off annotations This section uses ` + "`" + `run` + "`" + ` to perform injection of field values based off annotations
on the Resource. on the Resource.
#### 1: Run the Injector #### 1: Run the Injector
` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/inject-tshirt-sizes` + "`" + ` ` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/inject-tshirt-sizes` + "`" + `
directory, and invoke ` + "`" + `run-fns` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory. directory, and invoke ` + "`" + `run` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory.
# print the resources # print the resources
kustomize config tree local-resource --resources --name kustomize config tree local-resource --resources --name
@@ -428,7 +428,7 @@ var FunctionBasicsLong = `
└── name: nginx └── name: nginx
# run the functions # run the functions
kustomize config run-fns local-resource/ kustomize config run local-resource/
# print the new resources # print the new resources
kustomize config tree local-resource --resources --name kustomize config tree local-resource --resources --name
@@ -443,7 +443,7 @@ var FunctionBasicsLong = `
Change the ` + "`" + `tshirt-size` + "`" + ` annotation from ` + "`" + `medium` + "`" + ` to ` + "`" + `small` + "`" + ` and re-run the functions. Change the ` + "`" + `tshirt-size` + "`" + ` annotation from ` + "`" + `medium` + "`" + ` to ` + "`" + `small` + "`" + ` and re-run the functions.
kustomize config run-fns local-resource/ kustomize config run local-resource/
kustomize config tree local-resource/ kustomize config tree local-resource/
local-resource local-resource
├── [example-use.yaml] Validator ├── [example-use.yaml] Validator
@@ -459,5 +459,5 @@ var FunctionBasicsLong = `
Functions may be composed together. Try putting the Injection (tshirt-size) and Functions may be composed together. Try putting the Injection (tshirt-size) and
Validation functions together in the same .yaml file (separated by ` + "`" + `---` + "`" + `). Run Validation functions together in the same .yaml file (separated by ` + "`" + `---` + "`" + `). Run
` + "`" + `run-fns` + "`" + ` and observe that the first function in the file is applied to the Resources, ` + "`" + `run` + "`" + ` and observe that the first function in the file is applied to the Resources,
and then the second function in the file is applied.` and then the second function in the file is applied.`

View File

@@ -53,7 +53,7 @@
generated Resources -- e.g. 1. the function generates a Deployment, but doesn't generated Resources -- e.g. 1. the function generates a Deployment, but doesn't
specify `cpu`, 2. the user sets the `cpu` on the generated Resource, 3. the specify `cpu`, 2. the user sets the `cpu` on the generated Resource, 3. the
function should keep the `cpu` when regenerating the Resource a second time. function should keep the `cpu` when regenerating the Resource a second time.
- Functions **SHOULD** be usable outside `kustomize config run-fns` -- e.g. though pipeline - Functions **SHOULD** be usable outside `kustomize config run` -- e.g. though pipeline
mechanisms such as Tekton. mechanisms such as Tekton.
#### Input Format #### Input Format
@@ -120,7 +120,7 @@
#### Container Environment #### Container Environment
When run by `kustomize config run-fns`, functions are run in containers with the When run by `kustomize config run`, functions are run in containers with the
following environment: following environment:
- Network: `none` - Network: `none`
@@ -138,7 +138,7 @@
`nginx-template.sh` is a simple bash script which uses a *heredoc* as a templating solution `nginx-template.sh` is a simple bash script which uses a *heredoc* as a templating solution
for generating Resources from the functionConfig input fields. for generating Resources from the functionConfig input fields.
The script wraps itself using `config run-fns wrap -- $0` which will: The script wraps itself using `config run wrap -- $0` which will:
1. Parse the `ResourceList.functionConfig` (provided to the container stdin) into env vars 1. Parse the `ResourceList.functionConfig` (provided to the container stdin) into env vars
2. Merge the stdout into the original list of Resources 2. Merge the stdout into the original list of Resources
@@ -147,11 +147,11 @@
4. Format the output 4. Format the output
#!/bin/bash #!/bin/bash
# script must run wrapped by `kustomize config run-fns wrap` # script must run wrapped by `kustomize config run wrap`
# for parsing input the functionConfig into env vars # for parsing input the functionConfig into env vars
if [ -z ${WRAPPED} ]; then if [ -z ${WRAPPED} ]; then
export WRAPPED=true export WRAPPED=true
config run-fns wrap -- $0 config run wrap -- $0
exit $? exit $?
fi fi
@@ -210,7 +210,7 @@
### Example Function Usage ### Example Function Usage
Following is an example of running the `kustomize config run-fns` using the preceding API. Following is an example of running the `kustomize config run` using the preceding API.
#### `nginx.yaml` (Input) #### `nginx.yaml` (Input)
@@ -233,7 +233,7 @@ Following is an example of running the `kustomize config run-fns` using the prec
- `annotations[config.kubernetes.io/local-config]`: mark this as not a Resource that should - `annotations[config.kubernetes.io/local-config]`: mark this as not a Resource that should
be applied be applied
#### `kustomize config run-fns dir/` (Output) #### `kustomize config run dir/` (Output)
`dir/my-instance_deployment.yaml` contains the Deployment: `dir/my-instance_deployment.yaml` contains the Deployment:

View File

@@ -1,4 +1,4 @@
## run-fns ## run
[Alpha] Reoncile config functions to Resources. [Alpha] Reoncile config functions to Resources.
@@ -6,7 +6,7 @@
[Alpha] Reconcile config functions to Resources. [Alpha] Reconcile config functions to Resources.
run-fns sequentially invokes all config functions in the directly, providing Resources run sequentially invokes all config functions in the directly, providing Resources
in the directory as input to the first function, and writing the output of the last in the directory as input to the first function, and writing the output of the last
function back to the directory. function back to the directory.
@@ -23,7 +23,7 @@ order they appear in the file).
#### Config Functions: #### Config Functions:
Config functions are specified as Kubernetes types containing a metadata.configFn.container.image Config functions are specified as Kubernetes types containing a metadata.configFn.container.image
field. This fields tells run-fns how to invoke the container. field. This fields tells run how to invoke the container.
Example config function: Example config function:
@@ -40,7 +40,7 @@ order they appear in the file).
spec: spec:
configField: configValue configField: configValue
In the preceding example, 'kustomize config run-fns example/' would identify the function by In the preceding example, 'kustomize config run example/' would identify the function by
the metadata.configFn field. It would then write all Resources in the directory to the metadata.configFn field. It would then write all Resources in the directory to
a container stdin (running the gcr.io/example/examplefunction:v1.0.1 image). It a container stdin (running the gcr.io/example/examplefunction:v1.0.1 image). It
would then writer the container stdout back to example/, replacing the directory would then writer the container stdout back to example/, replacing the directory
@@ -50,4 +50,4 @@ order they appear in the file).
### Examples ### Examples
kustomize config run-fns example/ kustomize config run example/

View File

@@ -3,7 +3,7 @@
### Synopsis ### Synopsis
`kustomize config` enables encapsulating function for manipulating Resource `kustomize config` enables encapsulating function for manipulating Resource
configuration inside containers, which are run using `run-fns`. configuration inside containers, which are run using `run`.
First fetch the kustomize repository, which contains a collection of example First fetch the kustomize repository, which contains a collection of example
functions functions
@@ -20,7 +20,7 @@
#### 1: Generate the Resources #### 1: Generate the Resources
`cd` into the `kustomize/functions/examples/template-heredoc-cockroachdb/` `cd` into the `kustomize/functions/examples/template-heredoc-cockroachdb/`
directory, and invoke `run-fns` on the `local-resource/` directory. directory, and invoke `run` on the `local-resource/` directory.
cd template-heredoc-cockroachdb/ cd template-heredoc-cockroachdb/
@@ -28,12 +28,12 @@
kustomize config tree local-resource/ --name --image --replicas kustomize config tree local-resource/ --name --image --replicas
# run the function # run the function
kustomize config run-fns local-resource/ kustomize config run local-resource/
# view the generated Resources # view the generated Resources
kustomize config tree local-resource/ --name --image --replicas kustomize config tree local-resource/ --name --image --replicas
`run-fns` generated the directory ` local-resource/config` containing the generated `run` generated the directory ` local-resource/config` containing the generated
Resources. Resources.
#### 2. Modify the Generated Resources #### 2. Modify the Generated Resources
@@ -41,14 +41,14 @@
- modify the generated Resources by adding an annotation, sidecar container, etc. - modify the generated Resources by adding an annotation, sidecar container, etc.
- modify the `local-resources/example-use.yaml` by changing the replicas - modify the `local-resources/example-use.yaml` by changing the replicas
re-run `run-fns`. this will apply the updated replicas to the generated Resources, re-run `run`. this will apply the updated replicas to the generated Resources,
but keep the fields that you manually added to the generated Resource configuration. but keep the fields that you manually added to the generated Resource configuration.
# run the function # run the function
kustomize config run-fns local-resource/ kustomize config run local-resource/
`run-fns` facilitates a non-destructive *smart templating* approach that allows templating `run` facilitates a non-destructive *smart templating* approach that allows templating
to be composed with manual modifications directly to the template output, as well as to be composed with manual modifications directly to the template output, as well as
composition with other functions which may appy validation or injection of values. composition with other functions which may appy validation or injection of values.
@@ -66,7 +66,7 @@
#### 1: Generate the Resources #### 1: Generate the Resources
`cd` into the `kustomize/functions/examples/template-go-nginx/` `cd` into the `kustomize/functions/examples/template-go-nginx/`
directory, and invoke `run-fns` on the `local-resource/` directory. directory, and invoke `run` on the `local-resource/` directory.
cd template-go-nginx/ cd template-go-nginx/
@@ -74,12 +74,12 @@
kustomize config tree local-resource/ --name --image --replicas kustomize config tree local-resource/ --name --image --replicas
# run the function # run the function
kustomize config run-fns local-resource/ kustomize config run local-resource/
# view the generated Resources # view the generated Resources
kustomize config tree local-resource/ --name --image --replicas kustomize config tree local-resource/ --name --image --replicas
`run-fns` generated the directory ` local-resource/config` containing the generated `run` generated the directory ` local-resource/config` containing the generated
Resources. this time it put the configuration in a single file rather than multiple Resources. this time it put the configuration in a single file rather than multiple
files. The mapping of Resources to files is controlled by the function itself through files. The mapping of Resources to files is controlled by the function itself through
annotations on the generated Resources. annotations on the generated Resources.
@@ -89,11 +89,11 @@
- modify the generated Resources by adding an annotation, sidecar container, etc. - modify the generated Resources by adding an annotation, sidecar container, etc.
- modify the `local-resources/example-use.yaml` by changing the replicas - modify the `local-resources/example-use.yaml` by changing the replicas
re-run `run-fns`. this will apply the updated replicas to the generated Resources, re-run `run`. this will apply the updated replicas to the generated Resources,
but keep the fields that you manually added to the generated Resource configuration. but keep the fields that you manually added to the generated Resource configuration.
# run the function # run the function
kustomize config run-fns local-resource/ kustomize config run local-resource/
Just like in the preceding section, the function is implemented using a non-destructive Just like in the preceding section, the function is implemented using a non-destructive
approach which merges the generated Resources into previously generated instances. approach which merges the generated Resources into previously generated instances.
@@ -105,15 +105,15 @@
### Validation -- resource reservations ### Validation -- resource reservations
This section uses `run-fns` to perform validation rather than generate Resources. This section uses `run` to perform validation rather than generate Resources.
#### 1: Run the Validator #### 1: Run the Validator
`cd` into the `kustomize/functions/examples/validator-resource-requests` `cd` into the `kustomize/functions/examples/validator-resource-requests`
directory, and invoke `run-fns` on the `local-resource/` directory. directory, and invoke `run` on the `local-resource/` directory.
# run the function # run the function
kustomize config run-fns local-resource/ kustomize config run local-resource/
cpu-requests missing for a container in Deployment nginx (example-use.yaml [1]) cpu-requests missing for a container in Deployment nginx (example-use.yaml [1])
Error: exit status 1 Error: exit status 1
Usage: Usage:
@@ -125,19 +125,19 @@
and print the name of the file + Resource index. Edit the file and uncomment the resources, and print the name of the file + Resource index. Edit the file and uncomment the resources,
then re-run the functions. then re-run the functions.
kustomize config run-fns local-resource/ kustomize config run local-resource/
The validation now passes. The validation now passes.
### Injection -- resource reservations ### Injection -- resource reservations
This section uses `run-fns` to perform injection of field values based off annotations This section uses `run` to perform injection of field values based off annotations
on the Resource. on the Resource.
#### 1: Run the Injector #### 1: Run the Injector
`cd` into the `kustomize/functions/examples/inject-tshirt-sizes` `cd` into the `kustomize/functions/examples/inject-tshirt-sizes`
directory, and invoke `run-fns` on the `local-resource/` directory. directory, and invoke `run` on the `local-resource/` directory.
# print the resources # print the resources
kustomize config tree local-resource --resources --name kustomize config tree local-resource --resources --name
@@ -149,7 +149,7 @@
└── name: nginx └── name: nginx
# run the functions # run the functions
kustomize config run-fns local-resource/ kustomize config run local-resource/
# print the new resources # print the new resources
kustomize config tree local-resource --resources --name kustomize config tree local-resource --resources --name
@@ -164,7 +164,7 @@
Change the `tshirt-size` annotation from `medium` to `small` and re-run the functions. Change the `tshirt-size` annotation from `medium` to `small` and re-run the functions.
kustomize config run-fns local-resource/ kustomize config run local-resource/
kustomize config tree local-resource/ kustomize config tree local-resource/
local-resource local-resource
├── [example-use.yaml] Validator ├── [example-use.yaml] Validator
@@ -180,5 +180,5 @@
Functions may be composed together. Try putting the Injection (tshirt-size) and Functions may be composed together. Try putting the Injection (tshirt-size) and
Validation functions together in the same .yaml file (separated by `---`). Run Validation functions together in the same .yaml file (separated by `---`). Run
`run-fns` and observe that the first function in the file is applied to the Resources, `run` and observe that the first function in the file is applied to the Resources,
and then the second function in the file is applied. and then the second function in the file is applied.

View File

@@ -17,7 +17,7 @@ Resource configuration, and looks for invalid configuration.
The function is invoked by authoring a [local Resource](local-resource) The function is invoked by authoring a [local Resource](local-resource)
with `metadata.configFn` and running: with `metadata.configFn` and running:
kustomize config run-fns local-resources/ kustomize config run local-resources/
This exists non-zero if there is an error. This exists non-zero if there is an error.
@@ -25,11 +25,11 @@ This exists non-zero if there is an error.
Run the validator with: Run the validator with:
kustomize config run-fns local-resource/ kustomize config run local-resource/
This will add resource reservations to the Deployment. Change the `tshirt-size` This will add resource reservations to the Deployment. Change the `tshirt-size`
annotation from `medium` to `small` and rerun: annotation from `medium` to `small` and rerun:
kustomize config run-fns local-resource/ kustomize config run local-resource/
Observe that the reservations have changed. Observe that the reservations have changed.

View File

@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// Package main implements an injection function for resource reservations and // Package main implements an injection function for resource reservations and
// is run with `kustomize config run-fns -- DIR/`. // is run with `kustomize config run -- DIR/`.
package main package main
import ( import (

View File

@@ -27,21 +27,21 @@ function input, and writing the function output.
The function is invoked by authoring a [local Resource](local-resource) The function is invoked by authoring a [local Resource](local-resource)
with `metadata.configFn` and running: with `metadata.configFn` and running:
kustomize config run-fns local-resources/ kustomize config run local-resources/
This generates the `local-resources/config` directory containing the template output. This generates the `local-resources/config` directory containing the template output.
- the template output may be modified by adding fields -- such as initContainers, - the template output may be modified by adding fields -- such as initContainers,
sidecarConatiners, cpu resource limits, etc -- and these fields will be retained sidecarConatiners, cpu resource limits, etc -- and these fields will be retained
when re-running `run-fns` when re-running `run`
- the function input `example-use.yaml` may be changed and rerunning `run-fns` will update - the function input `example-use.yaml` may be changed and rerunning `run` will update
only the parts changed in the template output. only the parts changed in the template output.
## Running the Example ## Running the Example
Run the config with: Run the config with:
kustomize config run-fns local-resource/ kustomize config run local-resource/
This will create the directory This will create the directory
@@ -50,6 +50,6 @@ This will create the directory
Add an annotation to the StatefulSet Resource and change the replica count of the Add an annotation to the StatefulSet Resource and change the replica count of the
`kind: Nginx` Resource in `example-use.yaml`. Rerun the template: `kind: Nginx` Resource in `example-use.yaml`. Rerun the template:
kustomize config run-fns local-resource/ kustomize config run local-resource/
The replica count should be updated, but your annotation should remain. The replica count should be updated, but your annotation should remain.

View File

@@ -1,7 +1,7 @@
# Copyright 2019 The Kubernetes Authors. # Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
apiVersion: examples.config.kubernetes.io/v1beta1 # call `kustomize config run-fns` on a directory containing this file apiVersion: examples.config.kubernetes.io/v1beta1 # call `kustomize config run` on a directory containing this file
kind: Nginx kind: Nginx
metadata: metadata:
name: demo name: demo

View File

@@ -11,7 +11,7 @@ The function is implemented as an [image](image), and built using `make image`.
The template is implemented as a heredoc, which substitutes environment variables The template is implemented as a heredoc, which substitutes environment variables
into a static string. into a static string.
This simple implementation uses `kustomize config run-fns wrap --` to perform the This simple implementation uses `kustomize config run wrap --` to perform the
heavy lifting of implementing the function interface. heavy lifting of implementing the function interface.
- parse functionConfig from stdin into environment variables - parse functionConfig from stdin into environment variables
@@ -22,21 +22,21 @@ heavy lifting of implementing the function interface.
The function is invoked by authoring a [local Resource](local-resource) The function is invoked by authoring a [local Resource](local-resource)
with `metadata.configFn` and running: with `metadata.configFn` and running:
kustomize config run-fns local-resources/ kustomize config run local-resources/
This generates the `local-resources/config` directory containing the template output. This generates the `local-resources/config` directory containing the template output.
- the template output may be modified by adding fields -- such as initContainers, - the template output may be modified by adding fields -- such as initContainers,
sidecarConatiners, cpu resource limits, etc -- and these fields will be retained sidecarConatiners, cpu resource limits, etc -- and these fields will be retained
when re-running `run-fns` when re-running `run`
- the function input `example-use.yaml` may be changed and rerunning `run-fns` will update - the function input `example-use.yaml` may be changed and rerunning `run` will update
only the parts changed in the template output. only the parts changed in the template output.
## Running the Example ## Running the Example
Run the config with: Run the config with:
kustomize config run-fns local-resource/ kustomize config run local-resource/
This will create the directory This will create the directory
@@ -45,6 +45,6 @@ This will create the directory
Add an annotation to the StatefulSet Resource and change the replica count of the Add an annotation to the StatefulSet Resource and change the replica count of the
`kind: CockroachDB` Resource in `example-use.yaml`. Rerun the template: `kind: CockroachDB` Resource in `example-use.yaml`. Rerun the template:
kustomize config run-fns local-resource/ kustomize config run local-resource/
The replica count should be updated, but your annotation should remain. The replica count should be updated, but your annotation should remain.

View File

@@ -3,18 +3,18 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# use `kustomize config run-fns wrap` to parse the container stdin into # use `kustomize config run wrap` to parse the container stdin into
# environment variables, and to merge the template output into the # environment variables, and to merge the template output into the
# input Resources. # input Resources.
if [ -z ${WRAPPED} ]; then if [ -z ${WRAPPED} ]; then
export WRAPPED=true export WRAPPED=true
kustomize config run-fns wrap -- $0 kustomize config run wrap -- $0
exit $? exit $?
fi fi
# this is the template for a cockroachdb instance # this is the template for a cockroachdb instance
# environment variables are parsed from the input functionConfig by # environment variables are parsed from the input functionConfig by
# `kustomize config run-fns wrap` # `kustomize config run wrap`
cat <<End-of-message cat <<End-of-message
apiVersion: v1 apiVersion: v1
kind: Service kind: Service

View File

@@ -1,7 +1,7 @@
# Copyright 2019 The Kubernetes Authors. # Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# call `kustomize config run-fns` on a directory containing this file # call `kustomize config run` on a directory containing this file
apiVersion: examples.config.kubernetes.io/v1beta1 apiVersion: examples.config.kubernetes.io/v1beta1
kind: CockroachDB kind: CockroachDB
metadata: metadata:

View File

@@ -17,7 +17,7 @@ Resource configuration, and looks for invalid configuration.
The function is invoked by authoring a [local Resource](local-resource) The function is invoked by authoring a [local Resource](local-resource)
with `metadata.configFn` and running: with `metadata.configFn` and running:
kustomize config run-fns local-resources/ kustomize config run local-resources/
This exists non-zero if there is an error. This exists non-zero if there is an error.
@@ -25,7 +25,7 @@ This exists non-zero if there is an error.
Run the validator with: Run the validator with:
kustomize config run-fns local-resource/ kustomize config run local-resource/
This will return an error: This will return an error:
@@ -33,6 +33,6 @@ This will return an error:
Now uncomment the resource reservations and run again: Now uncomment the resource reservations and run again:
kustomize config run-fns local-resource/ kustomize config run local-resource/
This will return success This will return success

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// Package main implements a validator function run by `kustomize config run-fns` // Package main implements a validator function run by `kustomize config run`
package main package main
import ( import (