This example demonstrates how to declaratively run the [ensure-name-substring
]
function to prepend prefix in the resource names.
Get the example package by running the following commands:
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/ensure-name-substring-advanced
We use the following Kptfile
and fn-config.yaml
to run the function.
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: example
pipeline:
mutators:
- image: gcr.io/kpt-fn/ensure-name-substring:unstable
configPath: fn-config.yaml
# fn-config.yaml
apiVersion: fn.kpt.dev/v1alpha1
kind: EnsureNameSubstring
metadata:
name: my-config
substring: prod-
editMode: prepend
additionalNameFields:
- group: dev.example.com
version: v1
kind: MyResource
path: spec/name
We are going to prepend prefix prod-
to resource names.
The function will not only update field .metadata.name
but also field
.spec.name
in MyResource
.
Invoke the function by running the following commands:
$ kpt fn render ensure-name-substring-advanced
Check all resources have prod-
in their names and the field .spec.name
in
MyResource
also got updated.