From be9fe26def1d90532128e9815d676f6831615252 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Mon, 22 Jul 2024 13:33:46 +0200 Subject: [PATCH] Handle Namespace v1 in the uptest run * Special skip of the Namespace object similar to Secret * Fixes #18 Signed-off-by: Yury Tsarev --- internal/templates/00-assert.yaml.tmpl | 3 +++ internal/templates/01-assert.yaml.tmpl | 3 +++ internal/templates/01-update.yaml.tmpl | 3 +++ internal/templates/02-assert.yaml.tmpl | 3 +++ internal/templates/02-import.yaml.tmpl | 3 +++ internal/templates/03-assert.yaml.tmpl | 3 +++ internal/templates/03-delete.yaml.tmpl | 3 +++ internal/templates/renderer_test.go | 27 +++++++++++++++++++++++--- 8 files changed, 45 insertions(+), 3 deletions(-) diff --git a/internal/templates/00-assert.yaml.tmpl b/internal/templates/00-assert.yaml.tmpl index 95b184a..8998b56 100644 --- a/internal/templates/00-assert.yaml.tmpl +++ b/internal/templates/00-assert.yaml.tmpl @@ -10,6 +10,9 @@ commands: {{- if eq $resource.KindGroup "secret." -}} {{continue}} {{- end -}} +{{- if eq $resource.KindGroup "namespace." -}} + {{continue}} +{{- end -}} {{- if $resource.PreAssertScriptPath }} - command: {{ $resource.PreAssertScriptPath }} {{- end }} diff --git a/internal/templates/01-assert.yaml.tmpl b/internal/templates/01-assert.yaml.tmpl index c8a83a3..307ed9e 100644 --- a/internal/templates/01-assert.yaml.tmpl +++ b/internal/templates/01-assert.yaml.tmpl @@ -8,6 +8,9 @@ commands: {{- if eq $resource.KindGroup "secret." -}} {{continue}} {{- end -}} +{{- if eq $resource.KindGroup "namespace." -}} + {{continue}} +{{- end -}} {{- if not $resource.Namespace }} {{- if $resource.Root }} - script: ${KUBECTL} get {{ $resource.KindGroup }}/{{ $resource.Name }} -o=jsonpath='{.status.atProvider{{ $resource.UpdateAssertKey }}}' | grep -q "^{{ $resource.UpdateAssertValue }}$" diff --git a/internal/templates/01-update.yaml.tmpl b/internal/templates/01-update.yaml.tmpl index 621e97d..d9bbd9f 100644 --- a/internal/templates/01-update.yaml.tmpl +++ b/internal/templates/01-update.yaml.tmpl @@ -6,6 +6,9 @@ commands: {{- if eq $resource.KindGroup "secret." -}} {{continue}} {{- end -}} +{{- if eq $resource.KindGroup "namespace." -}} + {{continue}} +{{- end -}} {{- if not $resource.Namespace }} {{- if $resource.Root }} - command: ${KUBECTL} patch {{ $resource.KindGroup }}/{{ $resource.Name }} --type=merge -p '{"spec":{"forProvider":{{ $resource.UpdateParameter }}}}' diff --git a/internal/templates/02-assert.yaml.tmpl b/internal/templates/02-assert.yaml.tmpl index ac67afe..ac3aed5 100644 --- a/internal/templates/02-assert.yaml.tmpl +++ b/internal/templates/02-assert.yaml.tmpl @@ -8,6 +8,9 @@ commands: {{- if eq $resource.KindGroup "secret." -}} {{continue}} {{- end -}} +{{- if eq $resource.KindGroup "namespace." -}} + {{continue}} +{{- end -}} {{- range $condition := $resource.Conditions }} {{- if not $resource.Namespace }} - command: ${KUBECTL} wait {{ $resource.KindGroup }}/{{ $resource.Name }} --for=condition={{ $condition }} --timeout 10s diff --git a/internal/templates/02-import.yaml.tmpl b/internal/templates/02-import.yaml.tmpl index 1fd4392..5f73b8f 100644 --- a/internal/templates/02-import.yaml.tmpl +++ b/internal/templates/02-import.yaml.tmpl @@ -15,6 +15,9 @@ commands: {{- if eq $resource.KindGroup "secret." -}} {{continue}} {{- end -}} +{{- if eq $resource.KindGroup "namespace." -}} + {{continue}} +{{- end -}} {{- if not $resource.Namespace }} - script: /tmp/patch.sh {{ $resource.KindGroup }} {{ $resource.Name }} {{- end }} diff --git a/internal/templates/03-assert.yaml.tmpl b/internal/templates/03-assert.yaml.tmpl index f3b9315..e0041ca 100644 --- a/internal/templates/03-assert.yaml.tmpl +++ b/internal/templates/03-assert.yaml.tmpl @@ -9,6 +9,9 @@ commands: {{- if eq $resource.KindGroup "secret." -}} {{continue}} {{- end -}} +{{- if eq $resource.KindGroup "namespace." -}} + {{continue}} +{{- end -}} {{- if $resource.Namespace }} - script: ${KUBECTL} wait {{ $resource.KindGroup }}/{{ $resource.Name }} --for=delete --timeout 10s --namespace {{ $resource.Namespace }} {{- else }} diff --git a/internal/templates/03-delete.yaml.tmpl b/internal/templates/03-delete.yaml.tmpl index c291505..a2e2d3a 100644 --- a/internal/templates/03-delete.yaml.tmpl +++ b/internal/templates/03-delete.yaml.tmpl @@ -6,6 +6,9 @@ commands: {{- if eq $resource.KindGroup "secret." -}} {{continue}} {{- end -}} +{{- if eq $resource.KindGroup "namespace." -}} + {{continue}} +{{- end -}} {{- if $resource.PreDeleteScriptPath }} - command: {{ $resource.PreDeleteScriptPath }} {{- end }} diff --git a/internal/templates/renderer_test.go b/internal/templates/renderer_test.go index 5104883..e20072b 100644 --- a/internal/templates/renderer_test.go +++ b/internal/templates/renderer_test.go @@ -43,6 +43,12 @@ type: Opaque data: key: dmFsdWU= ` + + namespaceManifest = `apiVersion: v1 +kind: Namespace +metadata: + name: test-namespace +` ) func TestRender(t *testing.T) { @@ -173,6 +179,11 @@ commands: KindGroup: "secret.", Namespace: "upbound-system", }, + { + YAML: namespaceManifest, + Name: "test-namespace", + KindGroup: "namespace.", + }, }, }, want: want{ @@ -182,7 +193,7 @@ apiVersion: kuttl.dev/v1beta1 kind: TestStep commands: - command: /tmp/setup.sh -` + "---\n" + bucketManifest + "---\n" + claimManifest + "---\n" + secretManifest, +` + "---\n" + bucketManifest + "---\n" + claimManifest + "---\n" + secretManifest + "---\n" + namespaceManifest, "00-assert.yaml": `# This assert file belongs to the resource apply step. apiVersion: kuttl.dev/v1beta1 kind: TestAssert @@ -384,6 +395,11 @@ commands: KindGroup: "secret.", Namespace: "upbound-system", }, + { + YAML: namespaceManifest, + Name: "test-namespace", + KindGroup: "namespace.", + }, }, }, want: want{ @@ -393,7 +409,7 @@ apiVersion: kuttl.dev/v1beta1 kind: TestStep commands: - command: /tmp/setup.sh -` + "---\n" + bucketManifest + "---\n" + claimManifest + "---\n" + secretManifest, +` + "---\n" + bucketManifest + "---\n" + claimManifest + "---\n" + secretManifest + "---\n" + namespaceManifest, "00-assert.yaml": `# This assert file belongs to the resource apply step. apiVersion: kuttl.dev/v1beta1 kind: TestAssert @@ -478,6 +494,11 @@ commands: KindGroup: "secret.", Namespace: "upbound-system", }, + { + YAML: namespaceManifest, + Name: "test-namespace", + KindGroup: "namespace.", + }, }, }, want: want{ @@ -487,7 +508,7 @@ apiVersion: kuttl.dev/v1beta1 kind: TestStep commands: - command: /tmp/setup.sh -` + "---\n" + bucketManifest + "---\n" + claimManifest + "---\n" + secretManifest, +` + "---\n" + bucketManifest + "---\n" + claimManifest + "---\n" + secretManifest + "---\n" + namespaceManifest, "00-assert.yaml": `# This assert file belongs to the resource apply step. apiVersion: kuttl.dev/v1beta1 kind: TestAssert