Skip to content

Commit 5566708

Browse files
Merge pull request #712 from tmshort/fix-OCPBUGS-84943
OCPBUGS-84943: fix(test): drop blocking namespace-deletion wait between both-watch-modes scenarios
2 parents 50cdb2a + 28ae4f8 commit 5566708

1 file changed

Lines changed: 13 additions & 20 deletions

File tree

openshift/tests-extension/test/olmv1-singleownnamespace.go

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
appsv1 "k8s.io/api/apps/v1"
1414
corev1 "k8s.io/api/core/v1"
1515
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
16-
"k8s.io/apimachinery/pkg/api/errors"
1716
"k8s.io/apimachinery/pkg/api/meta"
1817
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1918
"k8s.io/apimachinery/pkg/util/rand"
@@ -417,7 +416,7 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace] OLMv1 ope
417416
DeferCleanup(func() {
418417
By(fmt.Sprintf("cleanup: deleting ClusterExtension %s", ce.Name))
419418
_ = k8sClient.Delete(context.Background(), ce, client.PropagationPolicy(metav1.DeletePropagationForeground))
420-
helpers.EnsureCleanupClusterExtension(context.Background(), ceName, nsName)
419+
helpers.EnsureCleanupClusterExtension(context.Background(), packageName, crdName)
421420
})
422421

423422
By(fmt.Sprintf("waiting for the ClusterExtension %s to be installed for %s scenario", ceName, sc.label))
@@ -445,33 +444,27 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMOwnSingleNamespace] OLMv1 ope
445444
g.Expect(found).To(BeTrue(), "failed to find deployment with olm.targetNamespaces annotation")
446445
}).WithTimeout(helpers.DefaultTimeout).WithPolling(helpers.DefaultPolling).Should(Succeed())
447446

448-
// Ginkgo never invokes those deferred cleanups until we exit the whole spec, so the first scenario’s
449-
// cluster resources survive long enough to collide with the second scenario.
450-
By(fmt.Sprintf("cleaning up resources created for %s scenario to allow next scenario", sc.label))
447+
// DeferCleanup handlers don’t run between loop iterations; they fire after the whole spec exits.
448+
// Explicitly clean up cluster-scoped resources (CE, CRD) so EnsureCleanupClusterExtension can
449+
// block until COS teardown completes before the next scenario starts. Unique names per scenario
450+
// prevent any resource collision regardless.
451+
By(fmt.Sprintf("cleaning up resources created for %s scenario before next scenario", sc.label))
451452
deletePolicy := metav1.DeletePropagationForeground
452453
Expect(k8sClient.Delete(ctx, ce, client.PropagationPolicy(deletePolicy))).To(Succeed(), "failed to delete ClusterExtension %q", ceName)
453454
helpers.EnsureCleanupClusterExtension(context.Background(), packageName, crdName)
454455

455456
Expect(k8sClient.Delete(ctx, crb, client.PropagationPolicy(deletePolicy))).To(Succeed(), "failed to delete ClusterRoleBinding %q", crbName)
456457
Expect(k8sClient.Delete(ctx, sa, client.PropagationPolicy(deletePolicy))).To(Succeed(), "failed to delete ServiceAccount %q", saName)
457458

459+
// Trigger namespace deletion and proceed without blocking. By this point
460+
// EnsureCleanupClusterExtension has completed, meaning the ClusterObjectSet
461+
// teardown has deleted all managed resources (Deployment, Service, etc.) and the
462+
// CRD is gone. Each scenario uses unique namespace names and CRD groups, so the
463+
// terminating namespace from scenario 1 cannot interfere with scenario 2.
458464
if watchNSObj != nil {
459-
Expect(k8sClient.Delete(ctx, watchNSObj, client.PropagationPolicy(deletePolicy))).To(Succeed(), "failed to delete watch namespace %q", watchNamespace)
460-
}
461-
Expect(k8sClient.Delete(ctx, installNS, client.PropagationPolicy(deletePolicy))).To(Succeed(), "failed to delete install namespace %q", installNamespace)
462-
463-
By(fmt.Sprintf("waiting for namespace %s to be fully deleted before next scenario", installNamespace))
464-
Eventually(func() bool {
465-
err := k8sClient.Get(ctx, client.ObjectKey{Name: installNamespace}, &corev1.Namespace{})
466-
return errors.IsNotFound(err)
467-
}).WithTimeout(helpers.DefaultTimeout).WithPolling(helpers.DefaultPolling).Should(BeTrue(), "expected namespace %s to be deleted", installNamespace)
468-
if watchNSObj != nil {
469-
By(fmt.Sprintf("waiting for namespace %s to be fully deleted before next scenario", watchNamespace))
470-
Eventually(func() bool {
471-
err := k8sClient.Get(ctx, client.ObjectKey{Name: watchNamespace}, &corev1.Namespace{})
472-
return errors.IsNotFound(err)
473-
}).WithTimeout(helpers.DefaultTimeout).WithPolling(helpers.DefaultPolling).Should(BeTrue(), "expected namespace %s to be deleted", watchNamespace)
465+
_ = k8sClient.Delete(ctx, watchNSObj, client.PropagationPolicy(deletePolicy))
474466
}
467+
_ = k8sClient.Delete(ctx, installNS, client.PropagationPolicy(deletePolicy))
475468
}
476469
})
477470
})

0 commit comments

Comments
 (0)