Skip to content

Commit f5dc9a9

Browse files
authored
fix: don't template registry+v1 manifests (#1979)
Signed-off-by: Joe Lanford <[email protected]>
1 parent 9a61b22 commit f5dc9a9

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,22 @@ func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, ins
5757
return nil, err
5858
}
5959
hash := sha256.Sum256(jsonData)
60-
chrt.Templates = append(chrt.Templates, &chart.File{
61-
Name: fmt.Sprintf("object-%x.json", hash[0:8]),
60+
name := fmt.Sprintf("object-%x.json", hash[0:8])
61+
62+
// Some registry+v1 manifests may actually contain Go Template strings
63+
// that are meant to survive and actually persist into etcd (e.g. to be
64+
// used as a templated configuration for another component). In order to
65+
// avoid applying templating logic to registry+v1's static manifests, we
66+
// create the manifests as Files, and then template those files via simple
67+
// Templates.
68+
chrt.Files = append(chrt.Files, &chart.File{
69+
Name: name,
6270
Data: jsonData,
6371
})
72+
chrt.Templates = append(chrt.Templates, &chart.File{
73+
Name: name,
74+
Data: []byte(fmt.Sprintf(`{{.Files.Get "%s"}}`, name)),
75+
})
6476
}
6577

6678
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)