Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions e2e/common/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,33 @@ 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))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "config-configmap-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion e2e/common/config/files/my.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
my.key.1=hello
my.key.2=world
my.key.2=world
my.key.3=${my.key.1} ${my.key.2}
11 changes: 11 additions & 0 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"reflect"
"regexp"
"runtime/debug"
Expand Down Expand Up @@ -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{
Expand Down
Loading