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:19 UTC

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

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