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

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

commit 7f5a0b79d7107640cba4cb1ff2f5d1fe8c065fbd
Author: phantomjinx <[email protected]>
AuthorDate: Fri Mar 11 15:20:12 2022 +0000

    fix(e2e-testing): Ensures changes to Proxy CR are cleaned up
    
    * Possible for proxy test to fail and the Proxy CR left pointing at a
      defunct service. Mandates that the Proxy CR is always returned to its
      default state.
    
    * Adds to e2e-testing cleanup action as check
---
 .github/actions/kamel-cleanup/cleanup.sh  | 39 ++++++++++++++++++++++++++++++-
 e2e/common/build/maven_http_proxy_test.go | 20 +++++++++++-----
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/.github/actions/kamel-cleanup/cleanup.sh 
b/.github/actions/kamel-cleanup/cleanup.sh
index 47e48e76d..da4ef64aa 100755
--- a/.github/actions/kamel-cleanup/cleanup.sh
+++ b/.github/actions/kamel-cleanup/cleanup.sh
@@ -48,9 +48,46 @@ while getopts ":c:i:x:" opt; do
 done
 shift $((OPTIND-1))
 
+#
+# Reset the proxy to default if using an OLM
+# which would require a catalogsource
+#
+if [ -n "${BUILD_CATALOG_SOURCE}" ]; then
+  set +e
+
+#
+# Remove values altogther
+#
+  PATCH=$(mktemp /tmp/proxy-patch.XXXXXXXX)
+  cat >${PATCH} <<EOF
+[
+  {
+    "op": "replace",
+    "path": "/spec",
+    "value": {}
+  },
+  {
+    "op": "replace",
+    "path": "/status",
+    "value": {}
+  }
+]
+EOF
+
+  kubectl patch --type='json' Proxy cluster --patch-file "${PATCH}"
+
+  if [ $? != 0 ]; then
+    echo "Error: Failed to reset the Proxy"
+    exit 1
+  fi
+
+  rm -f "${PATCH}"
+
+  set -e
+fi
 
 if [ "${SAVE_NAMESPACES}" == "true" ]; then
-  echo "Skipping cleanup since SAVE_NAMESPACES has been set to true"
+  echo "Skipping remaining cleanup since SAVE_NAMESPACES has been set to true"
   exit 0
 fi
 
diff --git a/e2e/common/build/maven_http_proxy_test.go 
b/e2e/common/build/maven_http_proxy_test.go
index 9a6e35eb6..1ccc91c43 100644
--- a/e2e/common/build/maven_http_proxy_test.go
+++ b/e2e/common/build/maven_http_proxy_test.go
@@ -29,8 +29,6 @@ import (
        "crypto/x509/pkix"
        "encoding/pem"
        "fmt"
-       "github.com/apache/camel-k/pkg/util/kubernetes"
-       "github.com/apache/camel-k/pkg/util/olm"
        "math/big"
        rand2 "math/rand"
        "reflect"
@@ -38,6 +36,9 @@ import (
        "testing"
        "time"
 
+       "github.com/apache/camel-k/pkg/util/kubernetes"
+       "github.com/apache/camel-k/pkg/util/olm"
+
        . "github.com/onsi/gomega"
        . "github.com/onsi/gomega/gstruct"
 
@@ -45,6 +46,7 @@ import (
        appsv1 "k8s.io/api/apps/v1"
        corev1 "k8s.io/api/core/v1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+       "k8s.io/apimachinery/pkg/types"
        "k8s.io/apimachinery/pkg/util/intstr"
 
        ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -163,6 +165,16 @@ func TestMavenProxy(t *testing.T) {
                        newProxy.Spec.NoProxy = strings.Join(noProxy, ",")
                        Expect(TestClient().Update(TestContext, newProxy))
 
+                       defer func() {
+                               //
+                               // Patching the proxy back to default
+                               // Note. A merge patch or client update making 
spec and status empty
+                               //       does not work on some platforms, eg. 
OCP4
+                               //
+                               patch := []byte(`[{"op": "replace","path": 
"/spec","value": {}},{"op": "replace","path": "/status","value": {}}]`)
+                               TestClient().Patch(TestContext, &defaultProxy, 
ctrl.RawPatch(types.JSONPatchType, patch))
+                       }()
+
                        // ENV values should be injected by the OLM
                        Expect(Kamel("install", "-n", 
ns).Execute()).To(Succeed())
 
@@ -209,10 +221,6 @@ func TestMavenProxy(t *testing.T) {
                Expect(TestClient().Delete(TestContext, service)).To(Succeed())
                Expect(TestClient().Delete(TestContext, secret)).To(Succeed())
                Expect(TestClient().Delete(TestContext, config)).To(Succeed())
-
-               if olmInstall {
-                       TestClient().Update(TestContext, &defaultProxy)
-               }
        })
 }
 

Reply via email to