You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2022/10/03 09:02:18 UTC

[camel-k] branch release-1.10.x updated (2687a931e -> bbcc87ba1)

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

pcongiusti pushed a change to branch release-1.10.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git


    from 2687a931e Fix finding of validate job
     new 097b22992 feat(cli): promote allow Integration update
     new cf1d62bd6 chore: replace properly the resources
     new 926e5788f chore(cli): add a promote message
     new bbcc87ba1 chore(e2e): added observed generation check

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../install/cli/files/promote-route-edited.groovy} |  3 +-
 e2e/namespace/install/cli/promote_test.go          | 36 ++++++++++++++++++++++
 e2e/support/test_support.go                        | 18 ++++++++++-
 pkg/cmd/bind.go                                    |  9 ++----
 pkg/cmd/promote.go                                 | 20 ++++++++++--
 pkg/controller/kameletbinding/initialize.go        |  2 +-
 pkg/install/cluster.go                             |  3 +-
 pkg/install/common.go                              |  2 +-
 pkg/trait/pull_secret.go                           |  2 +-
 pkg/util/kubernetes/replace.go                     | 12 +++++---
 10 files changed, 86 insertions(+), 21 deletions(-)
 copy e2e/{global/common/config/files/config-configmap-route.groovy => namespace/install/cli/files/promote-route-edited.groovy} (93%)


[camel-k] 02/04: chore: replace properly the resources

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit cf1d62bd6d004ff5178bcf889e4cb397b17ffd32
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Sep 29 17:15:55 2022 +0200

    chore: replace properly the resources
---
 .../install/cli/files/promote-route-edited.groovy  | 22 ++++++++++++++++++++++
 e2e/namespace/install/cli/promote_test.go          | 19 ++++++++++++++++---
 pkg/cmd/promote.go                                 | 20 ++++----------------
 3 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/e2e/namespace/install/cli/files/promote-route-edited.groovy b/e2e/namespace/install/cli/files/promote-route-edited.groovy
