Skip to content

Commit

Permalink
chore(e2e): Regression test on referenced secret(/cm) properties
Browse files Browse the repository at this point in the history
  • Loading branch information
gansheer authored and squakez committed Nov 8, 2023
1 parent eb9eeb3 commit 729d982
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
46 changes: 46 additions & 0 deletions e2e/common/config/config_test.go
Expand Up @@ -41,20 +41,23 @@ func TestRunConfigExamples(t *testing.T) {
Eventually(IntegrationPodPhase(ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("test-property"))
Expect(Kamel("delete", "property-route", "-n", ns).Execute()).To(Succeed())
})

t.Run("Property file", func(t *testing.T) {
Expect(KamelRunWithID(operatorID, ns, "./files/property-file-route.groovy", "--property", "file:./files/my.properties").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "property-file-route"), TestTimeoutShort).Should(ContainSubstring("hello world"))
Expect(Kamel("delete", "property-file-route", "-n", ns).Execute()).To(Succeed())
})

t.Run("Property precedence", func(t *testing.T) {
Expect(KamelRunWithID(operatorID, ns, "./files/property-file-route.groovy", "-p", "my.key.2=universe", "-p", "file:./files/my.properties").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "property-file-route"), TestTimeoutShort).Should(ContainSubstring("hello universe"))
Expect(Kamel("delete", "property-file-route", "-n", ns).Execute()).To(Succeed())
})

t.Run("Property from ConfigMap", func(t *testing.T) {
Expand All @@ -66,6 +69,7 @@ func TestRunConfigExamples(t *testing.T) {
Eventually(IntegrationPodPhase(ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-configmap-property-value"))
Expect(Kamel("delete", "property-route", "-n", ns).Execute()).To(Succeed())
})

t.Run("Property from ConfigMap as property file", func(t *testing.T) {
Expand All @@ -77,6 +81,7 @@ func TestRunConfigExamples(t *testing.T) {
Eventually(IntegrationPodPhase(ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-configmap-property-entry"))
Expect(Kamel("delete", "property-route", "-n", ns).Execute()).To(Succeed())
})

t.Run("Property from Secret", func(t *testing.T) {
Expand All @@ -88,6 +93,7 @@ func TestRunConfigExamples(t *testing.T) {
Eventually(IntegrationPodPhase(ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-secret-property-value"))
Expect(Kamel("delete", "property-route", "-n", ns).Execute()).To(Succeed())
})

t.Run("Property from Secret as property file", func(t *testing.T) {
Expand All @@ -101,6 +107,23 @@ func TestRunConfigExamples(t *testing.T) {
Eventually(IntegrationLogs(ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-secret-property-entry"))
})

t.Run("Property from Secret inlined", func(t *testing.T) {
var secData = make(map[string]string)
secData["my-message"] = "my-secret-external-value"
CreatePlainTextSecret(ns, "my-sec-inlined", secData)

// TODO: remove jvm.options trait as soon as CAMEL-20054 gets fixed
Expect(KamelRunWithID(operatorID, ns, "./files/property-secret-route.groovy",
"-t", "mount.configs=secret:my-sec-inlined",
"-t", "jvm.options=-Dcamel.k.mount-path.secrets=/etc/camel/conf.d/_secrets",
).Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "property-secret-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "property-secret-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "property-secret-route"), TestTimeoutShort).Should(ContainSubstring("my-secret-external-value"))
Expect(Kamel("delete", "property-secret-route", "-n", ns).Execute()).To(Succeed())

})

// Configmap

// Store a configmap on the cluster
Expand Down Expand Up @@ -225,13 +248,15 @@ func TestRunConfigExamples(t *testing.T) {
Eventually(IntegrationPodPhase(ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-super-application"))
Expect(Kamel("delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed())
})

t.Run("Build time property file with precedence", func(t *testing.T) {
Expect(KamelRunWithID(operatorID, ns, "./files/build-property-file-route.groovy", "--build-property", "quarkus.application.name=my-overridden-application", "--build-property", "file:./files/quarkus.properties").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "build-property-file-route"), TestTimeoutMedium).Should(ContainSubstring("my-overridden-application"))
Expect(Kamel("delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed())
})

t.Run("Build time property from ConfigMap", func(t *testing.T) {
Expand All @@ -243,6 +268,7 @@ func TestRunConfigExamples(t *testing.T) {
Eventually(IntegrationPodPhase(ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "build-property-file-route"), TestTimeoutLong).Should(ContainSubstring("my-cool-application"))
Expect(Kamel("delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed())
})

t.Run("Build time property from ConfigMap as property file", func(t *testing.T) {
Expand All @@ -254,6 +280,8 @@ func TestRunConfigExamples(t *testing.T) {
Eventually(IntegrationPodPhase(ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-super-cool-application"))
Expect(Kamel("delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed())

})

t.Run("Build time property from Secret", func(t *testing.T) {
Expand All @@ -265,6 +293,8 @@ func TestRunConfigExamples(t *testing.T) {
Eventually(IntegrationPodPhase(ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-great-application"))
Expect(Kamel("delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed())

})

t.Run("Build time property from Secret as property file", func(t *testing.T) {
Expand All @@ -276,7 +306,23 @@ func TestRunConfigExamples(t *testing.T) {
Eventually(IntegrationPodPhase(ns, "build-property-file-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "build-property-file-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-awsome-application"))
Expect(Kamel("delete", "build-property-file-route", "-n", ns).Execute()).To(Succeed())

})

Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
Expect(DeleteConfigmap(ns, "my-cm")).To(Succeed())
Expect(DeleteConfigmap(ns, "my-cm-multi")).To(Succeed())
Expect(DeleteConfigmap(ns, "my-cm-properties")).To(Succeed())
Expect(DeleteConfigmap(ns, "my-cm-test-build-property")).To(Succeed())
Expect(DeleteConfigmap(ns, "my-cm-test-build-properties")).To(Succeed())
Expect(DeleteConfigmap(ns, "my-cm-test-property")).To(Succeed())
Expect(DeleteConfigmap(ns, "my-cm-test-properties")).To(Succeed())
Expect(DeleteSecret(ns, "my-sec-inlined")).To(Succeed())
Expect(DeleteSecret(ns, "my-sec-test-build-property")).To(Succeed())
Expect(DeleteSecret(ns, "my-sec-test-build-properties")).To(Succeed())
Expect(DeleteSecret(ns, "my-sec-test-property")).To(Succeed())
Expect(DeleteSecret(ns, "my-sec-test-properties")).To(Succeed())
Expect(DeleteSecret(ns, "my-sec")).To(Succeed())
Expect(DeleteSecret(ns, "my-sec-multi")).To(Succeed())
}
21 changes: 21 additions & 0 deletions e2e/common/config/files/property-secret-route.groovy
@@ -0,0 +1,21 @@
// 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:property')
.routeId('property')
.log('property content is: {{secret:my-sec-inlined/my-message}}')

0 comments on commit 729d982

Please sign in to comment.