Skip to content

[transformer / replacer] text/template interfering with expected result #1329

@olblak

Description

@olblak

Discussed in https://github.com/orgs/updatecli/discussions/1243

Originally posted by sdurrheimer March 23, 2023
Hi there,

Is there a way to make updatecli not trying evaluate the go template functions in a transformer / replacer?
Like replace with the raw string, don't try to text/template it.

I'm trying to sync a file from one repo to another during release, and as the destination is a helm chart, I wanted to use a transformer / replacer to change one line into a some go template code meant to be used by the helm chart later.

With the following config, updatecli will try to evaluate the include function, when I just want it to replace with this exact string:

Code:

targets:
  push-crds-to-janitor-crds-helm-chart-repo:
    name: Push the CRDs file to the helm chart repo
    sourceid: crd-yaml
    scmid: helm-chart-repo
    kind: file
    spec:
      file: templates/crds.yaml
      forcecreate: true
    transformers:
      - replacer:
          from: "creationTimestamp: null"
          to: >
            labels:
                {{- include "rancher-janitor-operator-crds.labels" . | nindent 4 }}

Result:

Loading Pipeline "updatecli.yaml"
ERROR: failed loading pipeline(s)
	* "updatecli.yaml" - template: cfg:98: function "include" not defined

But If I try to escape the {{ and }}, the include function is no more called, but the escape characters appear in the end result:

  • {{"{{"}}- include "rancher-janitor-operator-crds.labels" . | nindent 4 {{"}}"}}
  • {{`"{{- include "rancher-janitor-operator-crds.labels" . | nindent 4 }}"`}}

All end up with the following, similar to the previous one, error:

SOURCES
=======
Pipeline "Push release and updated CRDs to the helm charts repos" failed
Skipping due to:
	sources stage:	"template: cfg:84: function \"include\" not defined"

If I escape more, the error moves to the next step:

  • {{`{{"{{\"{{\"}}"}}`}}- include "rancher-janitor-operator-crds.labels" . | nindent 4 {{`{{"{{\"}}\"}}"}}`}}
TARGETS
========
Pipeline "Push release and updated CRDs to the helm charts repos" failed
Skipping due to:
	targets stage:	"template: cfg:84: function \"include\" not defined"

And now adding more escape options is becoming difficult

One more escape level, almost there but not good enough:

  • {{`{{"{{\"{{\\\"{{\\\"}}\"}}"}}`}}- include "rancher-janitor-operator-crds.labels" . | nindent 4 {{`{{"{{\"{{\\\"}}\\\"}}\"}}"}}`}}

error:

TARGETS
========

push-crds-to-janitor-crds-helm-chart-repo
-----------------------------------------

**Dry Run enabled**

⚠ updated the [dry run] content of the file "/var/folders/zm/3ys3kgl958339xjq5dh82qgc0000gn/T/updatecli/gitlab/uks/charts/rancher-janitor-operator-crds/templates/crds.yaml"

--- /var/folders/zm/3ys3kgl958339xjq5dh82qgc0000gn/T/updatecli/gitlab/uks/charts/rancher-janitor-operator-crds/templates/crds.yaml
+++ /var/folders/zm/3ys3kgl958339xjq5dh82qgc0000gn/T/updatecli/gitlab/uks/charts/rancher-janitor-operator-crds/templates/crds.yaml
@@ -4,10 +4,10 @@
 metadata:
   annotations:
     controller-gen.kubebuilder.io/version: v0.11.3
-  creationTimestamp: null
-  name: nodecleaners.rancher.domain.tld
   labels:
     {{- include "rancher-janitor-operator-crds.labels" . | nindent 4 }}
+
+  name: nodecleaners.rancher.domain.tld
 spec:
   group: rancher.domain.tld
   names:

Pipeline "Push release and updated CRDs to the helm charts repos" failed
Skipping due to:
	targets stage:	"template: cfg:84: function \"include\" not defined"
```</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions