Search in sources :

Example 16 with ImageStream

use of io.fabric8.openshift.api.model.ImageStream in project strimzi by strimzi.

the class KafkaConnectS2IClusterTest method testGenerateSourceImageStream.

@Test
public void testGenerateSourceImageStream() {
    ImageStream is = kc.generateSourceImageStream();
    assertEquals(kc.getSourceImageStreamName(), is.getMetadata().getName());
    assertEquals(namespace, is.getMetadata().getNamespace());
    assertEquals(ResourceUtils.labels(Labels.STRIMZI_CLUSTER_LABEL, cluster, Labels.STRIMZI_TYPE_LABEL, "kafka-connect-s2i", "my-user-label", "cromulent", Labels.STRIMZI_NAME_LABEL, kc.getSourceImageStreamName()), is.getMetadata().getLabels());
    assertEquals(false, is.getSpec().getLookupPolicy().getLocal());
    assertEquals(1, is.getSpec().getTags().size());
    assertEquals(image.substring(image.lastIndexOf(":") + 1), is.getSpec().getTags().get(0).getName());
    assertEquals("DockerImage", is.getSpec().getTags().get(0).getFrom().getKind());
    assertEquals(image, is.getSpec().getTags().get(0).getFrom().getName());
}
Also used : ImageStream(io.fabric8.openshift.api.model.ImageStream) Test(org.junit.Test)

Example 17 with ImageStream

use of io.fabric8.openshift.api.model.ImageStream in project strimzi by strimzi.

the class KafkaConnectS2IClusterTest method testGenerateTargetImageStream.

@Test
public void testGenerateTargetImageStream() {
    ImageStream is = kc.generateTargetImageStream();
    assertEquals(kc.kafkaConnectClusterName(cluster), is.getMetadata().getName());
    assertEquals(namespace, is.getMetadata().getNamespace());
    assertEquals(ResourceUtils.labels(Labels.STRIMZI_CLUSTER_LABEL, cluster, Labels.STRIMZI_TYPE_LABEL, "kafka-connect-s2i", "my-user-label", "cromulent", Labels.STRIMZI_NAME_LABEL, kc.kafkaConnectClusterName(cluster)), is.getMetadata().getLabels());
    assertEquals(true, is.getSpec().getLookupPolicy().getLocal());
}
Also used : ImageStream(io.fabric8.openshift.api.model.ImageStream) Test(org.junit.Test)

Example 18 with ImageStream

use of io.fabric8.openshift.api.model.ImageStream in project vertx-openshift-it by cescoffier.

the class Deployment method deployIfNeeded.

public static String deployIfNeeded(KubernetesClient client, String name, String path) {
    if (oc(client).deploymentConfigs().withName(name).get() != null) {
        System.out.println("Skipping the creation of dc/" + name);
        return name;
    }
    ImageStream stream = findImageStream(client, name);
    ensureThat("the image stream " + name + " exists in the namespace " + client.getNamespace(), () -> assertThat(stream).isNotNull());
    File file = filter(Objects.requireNonNull(path), ImmutableMap.of("image", stream.getStatus().getDockerImageRepository()));
    String name2 = deployIfNeeded(client, file);
    assertThat(name).isEqualTo(name2);
    return name;
}
Also used : ImageStream(io.fabric8.openshift.api.model.ImageStream) File(java.io.File)

Example 19 with ImageStream

use of io.fabric8.openshift.api.model.ImageStream in project kie-wb-common by kiegroup.

the class OpenShiftClient method createFromUri.

private void createFromUri(String prjName, String uri) throws OpenShiftClientException {
    URL url = toUrl(uri);
    if (url != null) {
        KubernetesList kubeList = delegate.lists().load(url).get();
        List<HasMetadata> items = kubeList.getItems();
        if (items.size() > 0) {
            for (HasMetadata item : items) {
                String name = item.getMetadata().getName();
                if (item instanceof ServiceAccount) {
                    if (delegate.serviceAccounts().inNamespace(prjName).withName(name).get() == null) {
                        setGuvnorAlaGenerated(item);
                    }
                } else if (item instanceof Secret) {
                    if (delegate.secrets().inNamespace(prjName).withName(name).get() == null) {
                        setGuvnorAlaGenerated(item);
                    }
                } else if (item instanceof ImageStream) {
                    if (delegate.imageStreams().inNamespace(prjName).withName(name).get() == null) {
                        setGuvnorAlaGenerated(item);
                    }
                }
            }
            delegate.lists().inNamespace(prjName).create(kubeList);
        }
    }
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) URL(java.net.URL)

Example 20 with ImageStream

use of io.fabric8.openshift.api.model.ImageStream in project fabric8 by jboss-fuse.

the class Controller method applyEntity.

/**
 * Applies the given DTOs onto the Kubernetes master
 */
