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:20 UTC
[camel-k] 02/04: chore: replace properly the resources
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)
}
//