Skip to content

Commit

Permalink
Delete left over resources
Browse files Browse the repository at this point in the history
Signed-off-by: Sridhar Gaddam <[email protected]>
  • Loading branch information
sridhargaddam committed Dec 27, 2024
1 parent e281e30 commit 208fe2a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
39 changes: 33 additions & 6 deletions tests/e2e/ambient/ambient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package ambient

import (
"fmt"
"strings"
"time"

"github.com/Masterminds/semver/v3"
Expand Down Expand Up @@ -263,7 +264,7 @@ spec:

When("the Istio CR is deleted", func() {
BeforeEach(func() {
Expect(k.WithNamespace(controlPlaneNamespace).Delete("istio", istioName)).To(Succeed(), "Istio CR failed to be deleted")
Expect(k.Delete("istio", istioName)).To(Succeed(), "Istio CR failed to be deleted")
Success("Istio CR deleted")
})

Expand All @@ -277,7 +278,7 @@ spec:

When("the IstioCNI CR is deleted", func() {
BeforeEach(func() {
Expect(k.WithNamespace(istioCniNamespace).Delete("istiocni", istioCniName)).To(Succeed(), "IstioCNI CR failed to be deleted")
Expect(k.Delete("istiocni", istioCniName)).To(Succeed(), "IstioCNI CR failed to be deleted")
Success("IstioCNI deleted")
})

Expand All @@ -292,7 +293,7 @@ spec:

When("the ZTunnel CR is deleted", func() {
BeforeEach(func() {
Expect(k.WithNamespace(istioCniNamespace).Delete("ztunnel", istioCniName)).To(Succeed(), "ZTunnel CR failed to be deleted")
Expect(k.Delete("ztunnel", "default")).To(Succeed(), "ZTunnel CR failed to be deleted")
Success("ZTunnel deleted")
})

Expand All @@ -314,13 +315,18 @@ spec:
}

By("Cleaning up the Istio namespace")
Expect(cl.Delete(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: controlPlaneNamespace}})).To(Succeed(), "Istio Namespace failed to be deleted")
Expect(k.DeleteNamespace(controlPlaneNamespace)).To(Succeed(), "Istio Namespace failed to be deleted")

By("Cleaning up the IstioCNI namespace")
Expect(cl.Delete(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: istioCniNamespace}})).To(Succeed(), "IstioCNI Namespace failed to be deleted")
Expect(k.DeleteNamespace(istioCniNamespace)).To(Succeed(), "IstioCNI Namespace failed to be deleted")

By("Cleaning up the ZTunnel namespace")
Expect(cl.Delete(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ztunnelNamespace}})).To(Succeed(), "ZTunnel Namespace failed to be deleted")
Expect(k.DeleteNamespace(ztunnelNamespace)).To(Succeed(), "ZTunnel Namespace failed to be deleted")

By("Deleting any left-over Istio and IstioRevision resources")
Expect(forceDeleteIstioResources()).To(Succeed())
Success("Resources deleted")
Success("Cleanup done")
})
})

Expand Down Expand Up @@ -357,6 +363,27 @@ func getEnvVars(container corev1.Container) []corev1.EnvVar {
return container.Env
}

func forceDeleteIstioResources() error {
// This is a workaround to delete the Istio CRs that are left in the cluster
// This will be improved by splitting the tests into different Nodes with their independent setups and cleanups
err := k.ForceDelete("istio", istioName)
if err != nil && !strings.Contains(err.Error(), "not found") {
return fmt.Errorf("failed to delete %s CR: %w", "istio", err)
}

err = k.ForceDelete("istiorevision", "default")
if err != nil && !strings.Contains(err.Error(), "not found") {
return fmt.Errorf("failed to delete %s CR: %w", "istiorevision", err)
}

err = k.Delete("istiocni", istioCniName)
if err != nil && !strings.Contains(err.Error(), "not found") {
return fmt.Errorf("failed to delete %s CR: %w", "istiocni", err)
}

return nil
}

