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.git/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
replicas
is set to3
inDeployment
resource. - Check the value of field
image
is set to valuenginx:1.16.2
inDeployment
resource. - Check the value of field
environments
is set to value[dev, prod]
inMyKind
resource.
Note: #
Refer to the create-setters
function documentation for information about creating setters.