From b16e4ec566ddc70f6c393ca2cf5fecbfe94c2bc1 Mon Sep 17 00:00:00 2001 From: Julian van den Berkmortel Date: Wed, 10 Nov 2021 21:29:27 +0100 Subject: [PATCH] add test to demonstrate internal annotations getting lost (#4111) --- api/krusty/multiplepatch_test.go | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/api/krusty/multiplepatch_test.go b/api/krusty/multiplepatch_test.go index 5fb5fed3f..0d0e40e1c 100644 --- a/api/krusty/multiplepatch_test.go +++ b/api/krusty/multiplepatch_test.go @@ -1646,3 +1646,64 @@ spec: type: NodePort `) } + +// test for #4111, currently demonstrates incorrect behaviour +func TestPatchPreservesInternalAnnotations(t *testing.T) { + th := kusttest_test.MakeHarness(t) + th.WriteK(".", ` +nameSuffix: -abc +resources: + - fluentd.yaml +patchesJson6902: + - path: patch.yaml + target: + name: fluentd-sa + kind: ServiceAccount + version: v1 +`) + th.WriteF("fluentd.yaml", ` +apiVersion: v1 +kind: DaemonSet +metadata: + name: fluentd +spec: + template: + spec: + containers: + - image: fluentd:latest + name: fluentd + serviceAccountName: fluentd-sa +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: fluentd-sa +`) + th.WriteF("patch.yaml", ` +- op: add + path: /metadata/annotations + value: + note: this is a test annotation +`) + m := th.Run(".", th.MakeDefaultOptions()) + th.AssertActualEqualsExpected(m, ` +apiVersion: v1 +kind: DaemonSet +metadata: + name: fluentd-abc +spec: + template: + spec: + containers: + - image: fluentd:latest + name: fluentd + serviceAccountName: fluentd-sa +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + annotations: + note: this is a test annotation + name: fluentd-sa-abc +`) +} \ No newline at end of file