Skip to content

Commit

Permalink
Merge pull request #19 from ytsarev/namespace-skip
Browse files Browse the repository at this point in the history
Handle Namespace v1 in the uptest run
  • Loading branch information
sergenyalcin authored Jul 29, 2024
2 parents 34b893e + be9fe26 commit d016c0a
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 3 deletions.
3 changes: 3 additions & 0 deletions internal/templates/00-assert.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 3 additions & 0 deletions internal/templates/01-assert.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}$"
Expand Down
3 changes: 3 additions & 0 deletions internal/templates/01-update.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}}}'
Expand Down
3 changes: 3 additions & 0 deletions internal/templates/02-assert.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions internal/templates/02-import.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 3 additions & 0 deletions internal/templates/03-assert.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 3 additions & 0 deletions internal/templates/03-delete.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
27 changes: 24 additions & 3 deletions internal/templates/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ type: Opaque
data:
key: dmFsdWU=
`

namespaceManifest = `apiVersion: v1
kind: Namespace
metadata:
name: test-namespace
`
)

func TestRender(t *testing.T) {
Expand Down Expand Up @@ -173,6 +179,11 @@ commands:
KindGroup: "secret.",
Namespace: "upbound-system",
},
{
YAML: namespaceManifest,
Name: "test-namespace",
KindGroup: "namespace.",
},
},
},
want: want{
Expand All @@ -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
Expand Down Expand Up @@ -384,6 +395,11 @@ commands:
KindGroup: "secret.",
Namespace: "upbound-system",
},
{
YAML: namespaceManifest,
Name: "test-namespace",
KindGroup: "namespace.",
},
},
},
want: want{
Expand All @@ -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
Expand Down Expand Up @@ -478,6 +494,11 @@ commands:
KindGroup: "secret.",
Namespace: "upbound-system",
},
{
YAML: namespaceManifest,
Name: "test-namespace",
KindGroup: "namespace.",
},
},
},
want: want{
Expand All @@ -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
Expand Down

0 comments on commit d016c0a

Please sign in to comment.