func checkPodConnectivity(podName, srcNamespace, destNamespace string) {
command := fmt.Sprintf(`curl -o /dev/null -s -w "%%{http_code}\n" httpbin.%s.svc.cluster.local:8000/get`, destNamespace)
response, err := k.WithNamespace(srcNamespace).Exec(podName, srcNamespace, command)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/common-operator-integ-suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,4 @@ fi
IMAGE="${HUB}/${IMAGE_BASE}:${TAG}" SKIP_DEPLOY="${SKIP_DEPLOY}" OCP="${OCP}" IP_FAMILY="${IP_FAMILY}" ISTIO_MANIFEST="${ISTIO_MANIFEST}" \
NAMESPACE="${NAMESPACE}" CONTROL_PLANE_NS="${CONTROL_PLANE_NS}" DEPLOYMENT_NAME="${DEPLOYMENT_NAME}" MULTICLUSTER="${MULTICLUSTER}" ARTIFACTS="${ARTIFACTS}" \
ISTIO_NAME="${ISTIO_NAME}" COMMAND="${COMMAND}" VERSIONS_YAML_FILE="${VERSIONS_YAML_FILE}" KUBECONFIG="${KUBECONFIG}" ISTIOCTL_PATH="${ISTIOCTL}" \
go run github.com/onsi/ginkgo/v2/ginkgo -tags e2e --timeout 30m --junit-report=report.xml ${GINKGO_FLAGS} "${WD}"/...
go run github.com/onsi/ginkgo/v2/ginkgo -tags e2e --timeout 30m --junit-report=report.xml ${GINKGO_FLAGS} --fail-fast "${WD}"/...
7 changes: 5 additions & 2 deletions tests/e2e/controlplane/control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controlplane

import (
"fmt"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -52,6 +53,7 @@ var _ = Describe("Control Plane Installation", Ordered, func() {
extraArg = "--set=platform=openshift"
}

fmt.Println("go version is:: ", runtime.Version())
if skipDeploy {
Success("Skipping operator installation because it was deployed externally")
} else {
Expand Down Expand Up @@ -119,6 +121,7 @@ metadata:
for _, version := range supportedversion.List {
Context(version.Name, func() {
BeforeAll(func() {
fmt.Println("go version is:: ", runtime.Version())
Expect(k.CreateNamespace(controlPlaneNamespace)).To(Succeed(), "Istio namespace failed to be created")
Expect(k.CreateNamespace(istioCniNamespace)).To(Succeed(), "IstioCNI namespace failed to be created")
})
Expand Down Expand Up @@ -305,10 +308,10 @@ spec:
}

By("Cleaning up the Istio namespace")
Expect(cl.Delete(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: controlPlaneNamespace}})).To(Succeed(), "Istio Namespace failed to be deleted")
Expect(k.DeleteNamespace(controlPlaneNamespace)).To(Succeed(), "Istio Namespace failed to be deleted")

By("Cleaning up the IstioCNI namespace")
Expect(cl.Delete(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: istioCniNamespace}})).To(Succeed(), "IstioCNI Namespace failed to be deleted")
Expect(k.DeleteNamespace(istioCniNamespace)).To(Succeed(), "IstioCNI Namespace failed to be deleted")

By("Deleting any left-over Istio and IstioRevision resources")
Expect(forceDeleteIstioResources()).To(Succeed())
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/util/common/e2e_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func logOperatorDebugInfo(k kubectl.Kubectl) {
operator, err := k.GetYAML("deployment", deploymentName)
logDebugElement("=====Operator Deployment YAML=====", operator, err)

logs, err := k.Logs("deploy/"+deploymentName, ptr.Of(120*time.Second))
logs, err := k.Logs("deploy/"+deploymentName, ptr.Of(120*time.Minute))
logDebugElement("=====Operator logs=====", logs, err)

events, err := k.GetEvents()
Expand Down

0 comments on commit 208fe2a

Please sign in to comment.