Search in sources :

Example 6 with ConfigMap

use of io.fabric8.kubernetes.api.model.ConfigMap in project camel by apache.

the class KubernetesConfigMapsProducerTest method createGetAndDeleteConfigMap.

@Test
public void createGetAndDeleteConfigMap() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    Exchange ex = template.request("direct:createConfigMap", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, "test");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, labels);
            Map<String, String> data = new HashMap<String, String>();
            data.put("test", "test1");
            data.put("test1", "test2");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_DATA, data);
        }
    });
    ex = template.request("direct:getConfigMap", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, "test");
        }
    });
    ConfigMap result = ex.getOut().getBody(ConfigMap.class);
    assertNotNull(result);
    assertTrue(result.getData().containsKey("test"));
    assertTrue(result.getData().containsKey("test1"));
    assertEquals("test1", result.getData().get("test"));
    assertEquals("test2", result.getData().get("test1"));
    ex = template.request("direct:deleteConfigMap", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, "test");
        }
    });
    boolean configMapDeleted = ex.getOut().getBody(Boolean.class);
    assertTrue(configMapDeleted);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Map(java.util.Map) HashMap(java.util.HashMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Test(org.junit.Test)

Aggregations

ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)6 DoneableConfigMap (io.fabric8.kubernetes.api.model.DoneableConfigMap)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Exchange (org.apache.camel.Exchange)3 Processor (org.apache.camel.Processor)3 Test (org.junit.Test)3 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)1 ConfigMapList (io.fabric8.kubernetes.api.model.ConfigMapList)1 Resource (io.fabric8.kubernetes.client.dsl.Resource)1