public void applyEntity(Object dto, String sourceName) throws Exception {
    if (dto instanceof Pod) {
        applyPod((Pod) dto, sourceName);
    } else if (dto instanceof ReplicationController) {
        applyReplicationController((ReplicationController) dto, sourceName);
    } else if (dto instanceof Service) {
        applyService((Service) dto, sourceName);
    } else if (dto instanceof Namespace) {
        applyNamespace((Namespace) dto);
    } else if (dto instanceof Route) {
        applyRoute((Route) dto, sourceName);
    } else if (dto instanceof BuildConfig) {
        applyBuildConfig((BuildConfig) dto, sourceName);
    } else if (dto instanceof DeploymentConfig) {
        DeploymentConfig resource = (DeploymentConfig) dto;
        OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
        if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.APPS)) {
            applyResource(resource, sourceName, openShiftClient.deploymentConfigs());
        } else {
            LOG.warn("Not connected to OpenShift cluster so cannot apply entity " + dto);
        }
    } else if (dto instanceof PolicyBinding) {
        applyPolicyBinding((PolicyBinding) dto, sourceName);
    } else if (dto instanceof RoleBinding) {
        applyRoleBinding((RoleBinding) dto, sourceName);
    } else if (dto instanceof Role) {
        Role resource = (Role) dto;
        OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
        if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.AUTHORIZATION)) {
            applyResource(resource, sourceName, openShiftClient.roles());
        } else {
            LOG.warn("Not connected to OpenShift cluster so cannot apply entity " + dto);
        }
    } else if (dto instanceof ImageStream) {
        applyImageStream((ImageStream) dto, sourceName);
    } else if (dto instanceof OAuthClient) {
        applyOAuthClient((OAuthClient) dto, sourceName);
    } else if (dto instanceof Template) {
        applyTemplate((Template) dto, sourceName);
    } else if (dto instanceof ServiceAccount) {
        applyServiceAccount((ServiceAccount) dto, sourceName);
    } else if (dto instanceof Secret) {
        applySecret((Secret) dto, sourceName);
    } else if (dto instanceof ConfigMap) {
        applyResource((ConfigMap) dto, sourceName, kubernetesClient.configMaps());
    } else if (dto instanceof DaemonSet) {
        applyResource((DaemonSet) dto, sourceName, kubernetesClient.extensions().daemonSets());
    } else if (dto instanceof Deployment) {
        applyResource((Deployment) dto, sourceName, kubernetesClient.extensions().deployments());
    } else if (dto instanceof ReplicaSet) {
        applyResource((ReplicaSet) dto, sourceName, kubernetesClient.extensions().replicaSets());
    } else if (dto instanceof StatefulSet) {
        applyResource((StatefulSet) dto, sourceName, kubernetesClient.apps().statefulSets());
    } else if (dto instanceof Ingress) {
        applyResource((Ingress) dto, sourceName, kubernetesClient.extensions().ingresses());
    } else if (dto instanceof PersistentVolumeClaim) {
        applyPersistentVolumeClaim((PersistentVolumeClaim) dto, sourceName);
    } else if (dto instanceof HasMetadata) {
        HasMetadata entity = (HasMetadata) dto;
        try {
            String namespace = getNamespace();
            String resourceNamespace = getNamespace(entity);
            if (Strings.isNotBlank(namespace) && Strings.isNullOrBlank(resourceNamespace)) {
                getOrCreateMetadata(entity).setNamespace(namespace);
            }
            LOG.info("Applying " + getKind(entity) + " " + getName(entity) + " from " + sourceName);
            kubernetesClient.resource(entity).inNamespace(namespace).createOrReplace();
        } catch (Exception e) {
            onApplyError("Failed to create " + getKind(entity) + " from " + sourceName + ". " + e, e);
        }
    } else {
        throw new IllegalArgumentException("Unknown entity type " + dto);
    }
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) OAuthClient(io.fabric8.openshift.api.model.OAuthClient) DoneableImageStream(io.fabric8.openshift.api.model.DoneableImageStream) ImageStream(io.fabric8.openshift.api.model.ImageStream) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) Template(io.fabric8.openshift.api.model.Template) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) RoleBinding(io.fabric8.openshift.api.model.RoleBinding) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) Route(io.fabric8.openshift.api.model.Route) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Pod(io.fabric8.kubernetes.api.model.Pod) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Namespace(io.fabric8.kubernetes.api.model.Namespace) PolicyBinding(io.fabric8.openshift.api.model.PolicyBinding) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) FileNotFoundException(java.io.FileNotFoundException) OpenShiftNotAvailableException(io.fabric8.openshift.client.OpenShiftNotAvailableException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Role(io.fabric8.openshift.api.model.Role) Secret(io.fabric8.kubernetes.api.model.Secret) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DaemonSet(io.fabric8.kubernetes.api.model.extensions.DaemonSet) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet)

Aggregations

ImageStream (io.fabric8.openshift.api.model.ImageStream)21 IOException (java.io.IOException)11 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)9 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)9 Service (io.fabric8.kubernetes.api.model.Service)7 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)7 Test (org.junit.Test)7 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)6 Secret (io.fabric8.kubernetes.api.model.Secret)5 File (java.io.File)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)4 DoneableImageStream (io.fabric8.openshift.api.model.DoneableImageStream)4 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)4 Reconciliation (io.strimzi.controller.cluster.Reconciliation)4 KafkaConnectS2ICluster (io.strimzi.controller.cluster.model.KafkaConnectS2ICluster)4 BuildConfigOperator (io.strimzi.controller.cluster.operator.resource.BuildConfigOperator)4 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)4 DeploymentConfigOperator (io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator)4