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

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

commit e6f48618e337f3135afc96ef2001d7cf50950d17
Author: phantomjinx <[email protected]>
AuthorDate: Wed Nov 17 13:51:44 2021 +0000

    Fixes failure in OLM upgrade e2e tests
    
    * Makefile
     * Updates LAST RELEASED VERSION to 1.6.1 as this is included in the
       released index image. 1.7.0 needs to replace this rather than 1.6.0
     * Adds pre-bundle rule for updating the CSV manifest prior to building
       the bundle
    
    * actions
     * Adds more checking to ensure the action is performing as expected
     * Since replaces is added using Makefile, it is removed from here
    
    * *.go
     * Converts uninstall command to a function which is then guaranteed to
       execute via a deferral
---
 .github/actions/kamel-build-bundle/action.yaml | 13 ++++++------
 .github/workflows/upgrade.yml                  | 17 +++++++++++----
 e2e/support/test_support.go                    |  8 +++++++
 e2e/upgrade/cli_upgrade_test.go                |  6 ++----
 e2e/upgrade/olm_upgrade_test.go                |  6 ++++--
 script/Makefile                                | 29 ++++++++++++++++++++++++--
 6 files changed, 61 insertions(+), 18 deletions(-)

diff --git a/.github/actions/kamel-build-bundle/action.yaml 
b/.github/actions/kamel-build-bundle/action.yaml
index 19a3c95..22b5e69 100644
--- a/.github/actions/kamel-build-bundle/action.yaml
+++ b/.github/actions/kamel-build-bundle/action.yaml
@@ -47,18 +47,19 @@ runs:
         # replace image
         $(cd config/manifests && kustomize edit set image 
"docker.io/apache/camel-k=${{ inputs.local-image-name }}:${{ 
inputs.local-image-version }}")
 
-        # Patch CSV with the 'replaces' field to define the upgrade graph
-        # Use sed as the manifest/bases file is not included in the kustomize 
config
-        BASE_VERSION=$(echo ${{ inputs.local-image-version }} | grep -Po 
"\d.\d.\d")
-        sed -i "/  version: ${BASE_VERSION}/a \ \ replaces: 
camel-k-operator.v$(make get-last-released-version)" 
config/manifests/bases/camel-k.clusterserviceversion.yaml
-
         export CUSTOM_IMAGE=${{ inputs.local-image-name }}
         export LOCAL_IMAGE_BUNDLE=${{ inputs.image-registry 
}}/apache/camel-k-bundle:${{ inputs.local-image-version }}
+
         export PREV_XY_CHANNEL=stable-$(make get-last-released-version | grep 
-Po "\d.\d")
         echo "PREV_XY_CHANNEL=${PREV_XY_CHANNEL}" >> $GITHUB_ENV
         export NEW_XY_CHANNEL=stable-$(make get-version | grep -Po "\d.\d")
         echo "NEW_XY_CHANNEL=${NEW_XY_CHANNEL}" >> $GITHUB_ENV
-        make bundle-build BUNDLE_IMAGE_NAME=${LOCAL_IMAGE_BUNDLE} 
DEFAULT_CHANNEL="${NEW_XY_CHANNEL}" CHANNELS="${NEW_XY_CHANNEL}"
+
+        make bundle-build \
+          BUNDLE_IMAGE_NAME=${LOCAL_IMAGE_BUNDLE} \
+          DEFAULT_CHANNEL="${NEW_XY_CHANNEL}" \
+          CHANNELS="${NEW_XY_CHANNEL}"
+
         docker push ${LOCAL_IMAGE_BUNDLE}
 
         echo "::set-output name=local-image-bundle::$(echo 
${LOCAL_IMAGE_BUNDLE})"
diff --git a/.github/workflows/upgrade.yml b/.github/workflows/upgrade.yml
index 8b5d1ce..26c972c 100644
--- a/.github/workflows/upgrade.yml
+++ b/.github/workflows/upgrade.yml
@@ -75,10 +75,19 @@ jobs:
       shell: bash
       run: |
         export KAMEL_VERSION=$(make get-last-released-version)
-        curl -L 
https://github.com/apache/camel-k/releases/download/v${KAMEL_VERSION}/camel-k-client-${KAMEL_VERSION}-linux-64bit.tar.gz
 -o kamel.tar.gz
