use of io.fabric8.kubernetes.api.model.NamespaceBuilder in project camel by apache.
the class KubernetesNamespacesProducer method doCreateNamespace.
protected void doCreateNamespace(Exchange exchange, String operation) {
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Create a specific namespace require specify a namespace name");
throw new IllegalArgumentException("Create a specific namespace require specify a namespace name");
}
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, Map.class);
Namespace ns = new NamespaceBuilder().withNewMetadata().withName(namespaceName).withLabels(labels).endMetadata().build();
Namespace namespace = getEndpoint().getKubernetesClient().namespaces().create(ns);
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(namespace);
}
use of io.fabric8.kubernetes.api.model.NamespaceBuilder in project fabric8-maven-plugin by fabric8io.
the class ImportMojo method ensureNamespaceExists.
private void ensureNamespaceExists(KubernetesClient kubernetes, String name) {
name = convertToValidDnsLabel(name);
// lets check namespace exists
Namespace namespace = kubernetes.namespaces().withName(name).get();
if (namespace == null) {
Map<String, String> labels = new HashMap<>();
labels.put("provider", "fabric8");
labels.put("kind", "secrets");
namespace = new NamespaceBuilder().withNewMetadata().withName(name).withLabels(labels).endMetadata().build();
if (KubernetesHelper.isOpenShift(kubernetes)) {
ProjectRequest projectRequest = new ProjectRequestBuilder().withMetadata(namespace.getMetadata()).build();
OpenShiftClient openShiftClient = asOpenShiftClient(kubernetes);
log.info("Creating ProjectRequest " + name + " with labels: " + labels);
openShiftClient.projectrequests().create(projectRequest);
} else {
log.info("Creating Namespace " + name + " with labels: " + labels);
kubernetes.namespaces().withName(name).create(namespace);
}
}
}
use of io.fabric8.kubernetes.api.model.NamespaceBuilder in project curiostack by curioswitch.
the class CreateClusterNamespaceTask method exec.
@TaskAction
public void exec() {
ImmutableClusterExtension cluster = getProject().getExtensions().getByType(ClusterExtension.class);
Namespace namespace = new NamespaceBuilder().withMetadata(new ObjectMetaBuilder().withName(cluster.namespace()).build()).build();
KubernetesClient client = new DefaultKubernetesClient();
client.resource(namespace).createOrReplace();
}
Aggregations