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 2023/08/22 12:15:13 UTC
[camel-k] 04/06: feat(test): hot reload cm/secrets
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 4960c7efd19f1433fb00e17142062bcdc0061915
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Aug 21 13:07:27 2023 +0200
feat(test): hot reload cm/secrets
---
e2e/common/config/config_reload_test.go | 72 +++++++++++++++++++++++++++++++++
e2e/support/test_support.go | 15 +++++++
2 files changed, 87 insertions(+)
diff --git a/e2e/common/config/config_reload_test.go b/e2e/common/config/config_reload_test.go
new file mode 100644
index 000000000..71106d1ce
--- /dev/null
+++ b/e2e/common/config/config_reload_test.go
@@ -0,0 +1,72 @@
+//go:build integration
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"
+
+/*
+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.
+*/
+
+package config
+
+import (
+ "testing"
+
+ . "github.com/onsi/gomega"
+
+ corev1 "k8s.io/api/core/v1"
+
+ . "github.com/apache/camel-k/v2/e2e/support"
+ v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+)
+
+func TestConfigmapHotReload(t *testing.T) {
+ RegisterTestingT(t)
+
+ var cmData = make(map[string]string)
+ cmData["my-configmap-key"] = "my configmap content"
+ CreatePlainTextConfigmap(ns, "my-hot-cm", cmData)
+
+ Expect(KamelRunWithID(operatorID, ns, "./files/config-configmap-route.groovy", "--config", "configmap:my-hot-cm").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "config-configmap-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
+ Eventually(IntegrationConditionStatus(ns, "config-configmap-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "config-configmap-route"), TestTimeoutShort).Should(ContainSubstring("my configmap content"))
+
+ cmData["my-configmap-key"] = "my configmap content updated"
+ UpdatePlainTextConfigmap(ns, "my-hot-cm", cmData)
+ Eventually(IntegrationLogs(ns, "config-configmap-route"), TestTimeoutShort).Should(ContainSubstring("my configmap content updated"))
+
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+}
+
+func TestSecretHotReload(t *testing.T) {
+ RegisterTestingT(t)
+
+ var secData = make(map[string]string)
+ secData["my-secret-key"] = "very top secret"
+ CreatePlainTextSecret(ns, "my-hot-sec", secData)
+
+ Expect(KamelRunWithID(operatorID, ns, "./files/config-secret-route.groovy", "--config", "secret:my-hot-sec").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "config-secret-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
+ Eventually(IntegrationConditionStatus(ns, "config-secret-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "config-secret-route"), TestTimeoutShort).Should(ContainSubstring("very top secret"))
+
+ secData["my-secret-key"] = "very top secret updated"
+ UpdatePlainTextSecret(ns, "my-hot-sec", secData)
+ Eventually(IntegrationLogs(ns, "config-secret-route"), TestTimeoutShort).Should(ContainSubstring("very top secret updated"))
+
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+}
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 19af82c72..3de4c50fe 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -1523,6 +1523,21 @@ func CreatePlainTextSecret(ns string, name string, data map[string]string) error
return CreatePlainTextSecretWithLabels(ns, name, data, map[string]string{})
}
+func UpdateCreatePlainTextSecret(ns string, name string, data map[string]string) error {
+ sec := corev1.Secret{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Secret",
+ APIVersion: corev1.SchemeGroupVersion.String(),
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Namespace: ns,
+ Name: name,
+ },
+ StringData: data,
+ }
+ return TestClient().Update(TestContext, &sec)
+}
+
func CreatePlainTextSecretWithLabels(ns string, name string, data map[string]string, labels map[string]string) error {
sec := corev1.Secret{
TypeMeta: metav1.TypeMeta{