This is an automated email from the ASF dual-hosted git repository.

tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 7591e0fb7a1bc3bcbca7a5d767101a4290623580
Author: phantomjinx <[email protected]>
AuthorDate: Fri Sep 23 13:44:40 2022 +0100

    (e2e): check if namespace already exists
    
    * If test namespace exists then create a different one with extra suffix
---
 e2e/support/test_support.go | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 4e4f0013f..aa1761d75 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -2161,6 +2161,19 @@ func deleteTestNamespace(t *testing.T, ns ctrl.Object) {
        }
 }
 
+func testNamespaceExists(ns string) (bool, error) {
+       _, err := TestClient().CoreV1().Namespaces().Get(TestContext, ns, 
metav1.GetOptions{})
+       if err != nil {
+               if k8serrors.IsNotFound(err) {
+                       return false, nil
+               } else {
+                       return false, err
+               }
+       }
+
+       return true, nil
+}
+
 func newTestNamespace(injectKnativeBroker bool) ctrl.Object {
        brokerLabel := "eventing.knative.dev/injection"
        name := os.Getenv("CAMEL_K_TEST_NS")
@@ -2169,6 +2182,13 @@ func newTestNamespace(injectKnativeBroker bool) 
ctrl.Object {
        }
        c := TestClient()
 
+       if exists, err := testNamespaceExists(name); err != nil {
+               failTest(err)
+       } else if exists {
+               fmt.Println("Warning: namespace ", name, " already exists so 
using different namespace name")
+               name = fmt.Sprintf("%s-%d", name, time.Now().Second())
+       }
+
        if oc, err := openshift.IsOpenShift(TestClient()); err != nil {
                failTest(err)
        } else if oc {

Reply via email to