-        tar -zxf kamel.tar.gz
-        sudo mv kamel /usr/local/bin/
-        echo "Kamel version installed: $(kamel version)"
+        curl -L 
https://github.com/apache/camel-k/releases/download/v${KAMEL_VERSION}/camel-k-client-${KAMEL_VERSION}-linux-64bit.tar.gz
 -o /tmp/kamel.tar.gz
+        pushd /tmp && tar -zxf kamel.tar.gz && popd > /dev/null
+        if [ ! -x /tmp/kamel ]; then
+          echo "ERROR: No ${KAMEL_VERSION} downloaded correctly"
+          exit 1
+        fi
+        sudo mv /tmp/kamel /usr/local/bin/
+        if [ $? == 0 ]; then
+          echo "Kamel version installed: $(kamel version)"
+        else
+          echo "ERROR: Failed to install kamel binary ${KAMEL_VERSION}"
+          exit 1
+        fi
 
     - id: build-kamel-binary
       name: Build Kamel Binary
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 436f5b4..9bcf41e 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -1824,6 +1824,14 @@ func NewTestNamespace(injectKnativeBroker bool) 
ctrl.Object {
        return obj
 }
 
+func UninstallKamel(t *testing.T, args ...string) {
+       uargs := []string{"uninstall"}
+       uargs = append(uargs, args...)
+       if err := Kamel(uargs...).Execute(); err != nil {
+               t.Logf("Warning: An error occurred whilst trying to uninstall 
kamel: %s", err.Error())
+       }
+}
+
 func GetOutputString(command *cobra.Command) string {
        var buf bytes.Buffer
 
diff --git a/e2e/upgrade/cli_upgrade_test.go b/e2e/upgrade/cli_upgrade_test.go
index 65415bb..f8e5a91 100644
--- a/e2e/upgrade/cli_upgrade_test.go
+++ b/e2e/upgrade/cli_upgrade_test.go
@@ -38,6 +38,8 @@ import (
 
 func TestOperatorUpgrade(t *testing.T) {
        WithNewTestNamespace(t, func(ns string) {
+               defer UninstallKamel(t, "--all", "--olm=false")
+
                version, ok := os.LookupEnv("KAMEL_K_TEST_RELEASE_VERSION")
                Expect(ok).To(BeTrue())
 
@@ -112,9 +114,5 @@ func TestOperatorUpgrade(t *testing.T) {
                // Check the Integration runs correctly
                Eventually(IntegrationPodPhase(ns, name), 
TestTimeoutMedium).Should(Equal(corev1.PodRunning))
                Eventually(IntegrationConditionStatus(ns, name, 
v1.IntegrationConditionReady), 
TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
-
-               // Clean up
-               Expect(Kamel("delete", "--all", "-n", 
ns).Execute()).To(Succeed())
-               Expect(Kamel("uninstall", "--all", 
"--olm=false").Execute()).To(Succeed())
        })
 }
diff --git a/e2e/upgrade/olm_upgrade_test.go b/e2e/upgrade/olm_upgrade_test.go
index 8eea3f0..981aae3 100644
--- a/e2e/upgrade/olm_upgrade_test.go
+++ b/e2e/upgrade/olm_upgrade_test.go
@@ -46,6 +46,9 @@ import (
 const catalogSourceName = "test-camel-k-source"
 
 func TestOLMAutomaticUpgrade(t *testing.T) {
+       // Clean up cluster-wide resources that are not removed by OLM
+       defer UninstallKamel(t, "--all", "--olm=false")
+
        prevIIB := os.Getenv("CAMEL_K_PREV_IIB")
        newIIB := os.Getenv("CAMEL_K_NEW_IIB")
        kamel := os.Getenv("RELEASED_KAMEL_BIN")
@@ -98,6 +101,7 @@ func TestOLMAutomaticUpgrade(t *testing.T) {
 
                prevCSVVersion = clusterServiceVersion(noAdditionalConditions, 
ns)().Spec.Version
                prevIPVersionPrefix = fmt.Sprintf("%d.%d", 
prevCSVVersion.Version.Major, prevCSVVersion.Version.Minor)
+               t.Logf("Upgrading from Previous CSV Version: %s", 
prevCSVVersion.Version.String())
 
                // Check the operator pod is running
                Eventually(OperatorPodPhase(ns), 
TestTimeoutMedium).Should(Equal(corev1.PodRunning))
@@ -192,8 +196,6 @@ func TestOLMAutomaticUpgrade(t *testing.T) {
                        // Clean up
                        Expect(Kamel("delete", "--all", "-n", 
ns).Execute()).To(Succeed())
                        Expect(Kamel("uninstall", "-n", 
ns).Execute()).To(Succeed())
-                       // Clean up cluster-wide resources that are not removed 
by OLM
-                       Expect(Kamel("uninstall", "--all", 
"--olm=false").Execute()).To(Succeed())
                })
        })
 }
diff --git a/script/Makefile b/script/Makefile
index 631e10b..672f5b1 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -16,6 +16,7 @@
 VERSIONFILE := pkg/util/defaults/defaults.go
 VERSION ?= 1.9.0-SNAPSHOT
 OPERATOR_VERSION := $(subst -SNAPSHOT,,$(VERSION))
+LAST_RELEASED_IMAGE_NAME := camel-k-operator
 LAST_RELEASED_VERSION := 1.8.0
 RUNTIME_VERSION := 1.11.0
 BUILDAH_VERSION := 1.14.0
@@ -50,6 +51,12 @@ LINT_DEADLINE := 10m
 CHANNELS ?= $(OPERATOR_VERSION)
 DEFAULT_CHANNEL ?= $(OPERATOR_VERSION)
 PACKAGE := camel-k
+CSV_VERSION := $(CUSTOM_VERSION:-SNAPSHOT=)
+CSV_DISPLAY_NAME := Camel K Operator
+CSV_SUPPORT := Camel
+CSV_REPLACES := $(LAST_RELEASED_IMAGE_NAME).v$(LAST_RELEASED_VERSION)
+CSV_FILENAME := $(PACKAGE).clusterserviceversion.yaml
+CSV_PATH := config/manifests/bases/$(CSV_FILENAME)
 
 # Used to push pre-release artifacts
 STAGING_IMAGE_NAME := docker.io/camelk/camel-k
@@ -325,6 +332,9 @@ get-image:
 get-version:
        @echo $(CUSTOM_VERSION)
 
+get-last-released-img-name:
+       @echo $(LAST_RELEASED_IMAGE_NAME)
+
 get-last-released-version:
        @echo $(LAST_RELEASED_VERSION)
 
@@ -338,7 +348,7 @@ git-tag:
        ./script/git_tag.sh $(CUSTOM_VERSION) $(RELEASE_GIT_REMOTE)
 
 cross-compile:
-       # we must wrap the goldflags parameters with quotes as they will need 
to 
+       # we must wrap the goldflags parameters with quotes as they will need to
        # be processed as a single argument by the cross compile script
        ./script/cross_compile.sh $(CUSTOM_VERSION) $(subst ","\",$(GOFLAGS))
 
@@ -464,7 +474,22 @@ BUNDLE_PACKAGE := --package=$(PACKAGE)
 endif
 BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) 
$(BUNDLE_PACKAGE)
 
-bundle: set-version generate-crd $(BUNDLE_CAMEL_APIS) kustomize operator-sdk
+#
+# Tailor the manifest according to default values for this project
+# Note. to successfully make the bundle the name must match that specified in 
the PROJECT file
+#
+pre-bundle:
+# bundle name must match that which appears in PROJECT file
+       @sed -i 's/projectName: .*/projectName: $(PACKAGE)/' PROJECT
+       @sed -i 's~^    containerImage: .*~    containerImage: 
$(CUSTOM_IMAGE):$(CUSTOM_VERSION)~' $(CSV_PATH)
+       @sed -i 's/^    support: .*/    support: $(CSV_SUPPORT)/' $(CSV_PATH)
+       @sed -i 's/^  name: .*.\(v.*\)/  name: $(PACKAGE).v$(CSV_VERSION)/' 
$(CSV_PATH)
+       @sed -i 's/^  displayName: .*/  displayName: $(CSV_DISPLAY_NAME)/' 
$(CSV_PATH)
+       @sed -i 's/^  replaces: .*/  replaces: $(CSV_REPLACES)/' $(CSV_PATH)
+       @sed -i 's/^  version: .*/  version: $(CSV_VERSION)/' $(CSV_PATH)
+       @sed -i '/  version: ${CSV_VERSION}/a \ \ replaces: $(CSV_REPLACES)' 
$(CSV_PATH)
+
+bundle: set-version generate-crd $(BUNDLE_CAMEL_APIS) kustomize operator-sdk 
pre-bundle
        @# Sets the operator image to the preferred image:tag
        @cd config/manifests && $(KUSTOMIZE) edit set image 
$(IMAGE_NAME)=$(CUSTOM_IMAGE):$(CUSTOM_VERSION)
        @# Build kustomize manifests

Reply via email to