Search in sources :

Example 41 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project che by eclipse.

the class OpenShiftConnector method createImageStreamTag.

/**
     * Creates a new ImageStreamTag
     *
     * @param sourceImageWithTag the image that the ImageStreamTag will track
     * @param imageStreamTagName the name of the imageStream tag (e.g. {@code <ImageStream name>:<Tag name>})
     * @return the created ImageStreamTag
     * @throws IOException When {@code sourceImageWithTag} metadata cannot be found
     */
private ImageStreamTag createImageStreamTag(String sourceImageWithTag, String imageStreamTagName) throws IOException {
    try {
        openShiftClient.imageStreamTags().inNamespace(openShiftCheProjectName).createOrReplaceWithNew().withNewMetadata().withName(imageStreamTagName).endMetadata().withNewTag().withNewFrom().withKind("DockerImage").withName(sourceImageWithTag).endFrom().endTag().done();
        // Wait for image metadata to be pulled
        for (int waitCount = 0; waitCount < OPENSHIFT_IMAGESTREAM_MAX_WAIT_COUNT; waitCount++) {
            Thread.sleep(OPENSHIFT_IMAGESTREAM_WAIT_DELAY);
            ImageStreamTag createdTag = openShiftClient.imageStreamTags().inNamespace(openShiftCheProjectName).withName(imageStreamTagName).get();
            if (createdTag != null) {
                LOG.info(String.format("Created ImageStreamTag %s in namespace %s", createdTag.getMetadata().getName(), openShiftCheProjectName));
                return createdTag;
            }
        }
        throw new ImageNotFoundException(String.format("Image %s not found.", sourceImageWithTag));
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException(e.getLocalizedMessage(), e);
    }
}
Also used : ImageStreamTag(io.fabric8.openshift.api.model.ImageStreamTag) IOException(java.io.IOException) ImageNotFoundException(org.eclipse.che.plugin.docker.client.exception.ImageNotFoundException)

Example 42 with Namespace

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

the class KubernetesServicesProducer method doGetService.

protected void doGetService(Exchange exchange, String operation) throws Exception {
    Service service = null;
    String serviceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (ObjectHelper.isEmpty(serviceName)) {
        LOG.error("Get a specific service require specify a service name");
        throw new IllegalArgumentException("Get a specific service require specify a service name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Get a specific service require specify a namespace name");
        throw new IllegalArgumentException("Get a specific service require specify a namespace name");
    }
    service = getEndpoint().getKubernetesClient().services().inNamespace(namespaceName).withName(serviceName).get();
    exchange.getOut().setBody(service);
}
Also used : DoneableService(io.fabric8.kubernetes.api.model.DoneableService) Service(io.fabric8.kubernetes.api.model.Service)

Example 43 with Namespace

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

the class KubernetesNamespacesProducerTest method listTest.

@Test
public void listTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    List<Namespace> result = template.requestBody("direct:list", "", List.class);
    boolean defaultExists = false;
    Iterator<Namespace> it = result.iterator();
    while (it.hasNext()) {
        Namespace namespace = it.next();
        if ("default".equalsIgnoreCase(namespace.getMetadata().getName())) {
            defaultExists = true;
        }
    }
    assertTrue(defaultExists);
}
Also used : Namespace(io.fabric8.kubernetes.api.model.Namespace) Test(org.junit.Test)

Example 44 with Namespace

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

the class KubernetesNamespacesProducerTest method createAndDeleteNamespace.

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

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, labels);
        }
    });
    Namespace ns = ex.getOut().getBody(Namespace.class);
    assertEquals(ns.getMetadata().getName(), "test");
    ex = template.request("direct:deleteNamespace", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
        }
    });
    boolean nsDeleted = ex.getOut().getBody(Boolean.class);
    assertTrue(nsDeleted);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Map(java.util.Map) HashMap(java.util.HashMap) Namespace(io.fabric8.kubernetes.api.model.Namespace) Test(org.junit.Test)

Example 45 with Namespace

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

the class KubernetesNamespacesProducerTest method createListByLabelsAndDeleteNamespace.

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

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, labels);
        }
    });
    Namespace ns = ex.getOut().getBody(Namespace.class);
    assertEquals(ns.getMetadata().getName(), "test");
    ex = template.request("direct:listByLabels", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, labels);
        }
    });
    List<Namespace> result = ex.getOut().getBody(List.class);
    boolean testExists = false;
    Iterator<Namespace> it = result.iterator();
    while (it.hasNext()) {
        Namespace namespace = it.next();
        if ("test".equalsIgnoreCase(namespace.getMetadata().getName())) {
            testExists = true;
        }
    }
    assertTrue(testExists);
    ex = template.request("direct:deleteNamespace", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
        }
    });
    boolean nsDeleted = ex.getOut().getBody(Boolean.class);
    assertTrue(nsDeleted);
}
Also used : Processor(org.apache.camel.Processor) HashMap(java.util.HashMap) Namespace(io.fabric8.kubernetes.api.model.Namespace) Exchange(org.apache.camel.Exchange) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Service (io.fabric8.kubernetes.api.model.Service)12 Test (org.junit.Test)11 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)10 Namespace (io.fabric8.kubernetes.api.model.Namespace)8 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)7 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)7 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)6 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)6 BaseOperation (io.fabric8.kubernetes.client.dsl.base.BaseOperation)5 ArrayList (java.util.ArrayList)5 API (org.wso2.carbon.apimgt.core.models.API)5 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)4 Map (java.util.Map)4 Exchange (org.apache.camel.Exchange)4 Processor (org.apache.camel.Processor)4 DoneableNamespace (io.fabric8.kubernetes.api.model.DoneableNamespace)3 DoneableReplicationController (io.fabric8.kubernetes.api.model.DoneableReplicationController)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)3 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)3 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)3