Skip to content

Commit

Permalink
Merge pull request #27 from crossplane/backport-26-to-release-1.1
Browse files Browse the repository at this point in the history
[Backport release-1.1] Fix the case when Claim and XR are in the same test run
  • Loading branch information
sergenyalcin authored Sep 3, 2024
2 parents 4fe9322 + 06182ac commit f6d8b64
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/templates/00-apply.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ spec:
try:
- apply:
file: {{ .TestCase.TestDirectory }}
- script:
content: |
echo "Runnning annotation script"
{{- range $i, $resource := .Resources }}
{{- if eq $resource.KindGroup "secret." -}}
{{continue}}
{{- end -}}
{{- if not $resource.Namespace }}
{{- if eq $i 0}}
- script:
content: |
{{- end }}
${KUBECTL} annotate {{ $resource.KindGroup }}/{{ $resource.Name }} upjet.upbound.io/test=true --overwrite
{{- end }}
{{- end }}
Expand Down
106 changes: 106 additions & 0 deletions internal/templates/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ spec:
file: /tmp/test-input.yaml
- script:
content: |
echo "Runnning annotation script"
${KUBECTL} annotate s3.aws.upbound.io/example-bucket upjet.upbound.io/test=true --overwrite
- name: Assert Status Conditions
description: |
Expand Down Expand Up @@ -292,6 +293,7 @@ spec:
file: /tmp/test-input.yaml
- script:
content: |
echo "Runnning annotation script"
${KUBECTL} annotate s3.aws.upbound.io/example-bucket upjet.upbound.io/test=true --overwrite
- name: Assert Status Conditions
description: |
Expand Down Expand Up @@ -517,6 +519,7 @@ spec:
file: /tmp/test-input.yaml
- script:
content: |
echo "Runnning annotation script"
${KUBECTL} annotate s3.aws.upbound.io/example-bucket upjet.upbound.io/test=true --overwrite
- name: Assert Status Conditions
description: |
Expand Down Expand Up @@ -680,6 +683,7 @@ spec:
file: /tmp/test-input.yaml
- script:
content: |
echo "Runnning annotation script"
${KUBECTL} annotate s3.aws.upbound.io/example-bucket upjet.upbound.io/test=true --overwrite
- name: Assert Status Conditions
description: |
Expand Down Expand Up @@ -850,6 +854,7 @@ spec:
file: /tmp/test-input.yaml
- script:
content: |
echo "Runnning annotation script"
${KUBECTL} annotate s3.aws.upbound.io/example-bucket upjet.upbound.io/test=true --overwrite
- name: Assert Status Conditions
description: |
Expand Down Expand Up @@ -1012,6 +1017,94 @@ spec:
try:
- apply:
file: /tmp/test-input.yaml
- script:
content: |
echo "Runnning annotation script"
- name: Assert Status Conditions
description: |
Assert applied resources. First, run the pre-assert script if exists.
Then, check the status conditions. Finally run the post-assert script if it
exists.
try:
- assert:
resource:
apiVersion: cluster.gcp.platformref.upbound.io/v1alpha1
kind: Cluster
metadata:
name: test-cluster-claim
namespace: upbound-system
status:
((conditions[?type == 'Ready'])[0]):
status: "True"
((conditions[?type == 'Synced'])[0]):
status: "True"
- command:
entrypoint: /tmp/claim/post-assert.sh
`,
},
},
},
"SuccessClaimAndXR": {
args: args{
tc: &config.TestCase{
Timeout: 10 * time.Minute,
SetupScriptPath: "/tmp/setup.sh",
TeardownScriptPath: "/tmp/teardown.sh",
TestDirectory: "/tmp/test-input.yaml",
SkipUpdate: true,
SkipImport: true,
},
resources: []config.Resource{
{
YAML: claimManifest,
APIVersion: "cluster.gcp.platformref.upbound.io/v1alpha1",
Kind: "Cluster",
Name: "test-cluster-claim",
KindGroup: "cluster.gcp.platformref.upbound.io",
Namespace: "upbound-system",
PostAssertScriptPath: "/tmp/claim/post-assert.sh",
PreDeleteScriptPath: "/tmp/claim/pre-delete.sh",
Conditions: []string{"Ready", "Synced"},
},
{
YAML: claimManifest,
APIVersion: "xnetwork.gcp.platformref.upbound.io/v1alpha1",
Kind: "XNetwork",
Name: "test-network-xr",
KindGroup: "xnetwork.gcp.platformref.upbound.io",
PostAssertScriptPath: "/tmp/claim/post-assert.sh",
PreDeleteScriptPath: "/tmp/claim/pre-delete.sh",
Conditions: []string{"Ready", "Synced"},
},
},
},
want: want{
out: map[string]string{
"00-apply.yaml": `# This file belongs to the resource apply step.
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: apply
spec:
timeouts:
apply: 10m0s
assert: 10m0s
exec: 10m0s
steps:
- name: Run Setup Script
description: Setup the test environment by running the setup script.
try:
- command:
entrypoint: /tmp/setup.sh
- name: Apply Resources
description: Apply resources to the cluster.
try:
- apply:
file: /tmp/test-input.yaml
- script:
content: |
echo "Runnning annotation script"
${KUBECTL} annotate xnetwork.gcp.platformref.upbound.io/test-network-xr upjet.upbound.io/test=true --overwrite
- name: Assert Status Conditions
description: |
Assert applied resources. First, run the pre-assert script if exists.
Expand All @@ -1032,6 +1125,19 @@ spec:
status: "True"
- command:
entrypoint: /tmp/claim/post-assert.sh
- assert:
resource:
apiVersion: xnetwork.gcp.platformref.upbound.io/v1alpha1
kind: XNetwork
metadata:
name: test-network-xr
status:
((conditions[?type == 'Ready'])[0]):
status: "True"
((conditions[?type == 'Synced'])[0]):
status: "True"
- command:
entrypoint: /tmp/claim/post-assert.sh
`,
},
},
Expand Down

0 comments on commit f6d8b64

Please sign in to comment.