new file mode 100644
index 000000000..ab680d7bb
--- /dev/null
+++ b/e2e/namespace/install/cli/files/promote-route-edited.groovy
@@ -0,0 +1,22 @@
+// camel-k: language=groovy
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+from('timer:configmap')
+    .setBody()
+        .simple("resource:classpath:my-configmap-key")
+    .log('configmap: ${body}')
\ No newline at end of file
diff --git a/e2e/namespace/install/cli/promote_test.go b/e2e/namespace/install/cli/promote_test.go
index bc95fc010..ac941ace7 100644
--- a/e2e/namespace/install/cli/promote_test.go
+++ b/e2e/namespace/install/cli/promote_test.go
@@ -108,16 +108,21 @@ func TestKamelCLIPromote(t *testing.T) {
 			})
 
 			t.Run("plain integration promotion update", func(t *testing.T) {
-				// Update the configmap
+				// We need to update the Integration CR in order the operator to restart it both in dev and prod envs
+				Expect(KamelRunWithID(operatorDevID, nsDev, "./files/promote-route-edited.groovy", "--name", "promote-route",
+					"--config", "configmap:my-cm").Execute()).To(Succeed())
+				Eventually(IntegrationPodPhase(nsDev, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+				Eventually(IntegrationConditionStatus(nsDev, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+				Eventually(IntegrationLogs(nsDev, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am development configmap!"))
+				// Update the configmap only in prod
 				var cmData = make(map[string]string)
 				cmData["my-configmap-key"] = "I am production, but I was updated!"
 				UpdatePlainTextConfigmap(nsProd, "my-cm", cmData)
-
+				// Promote the edited Integration
 				Expect(Kamel("promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).To(Succeed())
 				Eventually(IntegrationPodPhase(nsProd, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
 				Eventually(IntegrationConditionStatus(nsProd, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
 				Eventually(IntegrationLogs(nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am production, but I was updated!"))
-				Eventually(IntegrationLogs(nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("very top secret production"))
 				// They must use the same image
 				Expect(IntegrationPodImage(nsProd, "promote-route")()).Should(Equal(IntegrationPodImage(nsDev, "promote-route")()))
 			})
@@ -146,6 +151,14 @@ func TestKamelCLIPromote(t *testing.T) {
 				Eventually(IntegrationLogs(nsProd, "kb-timer-source-to-log"), TestTimeoutShort).Should(ContainSubstring("my-kamelet-binding-rocks"))
 				// They must use the same image
 				Expect(IntegrationPodImage(nsProd, "kb-timer-source-to-log")()).Should(Equal(IntegrationPodImage(nsDev, "kb-timer-source-to-log")()))
+
+				// Kamelet Binding update
+				Expect(KamelBindWithID(operatorDevID, nsDev, "kb-timer-source", "log:info", "-p", "source.message=my-kamelet-binding-rocks-again").Execute()).To(Succeed())
+				Eventually(IntegrationPodPhase(nsDev, "kb-timer-source-to-log"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+				Eventually(IntegrationLogs(nsDev, "kb-timer-source-to-log"), TestTimeoutShort).Should(ContainSubstring("my-kamelet-binding-rocks-again"))
+				Expect(Kamel("promote", "-n", nsDev, "kb-timer-source-to-log", "--to", nsProd).Execute()).To(Succeed())
+				Eventually(IntegrationPodPhase(nsProd, "kb-timer-source-to-log"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+				Eventually(IntegrationLogs(nsProd, "kb-timer-source-to-log"), TestTimeoutShort).Should(ContainSubstring("my-kamelet-binding-rocks-again"))
 			})
 		})
 	})
diff --git a/pkg/cmd/promote.go b/pkg/cmd/promote.go
index 5d2e53723..17839810f 100644
--- a/pkg/cmd/promote.go
+++ b/pkg/cmd/promote.go
@@ -127,7 +127,7 @@ func (o *promoteCmdOptions) run(cmd *cobra.Command, args []string) error {
 		// KameletBinding promotion
 		destKameletBinding := o.editKameletBinding(sourceKameletBinding, sourceIntegration)
 
-		return o.saveKameletBinding(destKameletBinding)
+		return o.replaceResource(destKameletBinding)
 	}
 	// Plain Integration promotion
 	destIntegration := o.editIntegration(sourceIntegration)
@@ -138,7 +138,7 @@ func (o *promoteCmdOptions) run(cmd *cobra.Command, args []string) error {
 		return err
 	}
 
-	return o.saveIntegration(destIntegration)
+	return o.replaceResource(destIntegration)
 }
 
 func checkOpsCompatibility(cmd *cobra.Command, source, dest map[string]string) error {
@@ -423,14 +423,6 @@ func (o *promoteCmdOptions) editIntegration(it *v1.Integration) *v1.Integration
 	return &dst
 }
 
-func (o *promoteCmdOptions) saveIntegration(it *v1.Integration) error {
-	err := o._client.Create(o.Context, it)
-	if err != nil && !k8serrors.IsAlreadyExists(err) {
-		return o._client.Update(o.Context, it)
-	}
-	return err
-}
-
 func (o *promoteCmdOptions) editKameletBinding(kb *v1alpha1.KameletBinding, it *v1.Integration) *v1alpha1.KameletBinding {
 	dst := v1alpha1.NewKameletBinding(o.To, kb.Name)
 	dst.Spec = *kb.Spec.DeepCopy()
@@ -458,12 +450,8 @@ func (o *promoteCmdOptions) editKameletBinding(kb *v1alpha1.KameletBinding, it *
 	return &dst
 }
 
-func (o *promoteCmdOptions) saveKameletBinding(kb *v1alpha1.KameletBinding) error {
-	err := o._client.Create(o.Context, kb)
-	if err != nil && !k8serrors.IsAlreadyExists(err) {
-		return o._client.Update(o.Context, kb)
-	}
-	return err
+func (o *promoteCmdOptions) replaceResource(res k8sclient.Object) error {
+	return kubernetes.ReplaceResource(o.Context, o._client, res)
 }
 
 //


[camel-k] 01/04: feat(cli): promote allow Integration update

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 097b2299230d7dc7d80a569210468b980c36d87c
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Sep 26 16:34:24 2022 +0200

    feat(cli): promote allow Integration update
    
    Closes #3673
---
 e2e/namespace/install/cli/promote_test.go | 15 +++++++++++++++
 e2e/support/test_support.go               | 15 +++++++++++++++
 pkg/cmd/promote.go                        | 20 ++++++++++++++++++--
 3 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/e2e/namespace/install/cli/promote_test.go b/e2e/namespace/install/cli/promote_test.go
index 76ad5b62a..bc95fc010 100644
--- a/e2e/namespace/install/cli/promote_test.go
+++ b/e2e/namespace/install/cli/promote_test.go
@@ -107,6 +107,21 @@ func TestKamelCLIPromote(t *testing.T) {
 				Expect(IntegrationPodImage(nsProd, "promote-route")()).Should(Equal(IntegrationPodImage(nsDev, "promote-route")()))
 			})
 
+			t.Run("plain integration promotion update", func(t *testing.T) {
+				// Update the configmap
+				var cmData = make(map[string]string)
+				cmData["my-configmap-key"] = "I am production, but I was updated!"
+				UpdatePlainTextConfigmap(nsProd, "my-cm", cmData)
+
+				Expect(Kamel("promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).To(Succeed())
+				Eventually(IntegrationPodPhase(nsProd, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+				Eventually(IntegrationConditionStatus(nsProd, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+				Eventually(IntegrationLogs(nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am production, but I was updated!"))
+				Eventually(IntegrationLogs(nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("very top secret production"))
+				// They must use the same image
+				Expect(IntegrationPodImage(nsProd, "promote-route")()).Should(Equal(IntegrationPodImage(nsDev, "promote-route")()))
+			})
+
 			t.Run("no kamelet in destination", func(t *testing.T) {
 				Expect(Kamel("promote", "-n", nsDev, "timer-kamelet-usage", "--to", nsProd).Execute()).NotTo(Succeed())
 			})
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 28eec818f..c6074a096 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -1190,6 +1190,21 @@ func CreatePlainTextConfigmap(ns string, name string, data map[string]string) er
 	return TestClient().Create(TestContext, &cm)
 }
 
+func UpdatePlainTextConfigmap(ns string, name string, data map[string]string) error {
+	cm := corev1.ConfigMap{
+		TypeMeta: metav1.TypeMeta{
+			Kind:       "ConfigMap",
+			APIVersion: corev1.SchemeGroupVersion.String(),
+		},
+		ObjectMeta: metav1.ObjectMeta{
+			Namespace: ns,
+			Name:      name,
+		},
+		Data: data,
+	}
+	return TestClient().Update(TestContext, &cm)
+}
+
 func CreateBinaryConfigmap(ns string, name string, data map[string][]byte) error {
 	cm := corev1.ConfigMap{
 		TypeMeta: metav1.TypeMeta{
diff --git a/pkg/cmd/promote.go b/pkg/cmd/promote.go
index bf81e3e81..5d2e53723 100644
--- a/pkg/cmd/promote.go
+++ b/pkg/cmd/promote.go
@@ -127,7 +127,7 @@ func (o *promoteCmdOptions) run(cmd *cobra.Command, args []string) error {
 		// KameletBinding promotion
 		destKameletBinding := o.editKameletBinding(sourceKameletBinding, sourceIntegration)
 
-		return c.Create(o.Context, destKameletBinding)
+		return o.saveKameletBinding(destKameletBinding)
 	}
 	// Plain Integration promotion
 	destIntegration := o.editIntegration(sourceIntegration)
@@ -138,7 +138,7 @@ func (o *promoteCmdOptions) run(cmd *cobra.Command, args []string) error {
 		return err
 	}
 
-	return c.Create(o.Context, destIntegration)
+	return o.saveIntegration(destIntegration)
 }
 
 func checkOpsCompatibility(cmd *cobra.Command, source, dest map[string]string) error {
@@ -423,6 +423,14 @@ func (o *promoteCmdOptions) editIntegration(it *v1.Integration) *v1.Integration
 	return &dst
 }
 
+func (o *promoteCmdOptions) saveIntegration(it *v1.Integration) error {
+	err := o._client.Create(o.Context, it)
+	if err != nil && !k8serrors.IsAlreadyExists(err) {
+		return o._client.Update(o.Context, it)
+	}
+	return err
+}
+
 func (o *promoteCmdOptions) editKameletBinding(kb *v1alpha1.KameletBinding, it *v1.Integration) *v1alpha1.KameletBinding {
 	dst := v1alpha1.NewKameletBinding(o.To, kb.Name)
 	dst.Spec = *kb.Spec.DeepCopy()
@@ -450,6 +458,14 @@ func (o *promoteCmdOptions) editKameletBinding(kb *v1alpha1.KameletBinding, it *
 	return &dst
 }
 
+func (o *promoteCmdOptions) saveKameletBinding(kb *v1alpha1.KameletBinding) error {
+	err := o._client.Create(o.Context, kb)
+	if err != nil && !k8serrors.IsAlreadyExists(err) {
+		return o._client.Update(o.Context, kb)
+	}
+	return err
+}
+
 //
 // RoleBinding is required to allow access to images in one namespace
 // by another namespace. Without this on rbac-enabled clusters, the


[camel-k] 03/04: chore(cli): add a promote message

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 926e5788fcaa1e03467a5457daff3f93b1efd5ea
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Sep 30 10:05:31 2022 +0200

    chore(cli): add a promote message
    
    Closes #3676
---
 e2e/support/test_support.go                 |  3 ++-
 pkg/cmd/bind.go                             |  9 ++-------
 pkg/cmd/promote.go                          | 18 +++++++++++++++---
 pkg/controller/kameletbinding/initialize.go |  2 +-
 pkg/install/cluster.go                      |  3 ++-
 pkg/install/common.go                       |  2 +-
 pkg/trait/pull_secret.go                    |  2 +-
 pkg/util/kubernetes/replace.go              | 12 +++++++-----
 8 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index c6074a096..7860c8bc6 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -1864,7 +1864,8 @@ func BindKameletToWithErrorHandler(ns string, name string, annotations map[strin
 		if errorHandler != nil {
 			kb.Spec.ErrorHandler = asErrorHandlerSpec(errorHandler)
 		}
-		return kubernetes.ReplaceResource(TestContext, TestClient(), &kb)
+		_, err := kubernetes.ReplaceResource(TestContext, TestClient(), &kb)
+		return err
 	}
 }
 
diff --git a/pkg/cmd/bind.go b/pkg/cmd/bind.go
index d92128cb6..d956bf271 100644
--- a/pkg/cmd/bind.go
+++ b/pkg/cmd/bind.go
@@ -260,17 +260,12 @@ func (o *bindCmdOptions) run(cmd *cobra.Command, args []string) error {
 		return showOutput(cmd, &binding, o.OutputFormat, client.GetScheme())
 	}
 
-	existed := false
-	err = client.Create(o.Context, &binding)
-	if err != nil && k8serrors.IsAlreadyExists(err) {
-		existed = true
-		err = kubernetes.ReplaceResource(o.Context, client, &binding)
-	}
+	replaced, err := kubernetes.ReplaceResource(o.Context, client, &binding)
 	if err != nil {
 		return err
 	}
 
-	if !existed {
+	if !replaced {
 		fmt.Fprintln(cmd.OutOrStdout(), `kamelet binding "`+name+`" created`)
 	} else {
 		fmt.Fprintln(cmd.OutOrStdout(), `kamelet binding "`+name+`" updated`)
diff --git a/pkg/cmd/promote.go b/pkg/cmd/promote.go
index 17839810f..3ebd67bbc 100644
--- a/pkg/cmd/promote.go
+++ b/pkg/cmd/promote.go
@@ -127,7 +127,13 @@ func (o *promoteCmdOptions) run(cmd *cobra.Command, args []string) error {
 		// KameletBinding promotion
 		destKameletBinding := o.editKameletBinding(sourceKameletBinding, sourceIntegration)
 
-		return o.replaceResource(destKameletBinding)
+		replaced, err := o.replaceResource(destKameletBinding)
+		if !replaced {
+			fmt.Fprintln(cmd.OutOrStdout(), `Promoted Integration "`+name+`" created`)
+		} else {
+			fmt.Fprintln(cmd.OutOrStdout(), `Promoted Integration "`+name+`" updated`)
+		}
+		return err
 	}
 	// Plain Integration promotion
 	destIntegration := o.editIntegration(sourceIntegration)
@@ -138,7 +144,13 @@ func (o *promoteCmdOptions) run(cmd *cobra.Command, args []string) error {
 		return err
 	}
 
-	return o.replaceResource(destIntegration)
+	replaced, err := o.replaceResource(destIntegration)
+	if !replaced {
+		fmt.Fprintln(cmd.OutOrStdout(), `Promoted Integration "`+name+`" created`)
+	} else {
+		fmt.Fprintln(cmd.OutOrStdout(), `Promoted Integration "`+name+`" updated`)
+	}
+	return err
 }
 
 func checkOpsCompatibility(cmd *cobra.Command, source, dest map[string]string) error {
@@ -450,7 +462,7 @@ func (o *promoteCmdOptions) editKameletBinding(kb *v1alpha1.KameletBinding, it *
 	return &dst
 }
 
-func (o *promoteCmdOptions) replaceResource(res k8sclient.Object) error {
+func (o *promoteCmdOptions) replaceResource(res k8sclient.Object) (bool, error) {
 	return kubernetes.ReplaceResource(o.Context, o._client, res)
 }
 
diff --git a/pkg/controller/kameletbinding/initialize.go b/pkg/controller/kameletbinding/initialize.go
index 3f85198b5..0ff43d881 100644
--- a/pkg/controller/kameletbinding/initialize.go
+++ b/pkg/controller/kameletbinding/initialize.go
@@ -55,7 +55,7 @@ func (action *initializeAction) Handle(ctx context.Context, kameletbinding *v1al
 		return nil, err
 	}
 
-	if err := kubernetes.ReplaceResource(ctx, action.client, it); err != nil {
+	if _, err := kubernetes.ReplaceResource(ctx, action.client, it); err != nil {
 		return nil, errors.Wrap(err, "could not create integration for kamelet binding")
 	}
 
diff --git a/pkg/install/cluster.go b/pkg/install/cluster.go
index b135b2d64..149e7df27 100644
--- a/pkg/install/cluster.go
+++ b/pkg/install/cluster.go
@@ -322,7 +322,8 @@ func installCRD(ctx context.Context, c client.Client, kind string, version strin
 		return nil
 	}
 
-	return kubernetes.ReplaceResource(ctx, c, crd)
+	_, err = kubernetes.ReplaceResource(ctx, c, crd)
+	return err
 }
 
 func isClusterRoleInstalled(ctx context.Context, c client.Client, name string) (bool, error) {
diff --git a/pkg/install/common.go b/pkg/install/common.go
index a8606ed68..da4bc3e00 100644
--- a/pkg/install/common.go
+++ b/pkg/install/common.go
@@ -113,7 +113,7 @@ func ObjectOrCollect(ctx context.Context, c client.Client, namespace string, col
 	}
 
 	if force {
-		if err := kubernetes.ReplaceResource(ctx, c, obj); err != nil {
+		if _, err := kubernetes.ReplaceResource(ctx, c, obj); err != nil {
 			return err
 		}
 		// For some resources, also reset the status
diff --git a/pkg/trait/pull_secret.go b/pkg/trait/pull_secret.go
index 55ff73e9d..a53db960a 100644
--- a/pkg/trait/pull_secret.go
+++ b/pkg/trait/pull_secret.go
@@ -109,7 +109,7 @@ func (t *pullSecretTrait) delegateImagePuller(e *Environment) error {
 	// Applying the RoleBinding directly because it's a resource in the operator namespace
 	// (different from the integration namespace when delegation is enabled).
 	rb := t.newImagePullerRoleBinding(e)
-	if err := kubernetes.ReplaceResource(e.Ctx, e.Client, rb); err != nil {
+	if _, err := kubernetes.ReplaceResource(e.Ctx, e.Client, rb); err != nil {
 		return errors.Wrap(err, "error during the creation of the system:image-puller delegating role binding")
 	}
 	return nil
diff --git a/pkg/util/kubernetes/replace.go b/pkg/util/kubernetes/replace.go
index 9e047b3f9..b71b5a6ac 100644
--- a/pkg/util/kubernetes/replace.go
+++ b/pkg/util/kubernetes/replace.go
@@ -38,16 +38,18 @@ import (
 )
 
 // ReplaceResource allows to completely replace a resource on Kubernetes, taking care of immutable fields and resource versions.
-func ReplaceResource(ctx context.Context, c client.Client, res ctrl.Object) error {
+func ReplaceResource(ctx context.Context, c client.Client, res ctrl.Object) (bool, error) {
+	replaced := false
 	err := c.Create(ctx, res)
 	if err != nil && k8serrors.IsAlreadyExists(err) {
+		replaced = true
 		existing, ok := res.DeepCopyObject().(ctrl.Object)
 		if !ok {
-			return fmt.Errorf("type assertion failed: %v", res.DeepCopyObject())
+			return replaced, fmt.Errorf("type assertion failed: %v", res.DeepCopyObject())
 		}
 		err = c.Get(ctx, ctrl.ObjectKeyFromObject(existing), existing)
 		if err != nil {
-			return err
+			return replaced, err
 		}
 		mapRequiredMeta(existing, res)
 		mapRequiredServiceData(existing, res)
@@ -56,9 +58,9 @@ func ReplaceResource(ctx context.Context, c client.Client, res ctrl.Object) erro
 		err = c.Update(ctx, res)
 	}
 	if err != nil {
-		return errors.Wrap(err, "could not create or replace "+findResourceDetails(res))
+		return replaced, errors.Wrap(err, "could not create or replace "+findResourceDetails(res))
 	}
-	return nil
+	return replaced, nil
 }
 
 func mapRequiredMeta(from ctrl.Object, to ctrl.Object) {


[camel-k] 04/04: chore(e2e): added observed generation check

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit bbcc87ba18d73ffc71b0328305ec6076b7da0b9e
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Sep 30 15:03:04 2022 +0200

    chore(e2e): added observed generation check
---
 e2e/namespace/install/cli/promote_test.go | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/e2e/namespace/install/cli/promote_test.go b/e2e/namespace/install/cli/promote_test.go
index ac941ace7..0c95528f9 100644
--- a/e2e/namespace/install/cli/promote_test.go
+++ b/e2e/namespace/install/cli/promote_test.go
@@ -34,6 +34,8 @@ import (
 )
 
 func TestKamelCLIPromote(t *testing.T) {
+	one := int64(1)
+	two := int64(2)
 	// Dev environment namespace
 	WithNewTestNamespace(t, func(nsDev string) {
 		operatorDevID := "camel-k-cli-promote-dev"
@@ -53,6 +55,7 @@ func TestKamelCLIPromote(t *testing.T) {
 				"--config", "configmap:my-cm",
 				"--config", "secret:my-sec",
 			).Execute()).To(Succeed())
+			Eventually(IntegrationObservedGeneration(nsDev, "promote-route")).Should(Equal(&one))
 			Eventually(IntegrationPodPhase(nsDev, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
 			Eventually(IntegrationConditionStatus(nsDev, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
 			Eventually(IntegrationLogs(nsDev, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am development configmap!"))
@@ -99,6 +102,7 @@ func TestKamelCLIPromote(t *testing.T) {
 
 			t.Run("plain integration promotion", func(t *testing.T) {
 				Expect(Kamel("promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).To(Succeed())
+				Eventually(IntegrationObservedGeneration(nsProd, "promote-route")).Should(Equal(&one))
 				Eventually(IntegrationPodPhase(nsProd, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
 				Eventually(IntegrationConditionStatus(nsProd, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
 				Eventually(IntegrationLogs(nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am production!"))
@@ -111,6 +115,8 @@ func TestKamelCLIPromote(t *testing.T) {
 				// We need to update the Integration CR in order the operator to restart it both in dev and prod envs
 				Expect(KamelRunWithID(operatorDevID, nsDev, "./files/promote-route-edited.groovy", "--name", "promote-route",
 					"--config", "configmap:my-cm").Execute()).To(Succeed())
+				// The generation has to be incremented
+				Eventually(IntegrationObservedGeneration(nsDev, "promote-route")).Should(Equal(&two))
 				Eventually(IntegrationPodPhase(nsDev, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
 				Eventually(IntegrationConditionStatus(nsDev, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
 				Eventually(IntegrationLogs(nsDev, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am development configmap!"))
@@ -120,6 +126,8 @@ func TestKamelCLIPromote(t *testing.T) {
 				UpdatePlainTextConfigmap(nsProd, "my-cm", cmData)
 				// Promote the edited Integration
 				Expect(Kamel("promote", "-n", nsDev, "promote-route", "--to", nsProd).Execute()).To(Succeed())
+				// The generation has to be incremented also in prod
+				Eventually(IntegrationObservedGeneration(nsDev, "promote-route")).Should(Equal(&two))
 				Eventually(IntegrationPodPhase(nsProd, "promote-route"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
 				Eventually(IntegrationConditionStatus(nsProd, "promote-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
 				Eventually(IntegrationLogs(nsProd, "promote-route"), TestTimeoutShort).Should(ContainSubstring("I am production, but I was updated!"))