ensure-name-substring: Depends on example #
Overview #
This example demonstrates how the [ensure-name-substring] function interacts
with resources that use the
depends-on annotation. The
depends-on
annotation is a special annotation which is used to specify one or more resource
dependencies. If the resource being referenced in a depends-on annotation is
included in the input to the [ensure-name-substring] function, then the
function will also apply the ensure-name-substring logic to the name portion of
the annotation.
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/ensure-name-substring-depends-on
We use the following Kptfile to configure the function.
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: example
pipeline:
mutators:
- image: ghcr.io/kptdev/krm-functions-catalog/ensure-name-substring:latest
configMap:
prepend: prod-
The function configuration is provided using a ConfigMap. We set only one
key-value pair:
prepend: prod-: The desired name substring.
Function invocation #
Invoke the function by running the following commands:
$ kpt fn render ensure-name-substring-depends-on
Expected result #
Check that:
- all resources have
metadata.nameprepended withprod-. - the
Deploymentwith namewordpresshad itsdepends-onannotation updated, since the correspondingStatefulSetis also included in the package. - the
Deploymentwith namebardid not have itsdepends-onannotation updated, since it references a resource which was not included in the package. - the
ClusterRoleBindingwith nameread-secrets-globalhad itsdepends-onannotation updated, since the correspondingClusterRoleis also included in the package.