This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new f47a007 fix(cmd/run): secret/configmap as property file
f47a007 is described below
commit f47a007894cab1233473e0ac770e5031648935a9
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Mon Jun 21 18:09:45 2021 +0200
fix(cmd/run): secret/configmap as property file
* Documentation
* Example
* E2E test
Closes #1838
---
.../ROOT/pages/configuration/runtime-config.adoc | 31 ++++++++++++++++++++++
e2e/common/config/config_test.go | 13 +++++++++
.../files/config-configmap-properties-route.groovy | 21 +++++++++++++++
.../config-secret-property-route.groovy | 28 +++++++++++++++++++
4 files changed, 93 insertions(+)
diff --git a/docs/modules/ROOT/pages/configuration/runtime-config.adoc
b/docs/modules/ROOT/pages/configuration/runtime-config.adoc
index 019ddf2..cb68f2b 100644
--- a/docs/modules/ROOT/pages/configuration/runtime-config.adoc
+++ b/docs/modules/ROOT/pages/configuration/runtime-config.adoc
@@ -99,6 +99,37 @@ As soon as the `Integration` starts, the `Camel-K` operator
will take care to mo
NOTE: you can provide a `Secret` which is not yet available on the cluster.
The `Integration` won't start until the resource will be made available.
+[[runtime-config-props]]
+== Configmap/Secret property references
+
+Each `Configmap`/`Secret` will be parsed as a property file and you will be
able to use those properties inside your `Route` definition or, more in
general, as you would do with any other
xref:configuration/runtime-properties.adoc[runtime property]. As an example,
you can create the following `Secret`:
+
+[source,text]
+.my.properties
+----
+my.key.1=hello
+my.key.2=world
+----
+----
+kubectl create secret generic my-secret-properties --from-file=my.properties
+----
+
+In our `Integration` we can simply refer the properties defined in the
`Secret` as we'd do with any other property:
+
+[source,groovy]
+.config-secret-property-route.groovy
+----
+from('timer:secret')
+ .routeId('secret')
+ .log('{{my.key.1}} {{my.key.2}}')
+----
+
+We have to just provide the `--config` we are willing to use:
+
+----
+kamel run --config secret:my-secret-properties
config-secret-property-route.groovy --dev
+----
+
[[runtime-config-keys]]
== Configmap/Secret key filtering
diff --git a/e2e/common/config/config_test.go b/e2e/common/config/config_test.go
index 07ba32f..0a93e78 100644
--- a/e2e/common/config/config_test.go
+++ b/e2e/common/config/config_test.go
@@ -109,6 +109,19 @@ func TestRunConfigExamples(t *testing.T) {
Expect(Kamel("delete", "--all", "-n",
ns).Execute()).To(Succeed())
})
+ // Store a configmap as property file
+ var cmDataProps = make(map[string]string)
+ cmDataProps["my.properties"] = "my.key.1=hello\nmy.key.2=world"
+ NewPlainTextConfigmap(ns, "my-cm-properties", cmDataProps)
+
+ t.Run("Config configmap as property file", func(t *testing.T) {
+ Expect(Kamel("run", "-n", ns,
"./files/config-configmap-properties-route.groovy", "--config",
"configmap:my-cm-properties").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns,
"config-configmap-properties-route"),
TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns,
"config-configmap-properties-route", camelv1.IntegrationConditionReady),
TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns,
"config-configmap-properties-route"),
TestTimeoutShort).Should(ContainSubstring("hello world"))
+ Expect(Kamel("delete", "--all", "-n",
ns).Execute()).To(Succeed())
+ })
+
// Secret
// Store a secret on the cluster
diff --git a/e2e/common/config/files/config-configmap-properties-route.groovy
b/e2e/common/config/files/config-configmap-properties-route.groovy
new file mode 100644
index 0000000..370337b
--- /dev/null
+++ b/e2e/common/config/files/config-configmap-properties-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:configmap')
+ .routeId('configmap')
+ .log('configmap content is: {{my.key.1}} {{my.key.2}}')
diff --git a/examples/user-config/config-secret-property-route.groovy
b/examples/user-config/config-secret-property-route.groovy
new file mode 100644
index 0000000..6a2ed2d
--- /dev/null
+++ b/examples/user-config/config-secret-property-route.groovy
@@ -0,0 +1,28 @@
+// 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.
+ */
+
+//
+// To run this integrations use:
+//
+// kubectl create secret generic my-secret-properties --from-file=my.properties
+// kamel run --config secret:my-secret-properties
config-secret-property-route.groovy --dev
+//
+
+from('timer:secret')
+ .routeId('secret')
+ .log('{{my.key.1}} {{my.key.2}}')