Skip to content

Commit

Permalink
ensure proper cleanup of resources standalone and cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Bledi Feshti committed Dec 10, 2024
1 parent 28d6d1d commit 29800c7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 39 deletions.
53 changes: 31 additions & 22 deletions internal/integration_tests/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,35 +167,44 @@ func TestInstallNeo4jClusterWithApocConfigInGcloud(t *testing.T) {

func clusterTestCleanup(t *testing.T, clusterReleaseName model.ReleaseName, core1 clusterCore, core2 clusterCore, core3 clusterCore, removeLabels bool) func() {
return func() {
_ = runAll(t, "kubectl", [][]string{
{"scale", "statefulset", core1.name.String(), "--namespace", string(clusterReleaseName.Namespace()), "--replicas=0"},
{"scale", "statefulset", core2.name.String(), "--namespace", string(clusterReleaseName.Namespace()), "--replicas=0"},
{"scale", "statefulset", core3.name.String(), "--namespace", string(clusterReleaseName.Namespace()), "--replicas=0"},
}, false)

time.Sleep(30 * time.Second)

_ = runAll(t, "helm", [][]string{
{"uninstall", core1.name.String(), core2.name.String(), core3.name.String(), "--cascade=foreground", "--wait", "--timeout", "3m", "--namespace", string(clusterReleaseName.Namespace())},
{"uninstall", clusterReleaseName.String() + "-headless", "--cascade=foreground", "--wait", "--timeout", "1m", "--namespace", string(clusterReleaseName.Namespace())},
}, false)

_ = runAll(t, "kubectl", [][]string{
{"delete", "pvc", "--all", "--namespace", string(clusterReleaseName.Namespace()), "--force", "--grace-period=0"},
{"delete", "pv", "--all", "--force", "--grace-period=0"},
}, false)
namespace := string(clusterReleaseName.Namespace())

err := run(t, "kubectl", "get", "namespace", namespace)
if err == nil {
for _, core := range []clusterCore{core1, core2, core3} {
_ = run(t, "kubectl", "get", "statefulset", core.name.String(), "--namespace", namespace)
if err == nil {
_ = runAll(t, "kubectl", [][]string{
{"scale", "statefulset", core.name.String(), "--namespace", namespace, "--replicas=0"},
}, false)
}
}

time.Sleep(30 * time.Second)

_ = runAll(t, "helm", [][]string{
{"uninstall", core1.name.String(), core2.name.String(), core3.name.String(), "--cascade=foreground", "--wait", "--timeout", "3m", "--namespace", namespace},
{"uninstall", clusterReleaseName.String() + "-headless", "--cascade=foreground", "--wait", "--timeout", "1m", "--namespace", namespace},
}, false)

time.Sleep(10 * time.Second)

_ = runAll(t, "kubectl", [][]string{
{"delete", "pvc", "--all", "--namespace", namespace, "--force", "--grace-period=0", "--ignore-not-found"},
{"delete", "pv", "--all", "--force", "--grace-period=0", "--ignore-not-found"},
}, false)

_ = runAll(t, "kubectl", [][]string{
{"delete", "namespace", namespace, "--force", "--grace-period=0", "--ignore-not-found"},
}, false)
}

_ = runAll(t, "gcloud", [][]string{
{"compute", "disks", "delete", fmt.Sprintf("neo4j-data-disk-%s", core1.name), "--zone=" + string(gcloud.CurrentZone()), "--project=" + string(gcloud.CurrentProject()), "--quiet"},
{"compute", "disks", "delete", fmt.Sprintf("neo4j-data-disk-%s", core2.name), "--zone=" + string(gcloud.CurrentZone()), "--project=" + string(gcloud.CurrentProject()), "--quiet"},
{"compute", "disks", "delete", fmt.Sprintf("neo4j-data-disk-%s", core3.name), "--zone=" + string(gcloud.CurrentZone()), "--project=" + string(gcloud.CurrentProject()), "--quiet"},
}, false)

_ = runAll(t, "kubectl", [][]string{
{"delete", "namespace", string(clusterReleaseName.Namespace()), "--force", "--grace-period=0"},
{"delete", "priorityClass", "high-priority", "--force", "--grace-period=0"},
}, false)

if removeLabels {
_ = removeLabelFromNodes(t)
}
Expand Down
43 changes: 26 additions & 17 deletions internal/integration_tests/standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,37 @@ func standaloneCleanup(t *testing.T, releaseName model.ReleaseName) func() {
return func() {
namespace := string(releaseName.Namespace())

_ = runAll(t, "kubectl", [][]string{
{"scale", "statefulset", releaseName.String(), "--namespace", namespace, "--replicas=0"},
}, false)
err := run(t, "kubectl", "get", "namespace", namespace)
if err == nil {
_ = run(t, "kubectl", "get", "statefulset", releaseName.String(), "--namespace", namespace)
if err == nil {
_ = runAll(t, "kubectl", [][]string{
{"scale", "statefulset", releaseName.String(), "--namespace", namespace, "--replicas=0"},
}, false)

time.Sleep(30 * time.Second)
time.Sleep(30 * time.Second)
}

_ = runAll(t, "helm", [][]string{
{"uninstall", releaseName.String(), "--wait", "--timeout", "3m", "--namespace", namespace},
}, false)
_ = runAll(t, "helm", [][]string{
{"uninstall", releaseName.String(), "--cascade=foreground", "--wait", "--timeout", "3m", "--namespace", namespace},
}, false)

time.Sleep(10 * time.Second)
time.Sleep(10 * time.Second)

_ = runAll(t, "kubectl", [][]string{
{"delete", "statefulset", releaseName.String(), "--namespace", namespace, "--wait=true", "--timeout=60s", "--ignore-not-found"},
{"delete", "pod", "--all", "--namespace", namespace, "--wait=true", "--timeout=60s", "--ignore-not-found"},
{"delete", "pvc", "--all", "--namespace", namespace, "--wait=true", "--timeout=60s", "--ignore-not-found"},
{"delete", "pv", "--all", "--wait=true", "--timeout=60s", "--ignore-not-found"},
}, false)
_ = runAll(t, "kubectl", [][]string{
{"delete", "statefulset", releaseName.String(), "--namespace", namespace, "--force", "--grace-period=0", "--ignore-not-found"},
{"delete", "pod", "--all", "--namespace", namespace, "--force", "--grace-period=0", "--ignore-not-found"},
{"delete", "pvc", "--all", "--namespace", namespace, "--force", "--grace-period=0", "--ignore-not-found"},
}, false)

_ = runAll(t, "kubectl", [][]string{
{"delete", "namespace", namespace, "--ignore-not-found"},
}, false)
_ = runAll(t, "kubectl", [][]string{
{"delete", "pv", "--all", "--force", "--grace-period=0", "--ignore-not-found"},
}, false)

_ = runAll(t, "kubectl", [][]string{
{"delete", "namespace", namespace, "--force", "--grace-period=0", "--ignore-not-found"},
}, false)
}

_ = runAll(t, "gcloud", [][]string{
{"compute", "disks", "delete", fmt.Sprintf("neo4j-data-disk-%s", releaseName), "--zone=" + string(gcloud.CurrentZone()), "--project=" + string(gcloud.CurrentProject()), "--quiet"},
Expand Down

0 comments on commit 29800c7

Please sign in to comment.