Search in sources :

Example 1 with ConfigMap

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

the class KubernetesConfigMapsProducer method doCreateConfigMap.

protected void doCreateConfigMap(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);
    HashMap<String, String> configMapData = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_DATA, HashMap.class);
    if (ObjectHelper.isEmpty(cfMapName)) {
        LOG.error("Create a specific configMap require specify a configMap name");
        throw new IllegalArgumentException("Create a specific configMap require specify a configMap name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Create a specific configMap require specify a namespace name");
        throw new IllegalArgumentException("Create a specific configMap require specify a namespace name");
    }
    if (ObjectHelper.isEmpty(configMapData)) {
        LOG.error("Create a specific configMap require specify a data map");
        throw new IllegalArgumentException("Create a specific configMap require specify a data map");
    }
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class);
    ConfigMap cfMapCreating = new ConfigMapBuilder().withNewMetadata().withName(cfMapName).withLabels(labels).endMetadata().withData(configMapData).build();
    configMap = getEndpoint().getKubernetesClient().configMaps().inNamespace(namespaceName).create(cfMapCreating);
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(configMap);
}
Also used : DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder)

Example 2 with ConfigMap

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

the class KubernetesConfigMapsProducer method doListConfigMapsByLabels.

protected void doListConfigMapsByLabels(Exchange exchange, String operation) throws Exception {
    ConfigMapList configMapsList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class);
    NonNamespaceOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps = getEndpoint().getKubernetesClient().configMaps();
    for (Map.Entry<String, String> entry : labels.entrySet()) {
        configMaps.withLabel(entry.getKey(), entry.getValue());
    }
    configMapsList = configMaps.list();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(configMapsList.getItems());
}
Also used : ConfigMapList(io.fabric8.kubernetes.api.model.ConfigMapList) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Resource(io.fabric8.kubernetes.client.dsl.Resource) HashMap(java.util.HashMap) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Map(java.util.Map) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap)

Example 3 with ConfigMap

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

the class KubernetesConfigMapsProducer method doGetConfigMap.

protected void doGetConfigMap(Exchange exchange, String operation) throws Exception {
    ConfigMap configMap = null;
    String cfMapName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_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();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(configMap);
}
Also used : DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap)

Example 4 with ConfigMap

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

the class KubernetesConfigMapsProducerTest method listByLabelsTest.

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

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("component", "elasticsearch");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, labels);
        }
    });
    List<ConfigMap> result = ex.getOut().getBody(List.class);
    boolean configMapExists = false;
    Iterator<ConfigMap> it = result.iterator();
    while (it.hasNext()) {
        ConfigMap cfMap = it.next();
        if (cfMap.getMetadata().getLabels().containsValue("elasticsearch")) {
            configMapExists = true;
        }
    }
    assertFalse(configMapExists);
}
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)

Example 5 with ConfigMap

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

the class KubernetesConfigMapsProducerTest method getConfigMapTest.

@Test
public void getConfigMapTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    Exchange 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, "elasticsearch-7015o");
        }
    });
    ConfigMap result = ex.getOut().getBody(ConfigMap.class);
    assertNull(result);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) 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