Skip to content

Commit d0e4887

Browse files
committed
add cleanup
Signed-off-by: Maksim Fedotov <maksim.fedotov@flant.com>
1 parent 41ee455 commit d0e4887

5 files changed

Lines changed: 40 additions & 21 deletions

File tree

.github/workflows/dev_module_build.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,13 @@ jobs:
551551
run: |
552552
task run -v
553553
554+
- name: Cleanup E2E resources on cancel
555+
if: always() && (steps.e2e-tests.outcome == 'cancelled' || steps.e2e-tests.outcome == 'failure')
556+
id: e2e-tests-cleanup
557+
working-directory: ./tests/e2e/
558+
run: |
559+
task cleanup
560+
554561
last_comment:
555562
name: Update comment on finish
556563
needs:

tests/e2e/Taskfile.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,16 @@ tasks:
104104
{{if .FOCUS -}}
105105
--focus "{{ .FOCUS }}"
106106
{{end}}
107+
cleanup:
108+
desc: "Cleanup namespaces & resources left from e2e tests"
109+
deps:
110+
- kubectl
111+
- d8
112+
cmds:
113+
- |
114+
E2E_PREFIX=head-$(git rev-parse --short HEAD)
115+
readarray -t CLEANUP_RESOURCES < <(yq .cleanupResources[] default_config.yaml)
116+
for RESOURCE in "${CLEANUP_RESOURCES[@]}"; do
117+
kubectl get $RESOURCE --no-headers | awk "/$E2E_PREFIX/{print \$1}" | xargs kubectl delete $RESOURCE
118+
done
119+
kubectl get namespaces --no-headers | awk "/$E2E_PREFIX/{print \$1}" | xargs kubectl delete namespaces

tests/e2e/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ type Config struct {
131131
Namespace string `yaml:"namespaceSuffix"`
132132
TestData TestData `yaml:"testData"`
133133
LogFilter []string `yaml:"logFilter"`
134+
CleanupResources []string `yaml:"cleanupResources"`
134135
RegexpLogFilter []regexp.Regexp `yaml:"regexpLogFilter"`
135136
StorageClass StorageClass
136137
}

tests/e2e/default_config.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ logFilter:
5252
- "get storage class specified in spec: storage class not found" # Err.
5353
- "lastTransitionTime: Required value" # Err.
5454
- "virtualmachineipaddressleases.virtualization.deckhouse.io "
55-
regexpLogFilter:
5655
- "failed to detach: .* not found" # "err" "failed to detach: virtualmachine.kubevirt.io \"head-497d17b-vm-automatic-with-hotplug\" not found",
5756
- "error patching .* not found" # "err" "error patching *** virtualimages.virtualization.deckhouse.io \"head-497d17b-vi-pvc-oref-vi-oref-vd\" not found",
57+
58+
cleanupResources:
59+
- clustervirtualimages.virtualization.deckhouse.io
60+
- virtualmachineclasses.virtualization.deckhouse.io
61+
- replicatedstorageclasses.storage.deckhouse.io
62+
- virtualmachineipaddressleases.virtualization.deckhouse.io

tests/e2e/tests_suite_test.go

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -210,26 +210,19 @@ func Cleanup() []error {
210210
continue
211211
}
212212
}
213-
214-
res = kubectl.Delete(kc.DeleteOptions{
215-
IgnoreNotFound: true,
216-
Labels: map[string]string{"id": namePrefix},
217-
Resource: kc.ResourceCVI,
218-
})
219-
if res.Error() != nil {
220-
cleanupErrs = append(
221-
cleanupErrs, fmt.Errorf("cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()),
222-
)
223-
}
224-
res = kubectl.Delete(kc.DeleteOptions{
225-
IgnoreNotFound: true,
226-
Labels: map[string]string{"id": namePrefix},
227-
Resource: kc.ResourceVMClass,
228-
})
229-
if res.Error() != nil {
230-
cleanupErrs = append(
231-
cleanupErrs, fmt.Errorf("cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()),
232-
)
213+
214+
for _, r := range conf.CleanupResources {
215+
res = kubectl.Delete(kc.DeleteOptions{
216+
IgnoreNotFound: true,
217+
Labels: map[string]string{"id": namePrefix},
218+
Resource: kc.Resource(r),
219+
})
220+
if res.Error() != nil {
221+
cleanupErrs = append(
222+
cleanupErrs, fmt.Errorf("cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()),
223+
)
224+
continue
225+
}
233226
}
234227

235228
return cleanupErrs

0 commit comments

Comments
 (0)