Skip to content

Commit

Permalink
test(e2e): print debug info on namespace delete (#11646)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com>
  • Loading branch information
jakubdyszkiewicz authored Oct 3, 2024
1 parent d9c6b20 commit 1fcc8db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ spec:
E2EAfterEach(func() {
Expect(cluster.TriggerDeleteNamespace(externalServicesNamespace)).To(Succeed())
Expect(cluster.TriggerDeleteNamespace(TestNamespace)).To(Succeed())
cluster.WaitNamespaceDelete(externalServicesNamespace)
cluster.WaitNamespaceDelete(TestNamespace)
Expect(cluster.WaitNamespaceDelete(externalServicesNamespace)).To(Succeed())
Expect(cluster.WaitNamespaceDelete(TestNamespace)).To(Succeed())

Expect(cluster.DeleteKuma()).To(Succeed())
Expect(cluster.DismissCluster()).To(Succeed())
Expand Down
30 changes: 18 additions & 12 deletions test/framework/k8s_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ func (c *K8sCluster) WaitNamespaceCreate(namespace string) {
})
}

func (c *K8sCluster) WaitNamespaceDelete(namespace string) {
retry.DoWithRetry(c.t,
func (c *K8sCluster) WaitNamespaceDelete(namespace string) error {
_, err := retry.DoWithRetryE(c.t,
fmt.Sprintf("Wait for %s Namespace to terminate.", namespace),
c.defaultRetries,
c.defaultTimeout,
Expand All @@ -210,12 +210,22 @@ func (c *K8sCluster) WaitNamespaceDelete(namespace string) {
return "Failed to get Namespace " + namespace, err
}

nsLastCondition := "unknown"
if len(nsObject.Status.Conditions) != 0 {
nsLastCondition = nsObject.Status.Conditions[len(nsObject.Status.Conditions)-1].String()
var conditions []string
for _, condition := range nsObject.Status.Conditions {
conditions = append(conditions, condition.String())
}
return "Namespace available " + namespace, fmt.Errorf("Namespace %s still active, last condition: %s", namespace, nsLastCondition)
return "Namespace available " + namespace, fmt.Errorf("namespace %s still active, conditions: %s", namespace, strings.Join(conditions, ","))
})
if err != nil {
var namespaceStr string
nsObject, err := k8s.GetNamespaceE(c.t, c.GetKubectlOptions(), namespace)
if err == nil {
namespaceStr = "namespace object: " + nsObject.String()
}
all, _ := k8s.RunKubectlAndGetOutputE(c.t, c.GetKubectlOptions(namespace), "get", "all")
return errors.Wrapf(err, "debug data: %s, all in namespace: %s", namespaceStr, all)
}
return err
}

func (c *K8sCluster) WaitNodeDelete(node string) (string, error) {
Expand Down Expand Up @@ -952,9 +962,7 @@ func (c *K8sCluster) deleteKumaViaKumactl() error {
c.GetKubectlOptions(),
yaml)

c.WaitNamespaceDelete(Config.KumaNamespace)

return nil
return c.WaitNamespaceDelete(Config.KumaNamespace)
}

func (c *K8sCluster) DeleteKuma() error {
Expand Down Expand Up @@ -1040,9 +1048,7 @@ func (c *K8sCluster) DeleteNamespace(namespace string) error {
return err
}

c.WaitNamespaceDelete(namespace)

return nil
return c.WaitNamespaceDelete(namespace)
}

func (c *K8sCluster) TriggerDeleteNamespace(namespace string) error {
Expand Down

0 comments on commit 1fcc8db

Please sign in to comment.