Skip to content

Commit e2fbd80

Browse files
UPSTREAM: <carry>: [release-4.18] fix: don't template registry+v1 manifests
Signed-off-by: Joe Lanford <[email protected]>
1 parent 6c8c9d5 commit e2fbd80

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

internal/rukpak/convert/registryv1.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,22 @@ func toChart(in RegistryV1, installNamespace string, watchNamespaces []string) (
172172
return nil, err
173173
}
174174
hash := sha256.Sum256(jsonData)
175-
chrt.Templates = append(chrt.Templates, &chart.File{
176-
Name: fmt.Sprintf("object-%x.json", hash[0:8]),
175+
name := fmt.Sprintf("object-%x.json", hash[0:8])
176+
177+
// Some registry+v1 manifests may actually contain Go Template strings
178+
// that are meant to survive and actually persist into etcd (e.g. to be
179+
// used as a templated configuration for another component). In order to
180+
// avoid applying templating logic to registry+v1's static manifests, we
181+
// create the manifests as Files, and then template those files via simple
182+
// Templates.
183+
chrt.Files = append(chrt.Files, &chart.File{
184+
Name: name,
177185
Data: jsonData,
178186
})
187+
chrt.Templates = append(chrt.Templates, &chart.File{
188+
Name: name,
189+
Data: []byte(fmt.Sprintf(`{{.Files.Get "%s"}}`, name)),
190+
})
179191
}
180192

181193
return chrt, nil

test/e2e/cluster_extension_install_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ func TestClusterExtensionInstallRegistry(t *testing.T) {
354354
assert.NotEmpty(ct, clusterExtension.Status.Install.Bundle)
355355
}
356356
}, pollDuration, pollInterval)
357+
358+
t.Log("By verifying that no templating occurs for registry+v1 bundle manifests")
359+
cm := corev1.ConfigMap{}
360+
require.NoError(t, c.Get(context.Background(), types.NamespacedName{Namespace: ns.Name, Name: "test-configmap"}, &cm))
361+
require.Contains(t, cm.Annotations, "shouldNotTemplate")
362+
require.Contains(t, cm.Annotations["shouldNotTemplate"], "{{ $labels.namespace }}")
357363
})
358364
}
359365
}

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)