diff --git a/e2e/common/config/config_test.go b/e2e/common/config/config_test.go index 5de48e9696..f8b1ed7bf1 100644 --- a/e2e/common/config/config_test.go +++ b/e2e/common/config/config_test.go @@ -106,6 +106,12 @@ func TestRunConfigConfigmaps(t *testing.T) { err = CreatePlainTextConfigmap(t, ctx, ns, "my-cm-multi", cmDataMulti) g.Expect(err).To(BeNil()) + // Store a configmap that mocks the '--from-file' functionality + // kubectl create configmap my-cm-properties-file --from-file=./files/my.properties" + + err = CreateFromFileConfigmap(t, ctx, ns, "my-cm-properties-file", "./files/my.properties") + g.Expect(err).To(BeNil()) + t.Run("Config configmap", func(t *testing.T) { g.Expect(KamelRun(t, ctx, ns, "./files/config-configmap-route.yaml", "--config", "configmap:my-cm").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, "config-configmap-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) @@ -113,6 +119,20 @@ func TestRunConfigConfigmaps(t *testing.T) { g.Eventually(IntegrationLogs(t, ctx, ns, "config-configmap-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"])) }) + t.Run("Config configmap from properties file", func(t *testing.T) { + g.Expect(KamelRun(t, ctx, ns, "./files/config-configmap-properties-route.yaml", "--config", "configmap:my-cm-properties-file").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "config-configmap-properties-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "config-configmap-properties-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "config-configmap-properties-route"), TestTimeoutShort).Should(ContainSubstring("hello world")) + }) + + t.Run("Config configmap from properties file (interpolated)", func(t *testing.T) { + g.Expect(KamelRun(t, ctx, ns, "./files/config-configmap-properties-interpolation-route.yaml", "--config", "configmap:my-cm-properties-file").Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "config-configmap-properties-interpolation-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "config-configmap-properties-interpolation-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "config-configmap-properties-interpolation-route"), TestTimeoutShort).Should(ContainSubstring("hello world")) + }) + t.Run("Resource configmap", func(t *testing.T) { // We can reuse the configmap created previously g.Expect(KamelRun(t, ctx, ns, "./files/resource-configmap-route.yaml", "--resource", "configmap:my-cm").Execute()).To(Succeed()) diff --git a/e2e/common/config/files/config-configmap-properties-interpolation-route.yaml b/e2e/common/config/files/config-configmap-properties-interpolation-route.yaml new file mode 100644 index 0000000000..57cf9d67ff --- /dev/null +++ b/e2e/common/config/files/config-configmap-properties-interpolation-route.yaml @@ -0,0 +1,25 @@ +# camel-k: language=yaml + +# --------------------------------------------------------------------------- +# 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: + uri: "timer:configmap" + steps: + - setBody: + simple: "configmap content is: {{my.key.3}}" + - to: "log:info" diff --git a/e2e/common/config/files/my.properties b/e2e/common/config/files/my.properties index 3ab90369f1..502ea7bfdd 100644 --- a/e2e/common/config/files/my.properties +++ b/e2e/common/config/files/my.properties @@ -1,2 +1,3 @@ my.key.1=hello -my.key.2=world \ No newline at end of file +my.key.2=world +my.key.3=${my.key.1} ${my.key.2} \ No newline at end of file diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index 08cae0de33..11760f54f2 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -33,6 +33,7 @@ import ( "io" "os" "os/exec" + "path/filepath" "reflect" "regexp" "runtime/debug" @@ -1557,6 +1558,16 @@ func CreatePlainTextConfigmap(t *testing.T, ctx context.Context, ns string, name return CreatePlainTextConfigmapWithLabels(t, ctx, ns, name, data, map[string]string{}) } +func CreateFromFileConfigmap(t *testing.T, ctx context.Context, ns string, name string, pathToFile string) error { + content, _ := os.ReadFile(pathToFile) + filename := filepath.Base(pathToFile) + + var data = make(map[string]string) + data[filename] = string(content) + + return CreatePlainTextConfigmapWithLabels(t, ctx, ns, name, data, map[string]string{}) +} + func CreatePlainTextConfigmapWithLabels(t *testing.T, ctx context.Context, ns string, name string, data map[string]string, labels map[string]string) error { cm := corev1.ConfigMap{ TypeMeta: metav1.TypeMeta{