From d296ec7c8fcbba26211665ce3a67df59d4424f0c Mon Sep 17 00:00:00 2001 From: Phani Teja Marupaka Date: Wed, 24 Mar 2021 12:43:36 -0700 Subject: [PATCH 1/7] Search replace README and generated docs --- functions/go/Makefile | 6 + functions/go/search-replace/README.md | 179 ++++++++++++++++++ functions/go/search-replace/generated/docs.go | 128 +++++++++++++ functions/go/search-replace/main.go | 9 +- 4 files changed, 318 insertions(+), 4 deletions(-) create mode 100644 functions/go/search-replace/README.md create mode 100644 functions/go/search-replace/generated/docs.go diff --git a/functions/go/Makefile b/functions/go/Makefile index 97592e3f2..77328aa96 100644 --- a/functions/go/Makefile +++ b/functions/go/Makefile @@ -15,6 +15,7 @@ SHELL=/bin/bash GOPATH := $(shell go env GOPATH) TAG ?= unstable GCR = gcr.io/kpt-fn +GOBIN := $(shell go env GOPATH)/bin # Edit this list to contain all go functions FUNCTIONS := \ @@ -117,3 +118,8 @@ func-build: func-verify func-push: @echo Pushing image $(CURRENT_FUNCTION)... ../../scripts/go-function-release.sh push curated + +generate: + GO111MODULE=on go get -v github.com/GoogleContainerTools/kpt/mdtogo + $(GOBIN)/mdtogo search-replace search-replace/generated --license=none --strategy=cmdDocs + diff --git a/functions/go/search-replace/README.md b/functions/go/search-replace/README.md new file mode 100644 index 000000000..9852ba749 --- /dev/null +++ b/functions/go/search-replace/README.md @@ -0,0 +1,179 @@ +# search-replace + +## Overview + + + +Search and optionally replace fields across all resources. + + + +There is a spectrum of configuration customization techniques as described in +[this document]. One of the most basic and simplest to understand is +Search and Replace: The user fetches a package of configuration, searches all +the files for fields matching a criteria, and replaces their values. + +Search matchers are provided with `by-` prefix. When multiple matchers +are provided they are AND’ed together. `put-` matchers are mutually exclusive. + +### Synopsis + + + +``` +kpt fn eval search-replace:VERSION [DIR] -- [matcher_name=matcher_value] +``` + +#### Matchers + +```sh +by-value +Match by value of a field. + +by-value-regex +Match by Regex for the value of a field. The syntax of the regular expressions +accepted is the same general syntax used by Go, Perl, Python, and other languages. +More precisely, it is the syntax accepted by RE2 and described at +https://golang.org/s/re2syntax. With the exception that it matches the entire +value of the field by default without requiring start (^) and end ($) characters. + +by-path +Match by path expression of a field. Path expressions are used to deeply navigate +and match particular yaml nodes. Please note that the path expressions are not +regular expressions. + +put-value +Set or update the value of the matching fields. Input can be a pattern for which +the numbered capture groups are resolved using --by-value-regex input. + +put-comment +Set or update the line comment for matching fields. Input can be a pattern for +which the numbered capture groups are resolved using --by-value-regex input. +``` + + + +### Examples + + + +```sh +# Matches fields with value "3": +$ kpt fn eval search-replace:unstable -- by-value=3 +``` + +```sh +# Matches fields with value prefixed by "nginx-": +$ kpt fn eval search-replace:unstable -- by-value-regex='ngnix-.*' +``` + +```sh +# Matches field with path "spec.namespaces" set to "bookstore": +$ kpt fn eval search-replace:unstable -- by-path='metadata.namespace' by-value='bookstore' +``` + +```sh +# Matches fields with name "containerPort" arbitrarily deep in "spec" that have value of 80: +$ kpt fn eval search-replace:unstable -- by-path='spec.**.containerPort' by-value=80 +``` + +```sh +# Set namespaces for all resources to "bookstore", even namespace is not set on a resource: +$ kpt fn eval search-replace:unstable -- by-path='metadata.namespace' put-value='bookstore' +``` + +``` +# Search and Set multiple values using regex numbered capture groups +$ kpt fn eval search-replace:unstable -- by-value-regex='something-(.*)' put-value='my-project-id-${1}' +metadata: + name: something-foo + namespace: something-bar +... +metadata: + name: my-project-id-foo + namespace: my-project-id-bar +``` + +```sh +# Put the setter pattern as a line comment for matching fields. +$ kpt fn eval search-replace:unstable -- by-value='my-project-id-foo' put-comment='kpt-set: ${project-id}-foo' +metadata: + name: my-project-id-foo # kpt-set: ${project-id}-foo + +# Setter pattern comments can be added to multiple values matching a regex numbered capture groups +$ kpt fn eval search-replace:unstable -- by-value-regex='my-project-id-(.*)' put-comment='kpt-set: ${project-id}-${1}' +metadata: + name: my-project-id-foo # kpt-set: ${project-id}-foo + namespace: my-project-id-bar # kpt-set: ${project-id}-bar +``` + +Supported Path expressions: + +```sh +a.b.c + +a: + b: + c: thing # MATCHES +``` + +```sh +a.*.c + +a: + b1: + c: thing # MATCHES + d: whatever + b2: + c: thing # MATCHES + f: something irrelevant +``` + +```sh +a.**.c + +a: + b1: + c: thing1 # MATCHES + d: cat + b2: + c: thing2 # MATCHES + d: dog + b3: + d: + - f: + c: thing3 # MATCHES + d: beep + - f: + g: + c: thing4 # MATCHES + d: boop + - d: mooo +``` + +```sh +a.b[1].c + +a: + b: + - c: thing0 + - c: thing1 # MATCHES + - c: thing2 +``` + +```sh +a.b[*].c + +a: + b: + - c: thing0 # MATCHES + d: what..ever + - c: thing1 # MATCHES + d: blarh + - c: thing2 # MATCHES + f: thingamabob +``` + + + +[this document]: https://github.com/kubernetes/community/blob/master/contributors/design-proposals/architecture/declarative-application-management.md#declarative-configuration diff --git a/functions/go/search-replace/generated/docs.go b/functions/go/search-replace/generated/docs.go new file mode 100644 index 000000000..a71bc10c2 --- /dev/null +++ b/functions/go/search-replace/generated/docs.go @@ -0,0 +1,128 @@ + + +// Code generated by "mdtogo"; DO NOT EDIT. +package generated + +var SearchReplaceShort = `Search and optionally replace fields across all resources.` +var SearchReplaceLong = ` + kpt fn eval search-replace:VERSION [DIR] -- [matcher_name=matcher_value] + +Matchers: + + by-value + Match by value of a field. + + by-value-regex + Match by Regex for the value of a field. The syntax of the regular expressions + accepted is the same general syntax used by Go, Perl, Python, and other languages. + More precisely, it is the syntax accepted by RE2 and described at + https://golang.org/s/re2syntax. With the exception that it matches the entire + value of the field by default without requiring start (^) and end ($) characters. + + by-path + Match by path expression of a field. Path expressions are used to deeply navigate + and match particular yaml nodes. Please note that the path expressions are not + regular expressions. + + put-value + Set or update the value of the matching fields. Input can be a pattern for which + the numbered capture groups are resolved using --by-value-regex input. + + put-comment + Set or update the line comment for matching fields. Input can be a pattern for + which the numbered capture groups are resolved using --by-value-regex input. +` +var SearchReplaceExamples = ` + # Matches fields with value "3": + $ kpt fn eval search-replace:unstable -- by-value=3 + + # Matches fields with value prefixed by "nginx-": + $ kpt fn eval search-replace:unstable -- by-value-regex='ngnix-.*' + + # Matches field with path "spec.namespaces" set to "bookstore": + $ kpt fn eval search-replace:unstable -- by-path='metadata.namespace' by-value='bookstore' + + # Matches fields with name "containerPort" arbitrarily deep in "spec" that have value of 80: + $ kpt fn eval search-replace:unstable -- by-path='spec.**.containerPort' by-value=80 + + # Set namespaces for all resources to "bookstore", even namespace is not set on a resource: + $ kpt fn eval search-replace:unstable -- by-path='metadata.namespace' put-value='bookstore' + + # Search and Set multiple values using regex numbered capture groups + $ kpt fn eval search-replace:unstable -- by-value-regex='something-(.*)' put-value='my-project-id-${1}' + metadata: + name: something-foo + namespace: something-bar + ... + metadata: + name: my-project-id-foo + namespace: my-project-id-bar + + # Put the setter pattern as a line comment for matching fields. + $ kpt fn eval search-replace:unstable -- by-value='my-project-id-foo' put-comment='kpt-set: ${project-id}-foo' + metadata: + name: my-project-id-foo # kpt-set: ${project-id}-foo + + # Setter pattern comments can be added to multiple values matching a regex numbered capture groups + $ kpt fn eval search-replace:unstable -- by-value-regex='my-project-id-(.*)' put-comment='kpt-set: ${project-id}-${1}' + metadata: + name: my-project-id-foo # kpt-set: ${project-id}-foo + namespace: my-project-id-bar # kpt-set: ${project-id}-bar + +Supported Path expressions: + + a.b.c + + a: + b: + c: thing # MATCHES + + a.*.c + + a: + b1: + c: thing # MATCHES + d: whatever + b2: + c: thing # MATCHES + f: something irrelevant + + a.**.c + + a: + b1: + c: thing1 # MATCHES + d: cat + b2: + c: thing2 # MATCHES + d: dog + b3: + d: + - f: + c: thing3 # MATCHES + d: beep + - f: + g: + c: thing4 # MATCHES + d: boop + - d: mooo + + a.b[1].c + + a: + b: + - c: thing0 + - c: thing1 # MATCHES + - c: thing2 + + a.b[*].c + + a: + b: + - c: thing0 # MATCHES + d: what..ever + - c: thing1 # MATCHES + d: blarh + - c: thing2 # MATCHES + f: thingamabob +` diff --git a/functions/go/search-replace/main.go b/functions/go/search-replace/main.go index a76a19643..258a6ab57 100644 --- a/functions/go/search-replace/main.go +++ b/functions/go/search-replace/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/search-replace/generated" "sigs.k8s.io/kustomize/kyaml/fn/framework" kyaml "sigs.k8s.io/kustomize/kyaml/yaml" ) @@ -25,7 +26,10 @@ func main() { return nil }) - cmd.Long = usage() + cmd.Short = generated.SearchReplaceShort + cmd.Long = generated.SearchReplaceLong + cmd.Example = generated.SearchReplaceExamples + if err := cmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) @@ -46,9 +50,6 @@ func run(resourceList *framework.ResourceList) ([]framework.Item, error) { return searchResultsToItems(sr), nil } -func usage() string { - return `` // TODO: pmarupaka add usage docs -} // getSearchReplaceParams retrieve the search parameters from input config func getSearchReplaceParams(fc interface{}) (SearchReplace, error) { From dc32c1bc8ebefd861d2b733ebe68e4ee7e2017ab Mon Sep 17 00:00:00 2001 From: Phani Teja Marupaka Date: Wed, 24 Mar 2021 14:54:00 -0700 Subject: [PATCH 2/7] Apply setters README and godocs --- functions/go/Makefile | 1 + functions/go/apply-setters/README.md | 94 ++++++++++++++++++++ functions/go/apply-setters/generated/docs.go | 64 +++++++++++++ functions/go/apply-setters/main.go | 57 ++---------- 4 files changed, 164 insertions(+), 52 deletions(-) create mode 100644 functions/go/apply-setters/README.md create mode 100644 functions/go/apply-setters/generated/docs.go diff --git a/functions/go/Makefile b/functions/go/Makefile index 77328aa96..0032b3caf 100644 --- a/functions/go/Makefile +++ b/functions/go/Makefile @@ -122,4 +122,5 @@ func-push: generate: GO111MODULE=on go get -v github.com/GoogleContainerTools/kpt/mdtogo $(GOBIN)/mdtogo search-replace search-replace/generated --license=none --strategy=cmdDocs + $(GOBIN)/mdtogo apply-setters apply-setters/generated --license=none --strategy=cmdDocs diff --git a/functions/go/apply-setters/README.md b/functions/go/apply-setters/README.md new file mode 100644 index 000000000..63844d680 --- /dev/null +++ b/functions/go/apply-setters/README.md @@ -0,0 +1,94 @@ +# apply-setters + +### Overview + + + +Apply setter values on resources fields. May set either the complete or partial field value. + + + +Setters provide a solution for template-free setting of field values. They are a +safer alternative to other substitution techniques which do not have the context +of the structured data. Setters may be invoked to modify the configuration +using `apply-setters` function to set values. + +### Synopsis + + + +``` +kpt fn eval apply-setters:VERSION [DIR] -- [setter_name=setter_value] +``` + +Data model + +1. Fields reference setters specified as line comments -- e.g. + +``` + # kpt-set: replicas +``` + +2. Input values to setters are provided as key-value pairs -- e.g. + +``` + kpt fn eval apply-setters:unstable -- replicas=3 +``` + +Control flow + +1. Read the package resources. +2. Locate all fields which reference the setter and change their values. +3. Write the modified resources back to the package. + + + +### Examples + + + +Let's start with the input resources + +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: the-map # kpt-set: ${name} +data: + some-key: some-value +--- +apiVersion: v1 +kind: MyKind +metadata: + name: ns +environments: # kpt-set: ${env} + - dev + - stage +``` + +Invoke apply-setters function on the input resources + +``` +kpt fn eval apply-setters:unstable -- 'name=my-map' 'env=[prod, dev]' +``` + +The resources are transformed to + +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: my-map # kpt-set: ${name} +data: + some-key: some-value +--- +apiVersion: v1 +kind: MyKind +metadata: + name: ns +environments: # kpt-set: ${env} + - prod + - dev +``` + + diff --git a/functions/go/apply-setters/generated/docs.go b/functions/go/apply-setters/generated/docs.go new file mode 100644 index 000000000..7d50796e9 --- /dev/null +++ b/functions/go/apply-setters/generated/docs.go @@ -0,0 +1,64 @@ + + +// Code generated by "mdtogo"; DO NOT EDIT. +package generated + +var ApplySettersShort = `Apply setter values on resources fields. May set either the complete or partial field value.` +var ApplySettersLong = ` + kpt fn eval apply-setters:VERSION [DIR] -- [setter_name=setter_value] + +Data model + +1. Fields reference setters specified as line comments -- e.g. + + # kpt-set: replicas + +2. Input values to setters are provided as key-value pairs -- e.g. + + kpt fn eval apply-setters:unstable -- replicas=3 + +Control flow + +1. Read the package resources. +2. Locate all fields which reference the setter and change their values. +3. Write the modified resources back to the package. +` +var ApplySettersExamples = ` +Let's start with the input resources + + apiVersion: v1 + kind: ConfigMap + metadata: + name: the-map # kpt-set: ${name} + data: + some-key: some-value + --- + apiVersion: v1 + kind: MyKind + metadata: + name: ns + environments: # kpt-set: ${env} + - dev + - stage + +Invoke apply-setters function on the input resources + + kpt fn eval apply-setters:unstable -- 'name=my-map' 'env=[prod, dev]' + +The resources are transformed to + + apiVersion: v1 + kind: ConfigMap + metadata: + name: my-map # kpt-set: ${name} + data: + some-key: some-value + --- + apiVersion: v1 + kind: MyKind + metadata: + name: ns + environments: # kpt-set: ${env} + - prod + - dev +` diff --git a/functions/go/apply-setters/main.go b/functions/go/apply-setters/main.go index 46d6c6cd2..87f5ae94c 100644 --- a/functions/go/apply-setters/main.go +++ b/functions/go/apply-setters/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/apply-setters/generated" "sigs.k8s.io/kustomize/kyaml/fn/framework" kyaml "sigs.k8s.io/kustomize/kyaml/yaml" ) @@ -25,64 +26,16 @@ func main() { return nil }) - cmd.Long = usage() + cmd.Short = generated.ApplySettersShort + cmd.Long = generated.ApplySettersLong + cmd.Example = generated.ApplySettersExamples + if err := cmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } } -func usage() string { - return `Apply setter values to resource fields with setter references. - -Example: - -Here is an example resource config to start with - -apiVersion: v1 -kind: Deployment -metadata: - name: my-deployment -spec: - replicas: 1 # kpt-set: ${replicas} - -Use ConfigMap to configure the 'apply-setters' function. The desired setter values -are provided as key-value pairs using data field where key is the name of the -setter(as seen in the reference comments) and value is the new desired value for -the tagged field - -apiVersion: v1 -kind: ConfigMap -metadata: - name: my-config -data: - replicas: '3' - -Invoking apply-setters function would apply the changes to resource configs - -apiVersion: v1 -kind: Deployment -metadata: - name: my-deployment -spec: - replicas: 3 # kpt-set: ${replicas} - - -Values to array setters must be array nodes wrapped into strings. Here is the -example config to apply array setters. - -apiVersion: v1 -kind: ConfigMap -metadata: - name: my-config -data: - projectId: my-project - environments: | - - dev - - staging -` -} - // getSetters retrieve the setters from input config func getSetters(fc interface{}) (ApplySetters, error) { var fcd ApplySetters From b1398f7e8647d7fbea1a766573db9d62c3700c87 Mon Sep 17 00:00:00 2001 From: Phani Teja Marupaka Date: Wed, 24 Mar 2021 16:44:53 -0700 Subject: [PATCH 3/7] Suggested changes: generate docs for all funcitons via looping --- functions/go/Makefile | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/functions/go/Makefile b/functions/go/Makefile index 0032b3caf..2263e8ffd 100644 --- a/functions/go/Makefile +++ b/functions/go/Makefile @@ -28,6 +28,8 @@ FUNCTIONS := \ # Targets for running all function tests FUNCTION_TESTS := $(patsubst %,%-TEST,$(FUNCTIONS)) +# Targets for generating all functions docs +FUNCTION_GENERATE_DOCS := $(patsubst %,%-GENERATE,$(FUNCTIONS)) FUNCTION_CHECKLICENSES := $(patsubst %,%-CHECKLICENSES,$(FUNCTIONS)) # Targets to build functions @@ -56,6 +58,15 @@ test: $(FUNCTION_TESTS) ## Run unit tests for all functions $(FUNCTION_TESTS): $(MAKE) CURRENT_FUNCTION=$(subst -TEST,,$@) func-test +generate: install-mdtogo generate-docs + +.PHONY: generate-docs +generate-docs: $(FUNCTION_GENERATE_DOCS) ## Generate docs for all functions + +.PHONY: $(FUNCTION_GENERATE_DOCS) +$(FUNCTION_GENERATE_DOCS): + $(MAKE) CURRENT_FUNCTION=$(subst -GENERATE,,$@) func-generate + .PHONY: build build: $(FUNCTION_BUILDS) ## Build all function images. 'TAG' env is used to specify tag. 'dev' will be used if not set. @@ -85,9 +96,12 @@ else GO_LICENSES=$(shell which go-licenses) endif +install-mdtogo: + GO111MODULE=on go get -v github.com/GoogleContainerTools/kpt/mdtogo + # Recipes for individual function .PHONY: func-fix func-vet func-fmt func-test func-lint \ - func-build func-push func-verify func-check-licenses + func-build func-push func-verify func-check-licenses func-generate func-verify: func-fix func-vet func-fmt func-test func-lint func-check-licenses func-fix: @@ -119,8 +133,6 @@ func-push: @echo Pushing image $(CURRENT_FUNCTION)... ../../scripts/go-function-release.sh push curated -generate: - GO111MODULE=on go get -v github.com/GoogleContainerTools/kpt/mdtogo - $(GOBIN)/mdtogo search-replace search-replace/generated --license=none --strategy=cmdDocs - $(GOBIN)/mdtogo apply-setters apply-setters/generated --license=none --strategy=cmdDocs +func-generate: + $(GOBIN)/mdtogo $(CURRENT_FUNCTION) $(CURRENT_FUNCTION)/generated --license=none --strategy=cmdDocs From bcd35bb35dd2d7fe14d2fa1df0d0a64c673f827d Mon Sep 17 00:00:00 2001 From: Phani Teja Marupaka Date: Thu, 25 Mar 2021 14:32:08 -0700 Subject: [PATCH 4/7] Suggested changes: apply-setters docs --- functions/go/apply-setters/README.md | 145 ++++++++++++++----- functions/go/apply-setters/generated/docs.go | 120 +++++++++++---- 2 files changed, 199 insertions(+), 66 deletions(-) diff --git a/functions/go/apply-setters/README.md b/functions/go/apply-setters/README.md index 63844d680..38d1a58c3 100644 --- a/functions/go/apply-setters/README.md +++ b/functions/go/apply-setters/README.md @@ -4,42 +4,50 @@ -Apply setter values on resources fields. May set either the complete or partial field value. +Apply setter values on resource fields. Setters serve as parameters for template-free +setting of field values. -Setters provide a solution for template-free setting of field values. They are a -safer alternative to other substitution techniques which do not have the context -of the structured data. Setters may be invoked to modify the configuration +Setters are a safer alternative to other substitution techniques which do not have the context +of the structured data. Setters may be invoked to modify the package resources using `apply-setters` function to set values. ### Synopsis -``` -kpt fn eval apply-setters:VERSION [DIR] -- [setter_name=setter_value] -``` - -Data model +Package publishers declare setters in the package, consumers can set their values +either declaratively or imperatively. -1. Fields reference setters specified as line comments -- e.g. +Setter names can be discovered in the pipeline section of Kptfile, and the values +can be declared next to setter names. -``` - # kpt-set: replicas +```yaml +apiVersion: v1alpha2 +kind: Kptfile +metadata: + name: my-pkg +pipeline: + mutators: + - image: gcr.io/kpt-fns/apply-setters:unstable + configMap: + setter_name1: setter-value1 + setter_name2: setter-value2 ``` -2. Input values to setters are provided as key-value pairs -- e.g. +The declared values for setters are rendered by invoking the following command: ``` - kpt fn eval apply-setters:unstable -- replicas=3 +kpt fn render [PKG_PATH] ``` -Control flow +Alternatively, this function can be invoked imperatively on the package by passing the +inputs as key-value pairs. -1. Read the package resources. -2. Locate all fields which reference the setter and change their values. -3. Write the modified resources back to the package. +``` +kpt fn eval gcr.io/kpt-fns/apply-setters:VERSION [PKG_PATH] -- [setter_name=setter_value] +``` @@ -47,45 +55,110 @@ Control flow -Let's start with the input resources +#### Setting scalar values + +Let's start with the input resource in a package ```yaml apiVersion: v1 -kind: ConfigMap +kind: Deployment metadata: - name: the-map # kpt-set: ${name} -data: - some-key: some-value ---- + name: nginx-deployment # kpt-set: ${image}-deployment +spec: + replicas: 1 # kpt-set: ${replicas} +``` + +Discover the names of setters in the Kptfile and declare desired values. + +```yaml +apiVersion: v1alpha2 +kind: Kptfile +metadata: + name: my-pkg +pipeline: + mutators: + - image: gcr.io/kpt-fns/apply-setters:unstable + configMap: + image: ubuntu + replicas: 3 +``` + +Render the declared values by invoking: + +``` +kpt fn render +``` + +Alternatively, values can be rendered imperatively + +``` +kpt fn eval gcr.io/kpt-fns/apply-setters:unstable -- 'replicas=3' +``` + +Rendered resource looks like the following: + +```yaml +apiVersion: v1 +kind: Deployment +metadata: + name: ubuntu-deployment # kpt-set: ${image}-deployment +spec: + replicas: 3 # kpt-set: ${replicas} +``` + +#### Setting array values + +Array values can also be parameterized using setters. Since the values of configMap +in pipeline definition must be of string type, the array values must be wrapped into +string. However, the rendered values in the resources will be array type. + +Let's start with the input resource + +```yaml apiVersion: v1 kind: MyKind metadata: - name: ns + name: foo environments: # kpt-set: ${env} - dev - stage ``` -Invoke apply-setters function on the input resources +Declare the desired array values, wrapped into string. + +```yaml +apiVersion: v1alpha2 +kind: Kptfile +metadata: + name: my-pkg +pipeline: + mutators: + - image: gcr.io/kpt-fns/apply-setters:unstable + configMap: + env: | + - prod + - dev +``` + +Render the declared values by invoking: ``` -kpt fn eval apply-setters:unstable -- 'name=my-map' 'env=[prod, dev]' +kpt fn render ``` -The resources are transformed to +Alternatively, values can be rendered imperatively + +``` +kpt fn eval gcr.io/kpt-fns/apply-setters:unstable -- 'env=[prod, dev]' +``` + +Rendered resource looks like the following: ```yaml apiVersion: v1 -kind: ConfigMap -metadata: - name: my-map # kpt-set: ${name} -data: - some-key: some-value ---- -apiVersion: v1 kind: MyKind metadata: - name: ns + name: foo environments: # kpt-set: ${env} - prod - dev diff --git a/functions/go/apply-setters/generated/docs.go b/functions/go/apply-setters/generated/docs.go index 7d50796e9..8c4821c03 100644 --- a/functions/go/apply-setters/generated/docs.go +++ b/functions/go/apply-setters/generated/docs.go @@ -3,61 +3,121 @@ // Code generated by "mdtogo"; DO NOT EDIT. package generated -var ApplySettersShort = `Apply setter values on resources fields. May set either the complete or partial field value.` +var ApplySettersShort = `Apply setter values on resource fields. Setters serve as parameters for template-free +setting of field values.` var ApplySettersLong = ` - kpt fn eval apply-setters:VERSION [DIR] -- [setter_name=setter_value] +Package publishers declare setters in the package, consumers can set their values +either declaratively or imperatively. -Data model +Setter names can be discovered in the pipeline section of Kptfile, and the values +can be declared next to setter names. -1. Fields reference setters specified as line comments -- e.g. - - # kpt-set: replicas + apiVersion: v1alpha2 + kind: Kptfile + metadata: + name: my-pkg + pipeline: + mutators: + - image: gcr.io/kpt-fns/apply-setters:unstable + configMap: + setter_name1: setter-value1 + setter_name2: setter-value2 -2. Input values to setters are provided as key-value pairs -- e.g. +The declared values for setters are rendered by invoking the following command: - kpt fn eval apply-setters:unstable -- replicas=3 + kpt fn render [PKG_PATH] -Control flow +Alternatively, this function can be invoked imperatively on the package by passing the +inputs as key-value pairs. -1. Read the package resources. -2. Locate all fields which reference the setter and change their values. -3. Write the modified resources back to the package. + kpt fn eval gcr.io/kpt-fns/apply-setters:VERSION [PKG_PATH] -- [setter_name=setter_value] ` var ApplySettersExamples = ` -Let's start with the input resources +Setting scalar values: + +Let's start with the input resource in a package apiVersion: v1 - kind: ConfigMap + kind: Deployment metadata: - name: the-map # kpt-set: ${name} - data: - some-key: some-value - --- + name: nginx-deployment # kpt-set: ${image}-deployment + spec: + replicas: 1 # kpt-set: ${replicas} + +Discover the names of setters in the Kptfile and declare desired values. + + apiVersion: v1alpha2 + kind: Kptfile + metadata: + name: my-pkg + pipeline: + mutators: + - image: gcr.io/kpt-fns/apply-setters:unstable + configMap: + image: ubuntu + replicas: 3 + +Render the declared values by invoking: + + kpt fn render + +Alternatively, values can be rendered imperatively + + kpt fn eval gcr.io/kpt-fns/apply-setters:unstable -- 'replicas=3' + +Rendered resource looks like the following: + + apiVersion: v1 + kind: Deployment + metadata: + name: ubuntu-deployment # kpt-set: ${image}-deployment + spec: + replicas: 3 # kpt-set: ${replicas} + +Setting array values: + +Array values can also be parameterized using setters. Since the values of configMap +in pipeline definition must be of string type, the array values must be wrapped into +string. However, the rendered values in the resources will be array type. + +Let's start with the input resource + apiVersion: v1 kind: MyKind metadata: - name: ns + name: foo environments: # kpt-set: ${env} - dev - stage -Invoke apply-setters function on the input resources +Declare the desired array values, wrapped into string. + + apiVersion: v1alpha2 + kind: Kptfile + metadata: + name: my-pkg + pipeline: + mutators: + - image: gcr.io/kpt-fns/apply-setters:unstable + configMap: + env: | + - prod + - dev - kpt fn eval apply-setters:unstable -- 'name=my-map' 'env=[prod, dev]' +Render the declared values by invoking: -The resources are transformed to + kpt fn render + +Alternatively, values can be rendered imperatively + + kpt fn eval gcr.io/kpt-fns/apply-setters:unstable -- 'env=[prod, dev]' + +Rendered resource looks like the following: - apiVersion: v1 - kind: ConfigMap - metadata: - name: my-map # kpt-set: ${name} - data: - some-key: some-value - --- apiVersion: v1 kind: MyKind metadata: - name: ns + name: foo environments: # kpt-set: ${env} - prod - dev From 19da82e4fade31bd18f6f149c0ebc0caf05930e9 Mon Sep 17 00:00:00 2001 From: Phani Teja Marupaka Date: Thu, 25 Mar 2021 14:45:54 -0700 Subject: [PATCH 5/7] Update image name to full image path --- functions/go/search-replace/README.md | 18 +++++++++--------- functions/go/search-replace/generated/docs.go | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/functions/go/search-replace/README.md b/functions/go/search-replace/README.md index 9852ba749..8b9cab73d 100644 --- a/functions/go/search-replace/README.md +++ b/functions/go/search-replace/README.md @@ -21,7 +21,7 @@ are provided they are AND’ed together. `put-` matchers are mutually exclusive. ``` -kpt fn eval search-replace:VERSION [DIR] -- [matcher_name=matcher_value] +kpt fn eval gcr.io/kpt-fns/search-replace:VERSION [DIR] -- [matcher_name=matcher_value] ``` #### Matchers @@ -59,32 +59,32 @@ which the numbered capture groups are resolved using --by-value-regex input. ```sh # Matches fields with value "3": -$ kpt fn eval search-replace:unstable -- by-value=3 +$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value=3 ``` ```sh # Matches fields with value prefixed by "nginx-": -$ kpt fn eval search-replace:unstable -- by-value-regex='ngnix-.*' +$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='ngnix-.*' ``` ```sh # Matches field with path "spec.namespaces" set to "bookstore": -$ kpt fn eval search-replace:unstable -- by-path='metadata.namespace' by-value='bookstore' +$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='metadata.namespace' by-value='bookstore' ``` ```sh # Matches fields with name "containerPort" arbitrarily deep in "spec" that have value of 80: -$ kpt fn eval search-replace:unstable -- by-path='spec.**.containerPort' by-value=80 +$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='spec.**.containerPort' by-value=80 ``` ```sh # Set namespaces for all resources to "bookstore", even namespace is not set on a resource: -$ kpt fn eval search-replace:unstable -- by-path='metadata.namespace' put-value='bookstore' +$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='metadata.namespace' put-value='bookstore' ``` ``` # Search and Set multiple values using regex numbered capture groups -$ kpt fn eval search-replace:unstable -- by-value-regex='something-(.*)' put-value='my-project-id-${1}' +$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='something-(.*)' put-value='my-project-id-${1}' metadata: name: something-foo namespace: something-bar @@ -96,12 +96,12 @@ metadata: ```sh # Put the setter pattern as a line comment for matching fields. -$ kpt fn eval search-replace:unstable -- by-value='my-project-id-foo' put-comment='kpt-set: ${project-id}-foo' +$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value='my-project-id-foo' put-comment='kpt-set: ${project-id}-foo' metadata: name: my-project-id-foo # kpt-set: ${project-id}-foo # Setter pattern comments can be added to multiple values matching a regex numbered capture groups -$ kpt fn eval search-replace:unstable -- by-value-regex='my-project-id-(.*)' put-comment='kpt-set: ${project-id}-${1}' +$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='my-project-id-(.*)' put-comment='kpt-set: ${project-id}-${1}' metadata: name: my-project-id-foo # kpt-set: ${project-id}-foo namespace: my-project-id-bar # kpt-set: ${project-id}-bar diff --git a/functions/go/search-replace/generated/docs.go b/functions/go/search-replace/generated/docs.go index a71bc10c2..6ed07f09c 100644 --- a/functions/go/search-replace/generated/docs.go +++ b/functions/go/search-replace/generated/docs.go @@ -5,7 +5,7 @@ package generated var SearchReplaceShort = `Search and optionally replace fields across all resources.` var SearchReplaceLong = ` - kpt fn eval search-replace:VERSION [DIR] -- [matcher_name=matcher_value] + kpt fn eval gcr.io/kpt-fns/search-replace:VERSION [DIR] -- [matcher_name=matcher_value] Matchers: @@ -34,22 +34,22 @@ Matchers: ` var SearchReplaceExamples = ` # Matches fields with value "3": - $ kpt fn eval search-replace:unstable -- by-value=3 + $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value=3 # Matches fields with value prefixed by "nginx-": - $ kpt fn eval search-replace:unstable -- by-value-regex='ngnix-.*' + $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='ngnix-.*' # Matches field with path "spec.namespaces" set to "bookstore": - $ kpt fn eval search-replace:unstable -- by-path='metadata.namespace' by-value='bookstore' + $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='metadata.namespace' by-value='bookstore' # Matches fields with name "containerPort" arbitrarily deep in "spec" that have value of 80: - $ kpt fn eval search-replace:unstable -- by-path='spec.**.containerPort' by-value=80 + $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='spec.**.containerPort' by-value=80 # Set namespaces for all resources to "bookstore", even namespace is not set on a resource: - $ kpt fn eval search-replace:unstable -- by-path='metadata.namespace' put-value='bookstore' + $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='metadata.namespace' put-value='bookstore' # Search and Set multiple values using regex numbered capture groups - $ kpt fn eval search-replace:unstable -- by-value-regex='something-(.*)' put-value='my-project-id-${1}' + $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='something-(.*)' put-value='my-project-id-${1}' metadata: name: something-foo namespace: something-bar @@ -59,12 +59,12 @@ var SearchReplaceExamples = ` namespace: my-project-id-bar # Put the setter pattern as a line comment for matching fields. - $ kpt fn eval search-replace:unstable -- by-value='my-project-id-foo' put-comment='kpt-set: ${project-id}-foo' + $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value='my-project-id-foo' put-comment='kpt-set: ${project-id}-foo' metadata: name: my-project-id-foo # kpt-set: ${project-id}-foo # Setter pattern comments can be added to multiple values matching a regex numbered capture groups - $ kpt fn eval search-replace:unstable -- by-value-regex='my-project-id-(.*)' put-comment='kpt-set: ${project-id}-${1}' + $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='my-project-id-(.*)' put-comment='kpt-set: ${project-id}-${1}' metadata: name: my-project-id-foo # kpt-set: ${project-id}-foo namespace: my-project-id-bar # kpt-set: ${project-id}-bar From 126367579f536e017b8549a68cc348e6199722a2 Mon Sep 17 00:00:00 2001 From: Phani Teja Marupaka Date: Mon, 29 Mar 2021 11:22:01 -0700 Subject: [PATCH 6/7] Suggested changes: remove sh and func-generate to docs-generate --- functions/go/Makefile | 6 +++--- functions/go/search-replace/README.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/functions/go/Makefile b/functions/go/Makefile index 2263e8ffd..0fa8d46d3 100644 --- a/functions/go/Makefile +++ b/functions/go/Makefile @@ -65,7 +65,7 @@ generate-docs: $(FUNCTION_GENERATE_DOCS) ## Generate docs for all functions .PHONY: $(FUNCTION_GENERATE_DOCS) $(FUNCTION_GENERATE_DOCS): - $(MAKE) CURRENT_FUNCTION=$(subst -GENERATE,,$@) func-generate + $(MAKE) CURRENT_FUNCTION=$(subst -GENERATE,,$@) docs-generate .PHONY: build build: $(FUNCTION_BUILDS) ## Build all function images. 'TAG' env is used to specify tag. 'dev' will be used if not set. @@ -101,7 +101,7 @@ install-mdtogo: # Recipes for individual function .PHONY: func-fix func-vet func-fmt func-test func-lint \ - func-build func-push func-verify func-check-licenses func-generate + func-build func-push func-verify func-check-licenses docs-generate func-verify: func-fix func-vet func-fmt func-test func-lint func-check-licenses func-fix: @@ -133,6 +133,6 @@ func-push: @echo Pushing image $(CURRENT_FUNCTION)... ../../scripts/go-function-release.sh push curated -func-generate: +docs-generate: $(GOBIN)/mdtogo $(CURRENT_FUNCTION) $(CURRENT_FUNCTION)/generated --license=none --strategy=cmdDocs diff --git a/functions/go/search-replace/README.md b/functions/go/search-replace/README.md index 8b9cab73d..459a5e4dc 100644 --- a/functions/go/search-replace/README.md +++ b/functions/go/search-replace/README.md @@ -26,7 +26,7 @@ kpt fn eval gcr.io/kpt-fns/search-replace:VERSION [DIR] -- [matcher_name=matcher #### Matchers -```sh +``` by-value Match by value of a field. From fa1b1b65f1ef913bdcef4a9dda4fc729843da817 Mon Sep 17 00:00:00 2001 From: Phani Teja Marupaka Date: Tue, 30 Mar 2021 11:01:56 -0700 Subject: [PATCH 7/7] kpt-fns to kpt-fn --- functions/go/apply-setters/README.md | 12 ++++++------ functions/go/apply-setters/generated/docs.go | 12 ++++++------ functions/go/search-replace/README.md | 18 +++++++++--------- functions/go/search-replace/generated/docs.go | 18 +++++++++--------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/functions/go/apply-setters/README.md b/functions/go/apply-setters/README.md index 38d1a58c3..c085b9299 100644 --- a/functions/go/apply-setters/README.md +++ b/functions/go/apply-setters/README.md @@ -30,7 +30,7 @@ metadata: name: my-pkg pipeline: mutators: - - image: gcr.io/kpt-fns/apply-setters:unstable + - image: gcr.io/kpt-fn/apply-setters:unstable configMap: setter_name1: setter-value1 setter_name2: setter-value2 @@ -46,7 +46,7 @@ Alternatively, this function can be invoked imperatively on the package by passi inputs as key-value pairs. ``` -kpt fn eval gcr.io/kpt-fns/apply-setters:VERSION [PKG_PATH] -- [setter_name=setter_value] +kpt fn eval --image gcr.io/kpt-fn/apply-setters:VERSION [PKG_PATH] -- [setter_name=setter_value] ``` @@ -77,7 +77,7 @@ metadata: name: my-pkg pipeline: mutators: - - image: gcr.io/kpt-fns/apply-setters:unstable + - image: gcr.io/kpt-fn/apply-setters:unstable configMap: image: ubuntu replicas: 3 @@ -92,7 +92,7 @@ kpt fn render Alternatively, values can be rendered imperatively ``` -kpt fn eval gcr.io/kpt-fns/apply-setters:unstable -- 'replicas=3' +kpt fn eval --image gcr.io/kpt-fn/apply-setters:unstable -- 'replicas=3' ``` Rendered resource looks like the following: @@ -133,7 +133,7 @@ metadata: name: my-pkg pipeline: mutators: - - image: gcr.io/kpt-fns/apply-setters:unstable + - image: gcr.io/kpt-fn/apply-setters:unstable configMap: env: | - prod @@ -149,7 +149,7 @@ kpt fn render Alternatively, values can be rendered imperatively ``` -kpt fn eval gcr.io/kpt-fns/apply-setters:unstable -- 'env=[prod, dev]' +kpt fn eval --image gcr.io/kpt-fn/apply-setters:unstable -- 'env=[prod, dev]' ``` Rendered resource looks like the following: diff --git a/functions/go/apply-setters/generated/docs.go b/functions/go/apply-setters/generated/docs.go index 8c4821c03..6b5914d6c 100644 --- a/functions/go/apply-setters/generated/docs.go +++ b/functions/go/apply-setters/generated/docs.go @@ -18,7 +18,7 @@ can be declared next to setter names. name: my-pkg pipeline: mutators: - - image: gcr.io/kpt-fns/apply-setters:unstable + - image: gcr.io/kpt-fn/apply-setters:unstable configMap: setter_name1: setter-value1 setter_name2: setter-value2 @@ -30,7 +30,7 @@ The declared values for setters are rendered by invoking the following command: Alternatively, this function can be invoked imperatively on the package by passing the inputs as key-value pairs. - kpt fn eval gcr.io/kpt-fns/apply-setters:VERSION [PKG_PATH] -- [setter_name=setter_value] + kpt fn eval --image gcr.io/kpt-fn/apply-setters:VERSION [PKG_PATH] -- [setter_name=setter_value] ` var ApplySettersExamples = ` Setting scalar values: @@ -52,7 +52,7 @@ Discover the names of setters in the Kptfile and declare desired values. name: my-pkg pipeline: mutators: - - image: gcr.io/kpt-fns/apply-setters:unstable + - image: gcr.io/kpt-fn/apply-setters:unstable configMap: image: ubuntu replicas: 3 @@ -63,7 +63,7 @@ Render the declared values by invoking: Alternatively, values can be rendered imperatively - kpt fn eval gcr.io/kpt-fns/apply-setters:unstable -- 'replicas=3' + kpt fn eval --image gcr.io/kpt-fn/apply-setters:unstable -- 'replicas=3' Rendered resource looks like the following: @@ -98,7 +98,7 @@ Declare the desired array values, wrapped into string. name: my-pkg pipeline: mutators: - - image: gcr.io/kpt-fns/apply-setters:unstable + - image: gcr.io/kpt-fn/apply-setters:unstable configMap: env: | - prod @@ -110,7 +110,7 @@ Render the declared values by invoking: Alternatively, values can be rendered imperatively - kpt fn eval gcr.io/kpt-fns/apply-setters:unstable -- 'env=[prod, dev]' + kpt fn eval --image gcr.io/kpt-fn/apply-setters:unstable -- 'env=[prod, dev]' Rendered resource looks like the following: diff --git a/functions/go/search-replace/README.md b/functions/go/search-replace/README.md index 459a5e4dc..95b863c5d 100644 --- a/functions/go/search-replace/README.md +++ b/functions/go/search-replace/README.md @@ -21,7 +21,7 @@ are provided they are AND’ed together. `put-` matchers are mutually exclusive. ``` -kpt fn eval gcr.io/kpt-fns/search-replace:VERSION [DIR] -- [matcher_name=matcher_value] +kpt fn eval [DIR] --image gcr.io/kpt-fn/search-replace:VERSION -- [matcher_name=matcher_value] ``` #### Matchers @@ -59,32 +59,32 @@ which the numbered capture groups are resolved using --by-value-regex input. ```sh # Matches fields with value "3": -$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value=3 +$ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-value=3 ``` ```sh # Matches fields with value prefixed by "nginx-": -$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='ngnix-.*' +$ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-value-regex='ngnix-.*' ``` ```sh # Matches field with path "spec.namespaces" set to "bookstore": -$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='metadata.namespace' by-value='bookstore' +$ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-path='metadata.namespace' by-value='bookstore' ``` ```sh # Matches fields with name "containerPort" arbitrarily deep in "spec" that have value of 80: -$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='spec.**.containerPort' by-value=80 +$ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-path='spec.**.containerPort' by-value=80 ``` ```sh # Set namespaces for all resources to "bookstore", even namespace is not set on a resource: -$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='metadata.namespace' put-value='bookstore' +$ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-path='metadata.namespace' put-value='bookstore' ``` ``` # Search and Set multiple values using regex numbered capture groups -$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='something-(.*)' put-value='my-project-id-${1}' +$ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-value-regex='something-(.*)' put-value='my-project-id-${1}' metadata: name: something-foo namespace: something-bar @@ -96,12 +96,12 @@ metadata: ```sh # Put the setter pattern as a line comment for matching fields. -$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value='my-project-id-foo' put-comment='kpt-set: ${project-id}-foo' +$ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-value='my-project-id-foo' put-comment='kpt-set: ${project-id}-foo' metadata: name: my-project-id-foo # kpt-set: ${project-id}-foo # Setter pattern comments can be added to multiple values matching a regex numbered capture groups -$ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='my-project-id-(.*)' put-comment='kpt-set: ${project-id}-${1}' +$ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-value-regex='my-project-id-(.*)' put-comment='kpt-set: ${project-id}-${1}' metadata: name: my-project-id-foo # kpt-set: ${project-id}-foo namespace: my-project-id-bar # kpt-set: ${project-id}-bar diff --git a/functions/go/search-replace/generated/docs.go b/functions/go/search-replace/generated/docs.go index 6ed07f09c..444dddf36 100644 --- a/functions/go/search-replace/generated/docs.go +++ b/functions/go/search-replace/generated/docs.go @@ -5,7 +5,7 @@ package generated var SearchReplaceShort = `Search and optionally replace fields across all resources.` var SearchReplaceLong = ` - kpt fn eval gcr.io/kpt-fns/search-replace:VERSION [DIR] -- [matcher_name=matcher_value] + kpt fn eval [DIR] --image gcr.io/kpt-fn/search-replace:VERSION -- [matcher_name=matcher_value] Matchers: @@ -34,22 +34,22 @@ Matchers: ` var SearchReplaceExamples = ` # Matches fields with value "3": - $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value=3 + $ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-value=3 # Matches fields with value prefixed by "nginx-": - $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='ngnix-.*' + $ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-value-regex='ngnix-.*' # Matches field with path "spec.namespaces" set to "bookstore": - $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='metadata.namespace' by-value='bookstore' + $ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-path='metadata.namespace' by-value='bookstore' # Matches fields with name "containerPort" arbitrarily deep in "spec" that have value of 80: - $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='spec.**.containerPort' by-value=80 + $ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-path='spec.**.containerPort' by-value=80 # Set namespaces for all resources to "bookstore", even namespace is not set on a resource: - $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-path='metadata.namespace' put-value='bookstore' + $ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-path='metadata.namespace' put-value='bookstore' # Search and Set multiple values using regex numbered capture groups - $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='something-(.*)' put-value='my-project-id-${1}' + $ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-value-regex='something-(.*)' put-value='my-project-id-${1}' metadata: name: something-foo namespace: something-bar @@ -59,12 +59,12 @@ var SearchReplaceExamples = ` namespace: my-project-id-bar # Put the setter pattern as a line comment for matching fields. - $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value='my-project-id-foo' put-comment='kpt-set: ${project-id}-foo' + $ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-value='my-project-id-foo' put-comment='kpt-set: ${project-id}-foo' metadata: name: my-project-id-foo # kpt-set: ${project-id}-foo # Setter pattern comments can be added to multiple values matching a regex numbered capture groups - $ kpt fn eval gcr.io/kpt-fns/search-replace:unstable -- by-value-regex='my-project-id-(.*)' put-comment='kpt-set: ${project-id}-${1}' + $ kpt fn eval --image gcr.io/kpt-fn/search-replace:unstable -- by-value-regex='my-project-id-(.*)' put-comment='kpt-set: ${project-id}-${1}' metadata: name: my-project-id-foo # kpt-set: ${project-id}-foo namespace: my-project-id-bar # kpt-set: ${project-id}-bar