Skip to content

Commit 5c136ca

Browse files
committed
UPSTREAM: <carry>: [release-4.19] fix: don't template registry+v1 manifests
Signed-off-by: Joe Lanford <[email protected]>
1 parent 005bb2f commit 5c136ca

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

internal/operator-controller/rukpak/convert/registryv1.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,22 @@ func RegistryV1ToHelmChart(rv1 fs.FS, installNamespace string, watchNamespace st
6161
return nil, err
6262
}
6363
hash := sha256.Sum256(jsonData)
64-
chrt.Templates = append(chrt.Templates, &chart.File{
65-
Name: fmt.Sprintf("object-%x.json", hash[0:8]),
64+
name := fmt.Sprintf("object-%x.json", hash[0:8])
65+
66+
// Some registry+v1 manifests may actually contain Go Template strings
67+
// that are meant to survive and actually persist into etcd (e.g. to be
68+
// used as a templated configuration for another component). In order to
69+
// avoid applying templating logic to registry+v1's static manifests, we
70+
// create the manifests as Files, and then template those files via simple
71+
// Templates.
72+
chrt.Files = append(chrt.Files, &chart.File{
73+
Name: name,
6674
Data: jsonData,
6775
})
76+
chrt.Templates = append(chrt.Templates, &chart.File{
77+
Name: name,
78+
Data: []byte(fmt.Sprintf(`{{.Files.Get "%s"}}`, name)),
79+
})
6880
}
6981

7082
return chrt, nil

test/e2e/cluster_extension_install_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ func TestClusterExtensionInstallRegistry(t *testing.T) {
377377
assert.NotEmpty(ct, clusterExtension.Status.Install.Bundle)
378378
}
379379
}, pollDuration, pollInterval)
380+
381+
t.Log("By verifying that no templating occurs for registry+v1 bundle manifests")
382+
cm := corev1.ConfigMap{}
383+
require.NoError(t, c.Get(context.Background(), types.NamespacedName{Namespace: ns.Name, Name: "test-configmap"}, &cm))
384+
require.Contains(t, cm.Annotations, "shouldNotTemplate")
385+
require.Contains(t, cm.Annotations["shouldNotTemplate"], "{{ $labels.namespace }}")
380386
})
381387
}
382388
}

testdata/images/bundles/test-operator/v1.0.0/manifests/bundle.configmap.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ apiVersion: v1
22
kind: ConfigMap
33
metadata:
44
name: test-configmap
5+
annotations:
6+
shouldNotTemplate: >
7+
The namespace is {{ $labels.namespace }}. The templated
8+
$labels.namespace is NOT expected to be processed by OLM's
9+
rendering engine for registry+v1 bundles.
510
data:
611
version: "v1.0.0"
712
name: "test-configmap"

0 commit comments

Comments
 (0)