Search in sources :

Example 1 with NamespaceBuilder

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);
}
Also used : DoneableNamespace(io.fabric8.kubernetes.api.model.DoneableNamespace) Namespace(io.fabric8.kubernetes.api.model.Namespace) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder)

Example 2 with NamespaceBuilder

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);
        }
    }
}
Also used : ProjectRequestBuilder(io.fabric8.openshift.api.model.ProjectRequestBuilder) HashMap(java.util.HashMap) ProjectRequest(io.fabric8.openshift.api.model.ProjectRequest) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Namespace(io.fabric8.kubernetes.api.model.Namespace) KubernetesHelper.getNamespace(io.fabric8.kubernetes.api.KubernetesHelper.getNamespace) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder)

Example 3 with NamespaceBuilder

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();
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) ImmutableClusterExtension(org.curioswitch.gradle.plugins.gcloud.ImmutableClusterExtension) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Namespace(io.fabric8.kubernetes.api.model.Namespace) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

Namespace (io.fabric8.kubernetes.api.model.Namespace)3 NamespaceBuilder (io.fabric8.kubernetes.api.model.NamespaceBuilder)3 KubernetesHelper.getNamespace (io.fabric8.kubernetes.api.KubernetesHelper.getNamespace)1 DoneableNamespace (io.fabric8.kubernetes.api.model.DoneableNamespace)1 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)1 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 ProjectRequest (io.fabric8.openshift.api.model.ProjectRequest)1 ProjectRequestBuilder (io.fabric8.openshift.api.model.ProjectRequestBuilder)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1 HashMap (java.util.HashMap)1 ImmutableClusterExtension (org.curioswitch.gradle.plugins.gcloud.ImmutableClusterExtension)1 TaskAction (org.gradle.api.tasks.TaskAction)1