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);
}
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());
}
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);
}
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);
}
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);
}
Aggregations