apply-setters: Simple Example #
Overview #
In this example, we will see how to apply desired setter values to the
resource fields parameterized by kpt-set comments.
Fetch the example package #
Get the example package by running the following commands:
$ kpt pkg get https://github.com/kptdev/krm-functions-catalog/tree/master/examples/apply-setters-simple
We 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: apply-setters-fn-config
data:
replicas: "3"
role: |
- dev
- prod
tag: 1.16.2
Function invocation #
Invoke the function by running the following command:
$ kpt fn render apply-setters-simple
Expected result #
- 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.
Note: #
Refer to the create-setters function documentation for information about creating setters.