Closed marlenepereira closed 3 years ago
Package packages/test/alerts.yaml
packages/test/alerts.yaml
apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: name: alerts spec: groups: - name: my_alerts rules: - alert: TestAlert annotations: # {"$kpt-template":"true"} runbook_url: | {{render "runbook-url" "TestAlert"}} summary: Summary with template `{{ $labels.name }}` and `{{ $metadata.namespace }}`.
Kptfile test/Kptfile
test/Kptfile
apiVersion: kpt.dev/v1alpha1 kind: Kptfile metadata: name: test packageMetadata: shortDescription: sample description openAPI: definitions: io.k8s.cli.setters.runbook-url: x-k8s-cli: setter: name: runbook-url value: https://runbooks.com
packages.yaml
apiVersion: kpt.seek.com/v1alpha1 kind: ClusterPackages metadata: name: test-package spec: baseDir: test packages: - name: test variables: - name: runbook-url value: https://runbooks.com/runbooks#{{args 0}} local: directory: packages/test
2021-05-13T00:03:05Z | FATAL | Error performing sync operation error="template: render:1: undefined variable \"$labels\""
kpt fn source target/packages.yaml | kpt fn run --image seek/kpt-sync:0.0.8 \ --mount "type=bind,source=$(pwd)/packages/test,target=/packages/test" \ | kpt fn sink .
Placing the field with template before the field containing the # {"$kpt-template":"true"} comment results in the expected behavior. Package packages/test/alerts.yaml
# {"$kpt-template":"true"}
apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: name: alerts spec: groups: - name: my_alerts rules: - alert: TestAlert annotations: summary: Summary with template `{{ $labels.name }}` and `{{ $metadata.namespace }}`. # {"$kpt-template":"true"} runbook_url: | {{render "runbook-url" "TestAlert"}}
Output
apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: name: alerts spec: groups: - name: my_alerts rules: - alert: TestAlert annotations: summary: Summary with template `{{ $labels.name }}` and `{{ $metadata.namespace }}`. # {"$kpt-template":"true"} runbook_url: | https://runbooks.com/runbooks#TestAlert
This was addressed by https://github.com/seek-oss/kpt-functions/pull/39.
Affected Function(s)
Configuration Files
Package
packages/test/alerts.yaml
Kptfile
test/Kptfile
packages.yaml
Output
Steps to Reproduce
kpt fn source target/packages.yaml | kpt fn run --image seek/kpt-sync:0.0.8 \ --mount "type=bind,source=$(pwd)/packages/test,target=/packages/test" \ | kpt fn sink .
Important Factoids
Placing the field with template before the field containing the
# {"$kpt-template":"true"}
comment results in the expected behavior. Packagepackages/test/alerts.yaml
Output