From 3f672aafb68fceb33a49b8d06efdd7abc22be64f Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 22 Jun 2023 06:05:20 +0100 Subject: [PATCH 1/2] Failing test for stringifying Secret data --- tests/e2e/gitopsset_controller_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/gitopsset_controller_test.go b/tests/e2e/gitopsset_controller_test.go index 818bfffa..e6327698 100644 --- a/tests/e2e/gitopsset_controller_test.go +++ b/tests/e2e/gitopsset_controller_test.go @@ -569,7 +569,7 @@ func TestReconcilingUpdatingSecret(t *testing.T) { Content: runtime.RawExtension{ Raw: mustMarshalJSON(t, test.NewConfigMap(func(c *corev1.ConfigMap) { c.Data = map[string]string{ - "testing": "{{ .Element.testKey | toString }}", + "testing": "{{ .Element.testKey }}", } })), }, @@ -637,7 +637,7 @@ func TestReconcilingUpdatingSecret_in_matrix(t *testing.T) { Content: runtime.RawExtension{ Raw: mustMarshalJSON(t, test.NewConfigMap(func(c *corev1.ConfigMap) { c.Data = map[string]string{ - "testing": "{{ .Element.testKey | toString }}", + "testing": "{{ .Element.testKey }}", "team": "{{ .Element.team }}", } })), From 1434fc63e2fa273812efa604b1877f171d60c3ca Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 22 Jun 2023 06:17:06 +0100 Subject: [PATCH 2/2] Convert Secret data values to strings This converts all values in a Secret data element to strings when generating. --- controllers/templates/generators/config/config.go | 4 ++-- controllers/templates/generators/config/config_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/templates/generators/config/config.go b/controllers/templates/generators/config/config.go index ac34ede9..d61a8df6 100644 --- a/controllers/templates/generators/config/config.go +++ b/controllers/templates/generators/config/config.go @@ -92,11 +92,11 @@ func secretToParams(ctx context.Context, k8sClient client.Client, key client.Obj return mapToAnyMap(secret.Data), nil } -func mapToAnyMap[V any](m map[string]V) map[string]any { +func mapToAnyMap[V string | []byte](m map[string]V) map[string]any { result := map[string]any{} for k, v := range m { - result[k] = v + result[k] = string(v) } return result diff --git a/controllers/templates/generators/config/config_test.go b/controllers/templates/generators/config/config_test.go index 8a3af653..359f40fb 100644 --- a/controllers/templates/generators/config/config_test.go +++ b/controllers/templates/generators/config/config_test.go @@ -152,8 +152,8 @@ func TestConfigGenerator_Generate(t *testing.T) { }, want: []map[string]any{ { - "test-key1": []byte("test-value1"), - "test-key2": []byte("test-value2"), + "test-key1": "test-value1", + "test-key2": "test-value2", }, }, },