In this example, we will see how to apply desired setter values to the
resource fields parameterized by kpt-set comments.
Get the example package by running the following commands:
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/apply-setters-simpleWe 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: setters
data:
env: |-
- prod
- dev
nested-env: |-
- key: some-other-key
value: some-other-value
nginx-replicas: "3"
tag: 1.16.2Invoke the function by running the following command:
$ kpt fn render apply-setters-simple- Check the value of field
replicasis set to3inDeploymentresource. - Check the value of field
imageis set to valuenginx:1.16.2inDeploymentresource. - Check the value of field
environmentsis set to value[dev, prod]inMyKindresource with the name offoo. - Check the value of field
environmentsis set to value:
- key: some-other-key
value: some-other-value
in MyKind resource with the name of bar.
Refer to the create-setters function documentation for information about creating setters.