droot / kpt-substring-sample

Sample to demonstrate ensure-substring function

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ensure-name-substring: Advanced Example

Overview

This example demonstrates how to declaratively run the [ensure-name-substring] function to prepend prefix in the resource names.

Fetch the example package

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.

Function invocation

Invoke the function by running the following commands:

$ kpt fn render ensure-name-substring-advanced

Expected result

Check all resources have prod- in their names and the field .spec.name in MyResource also got updated.

About

Sample to demonstrate ensure-substring function

License:Apache License 2.0