use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesNamespacesProducer method doListNamespaceByLabel.
protected void doListNamespaceByLabel(Exchange exchange, String operation) {
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, Map.class);
if (ObjectHelper.isEmpty(labels)) {
LOG.error("Get a specific namespace by labels require specify a labels set");
throw new IllegalArgumentException("Get a specific namespace by labels require specify a labels set");
}
NonNamespaceOperation<Namespace, NamespaceList, DoneableNamespace, Resource<Namespace, DoneableNamespace>> namespaces = getEndpoint().getKubernetesClient().namespaces();
for (Map.Entry<String, String> entry : labels.entrySet()) {
namespaces.withLabel(entry.getKey(), entry.getValue());
}
NamespaceList namespace = namespaces.list();
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(namespace.getItems());
}
use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesClientServiceDiscovery method getServices.
@Override
public List<ServiceDefinition> getServices(String name) {
LOG.debug("Discovering endpoints from namespace: {} with name: {}", getNamespace(), name);
Endpoints endpoints = client.endpoints().inNamespace(getNamespace()).withName(name).get();
List<ServiceDefinition> result = new ArrayList<>();
if (endpoints != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Found {} endpoints in namespace: {} for name: {} and portName: {}", endpoints.getSubsets().size(), getNamespace(), name, getPortName());
}
for (EndpointSubset subset : endpoints.getSubsets()) {
if (subset.getPorts().size() == 1) {
addServers(name, result, subset.getPorts().get(FIRST), subset);
} else {
final List<EndpointPort> ports = subset.getPorts();
final int portSize = ports.size();
EndpointPort port;
for (int p = 0; p < portSize; p++) {
port = ports.get(p);
if (ObjectHelper.isEmpty(getPortName()) || getPortName().endsWith(port.getName())) {
addServers(name, result, port, subset);
}
}
}
}
}
return result;
}
use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesBuildConfigsProducer method doGetBuildConfig.
protected void doGetBuildConfig(Exchange exchange, String operation) throws Exception {
BuildConfig buildConfig = null;
String buildConfigName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_CONFIG_NAME, String.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (ObjectHelper.isEmpty(buildConfigName)) {
LOG.error("Get a specific Build Config require specify a Build Config name");
throw new IllegalArgumentException("Get a specific Build Config require specify a Build Config name");
}
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Get a specific Build Config require specify a namespace name");
throw new IllegalArgumentException("Get a specific Build Config require specify a namespace name");
}
buildConfig = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs().inNamespace(namespaceName).withName(buildConfigName).get();
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(buildConfig);
}
use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesBuildsProducer method doGetBuild.
protected void doGetBuild(Exchange exchange, String operation) throws Exception {
Build build = null;
String buildName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_NAME, String.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (ObjectHelper.isEmpty(buildName)) {
LOG.error("Get a specific Build require specify a Build name");
throw new IllegalArgumentException("Get a specific Build require specify a Build name");
}
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Get a specific Build require specify a namespace name");
throw new IllegalArgumentException("Get a specific Build require specify a namespace name");
}
build = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).builds().inNamespace(namespaceName).withName(buildName).get();
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(build);
}
use of io.fabric8.kubernetes.api.model.Namespace 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);
}
Aggregations