camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [camel] 01/03: CAMEL-12891 - Allow getConfigMap operation to specify namespace.
Date Mon, 22 Oct 2018 06:02:45 GMT
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e998c9f2d79d5dd916c339178abf1d7bf8977e47
Author: Bob Paulin <bob@bobpaulin.com>
AuthorDate: Fri Oct 19 22:26:49 2018 -0500

    CAMEL-12891 - Allow getConfigMap operation to specify namespace.
---
 .../config_maps/KubernetesConfigMapsProducer.java  |  7 ++++++-
 .../producer/KubernetesConfigMapsProducerTest.java | 24 ++++++++++++++++++++--
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsProducer.java
b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsProducer.java
index 7513a8e..6878a33 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsProducer.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsProducer.java
@@ -109,11 +109,16 @@ public class KubernetesConfigMapsProducer extends DefaultProducer {
     protected void doGetConfigMap(Exchange exchange, String operation) throws Exception {
         ConfigMap configMap = null;
         String cfMapName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME,
String.class);
+        String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
String.class);
         if (ObjectHelper.isEmpty(cfMapName)) {
             LOG.error("Get a specific ConfigMap require specify a ConfigMap name");
             throw new IllegalArgumentException("Get a specific ConfigMap require specify
a ConfigMap name");
         }
-        configMap = getEndpoint().getKubernetesClient().configMaps().withName(cfMapName).get();
+        if(namespaceName != null) {
+            configMap = getEndpoint().getKubernetesClient().configMaps().inNamespace(namespaceName).withName(cfMapName).get();
+        } else {
+            configMap = getEndpoint().getKubernetesClient().configMaps().withName(cfMapName).get();
+        }
 
         MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
         exchange.getOut().setBody(configMap);
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducerTest.java
index ef63de6..2205c4c 100644
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducerTest.java
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducerTest.java
@@ -73,9 +73,9 @@ public class KubernetesConfigMapsProducerTest extends KubernetesTestSupport
{
 
         assertEquals(3, result.size());
     }
-
+    
     @Test
-    public void getConfigMapTest() throws Exception {
+    public void getConfigMapTestDefaultNamespace() throws Exception {
         ObjectMeta meta = new ObjectMeta();
         meta.setName("cm1");
         server.expect().withPath("/api/v1/namespaces/test/configmaps/cm1").andReturn(200,
new ConfigMapBuilder().withMetadata(meta).build()).once();
@@ -95,6 +95,26 @@ public class KubernetesConfigMapsProducerTest extends KubernetesTestSupport
{
     }
 
     @Test
+    public void getConfigMapTestCustomNamespace() throws Exception {
+        ObjectMeta meta = new ObjectMeta();
+        meta.setName("cm1");
+        server.expect().withPath("/api/v1/namespaces/custom/configmaps/cm1").andReturn(200,
new ConfigMapBuilder().withMetadata(meta).build()).once();
+        server.expect().withPath("/api/v1/namespaces/custom/configmaps/cm2").andReturn(200,
new ConfigMapBuilder().build()).once();
+        Exchange ex = template.request("direct:getConfigMap", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
"custom");
+                exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME,
"cm1");
+            }
+        });
+
+        ConfigMap result = ex.getOut().getBody(ConfigMap.class);
+
+        assertEquals("cm1", result.getMetadata().getName());
+    }
+
+    @Test
     public void createGetAndDeleteConfigMap() throws Exception {
         ConfigMap cm1 = new ConfigMapBuilder().withNewMetadata().withName("cm1").withNamespace("test").and().build();
         server.expect().withPath("/api/v1/namespaces/test/configmaps/cm1").andReturn(200,
cm1).once();


Mime
View raw message