create-setters: Simple Example #
Overview #
In this example, we will see how to add
setter comments to
resource fields using create-setters
function.
Fetch the example package #
Get the example package by running the following command:
$ kpt pkg get https://github.com/kptdev/krm-functions-catalog.git/examples/create-setters-simple
We use ConfigMap
to configure the create-setters
function.
The desired setter values are provided as key-value pairs using data
field.
Here, key is the name of the setter and value is the field value to be parameterized.
# create-setters-fn-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: create-setters-fn-config
data:
nginx-replicas: "4"
env: |
- dev
- stage
tag: 1.16.1
Function invocation #
Invoke the function by running the following command:
$ kpt fn render create-setters-simple
Expected result #
- Check the setter comment
kpt-set: ${nginx-replicas}
is added toreplicas
field value4
inDeployment
resource. - Check the setter comment
kpt-set: nginx:${tag}
is added toimage
field valuenginx:1.16.1
inDeployment
resource. - Check the setter comment
kpt-set: ${env}
is added toenvironment
field inMyKind
resource.