Search in sources :

Example 6 with ImageStreamTag

use of io.fabric8.openshift.api.model.ImageStreamTag in project che by eclipse.

the class OpenShiftConnector method removeImage.

@Override
public void removeImage(final RemoveImageParams params) throws IOException {
    String image = KubernetesStringUtils.getImageStreamNameFromPullSpec(params.getImage());
    String imageStreamTagName = KubernetesStringUtils.convertPullSpecToTagName(image);
    ImageStreamTag imageStreamTag = getImageStreamTagFromRepo(imageStreamTagName);
    openShiftClient.resource(imageStreamTag).delete();
}
Also used : ImageStreamTag(io.fabric8.openshift.api.model.ImageStreamTag)

Example 7 with ImageStreamTag

use of io.fabric8.openshift.api.model.ImageStreamTag 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 8 with ImageStreamTag

use of io.fabric8.openshift.api.model.ImageStreamTag in project che by eclipse.

the class OpenShiftConnector method inspectContainer.

@Override
public ContainerInfo inspectContainer(String containerId) throws IOException {
    Pod pod = getChePodByContainerId(containerId);
    if (pod == null) {
        LOG.warn("No Pod found by container ID {}", containerId);
        return null;
    }
    List<Container> podContainers = pod.getSpec().getContainers();
    if (podContainers.size() > 1) {
        throw new OpenShiftException("Multiple Containers found in Pod.");
    } else if (podContainers.size() < 1 || isNullOrEmpty(podContainers.get(0).getImage())) {
        throw new OpenShiftException(String.format("Container %s not found", containerId));
    }
    String podPullSpec = podContainers.get(0).getImage();
    String tagName = KubernetesStringUtils.getTagNameFromPullSpec(podPullSpec);
    ImageStreamTag tag = getImageStreamTagFromRepo(tagName);
    ImageInfo imageInfo = getImageInfoFromTag(tag);
    String deploymentName = pod.getMetadata().getLabels().get(OPENSHIFT_DEPLOYMENT_LABEL);
    if (deploymentName == null) {
        LOG.warn("No label {} found for Pod {}", OPENSHIFT_DEPLOYMENT_LABEL, pod.getMetadata().getName());
        return null;
    }
    Service svc = getCheServiceBySelector(OPENSHIFT_DEPLOYMENT_LABEL, deploymentName);
    if (svc == null) {
        LOG.warn("No Service found by selector {}={}", OPENSHIFT_DEPLOYMENT_LABEL, deploymentName);
        return null;
    }
    return createContainerInfo(svc, imageInfo, pod, containerId);
}
Also used : KubernetesContainer(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesContainer) Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) OpenShiftException(org.eclipse.che.plugin.openshift.client.exception.OpenShiftException) ImageStreamTag(io.fabric8.openshift.api.model.ImageStreamTag) KubernetesService(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesService) Service(io.fabric8.kubernetes.api.model.Service) ImageInfo(org.eclipse.che.plugin.docker.client.json.ImageInfo)

Aggregations

ImageStreamTag (io.fabric8.openshift.api.model.ImageStreamTag)8 IOException (java.io.IOException)4 Pod (io.fabric8.kubernetes.api.model.Pod)3 OpenShiftException (org.eclipse.che.plugin.openshift.client.exception.OpenShiftException)3 Container (io.fabric8.kubernetes.api.model.Container)2 Service (io.fabric8.kubernetes.api.model.Service)2 ImageStream (io.fabric8.openshift.api.model.ImageStream)2 ContainerCreated (org.eclipse.che.plugin.docker.client.json.ContainerCreated)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)1 PodList (io.fabric8.kubernetes.api.model.PodList)1 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)1 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)1 Probe (io.fabric8.kubernetes.api.model.Probe)1 ProbeBuilder (io.fabric8.kubernetes.api.model.ProbeBuilder)1 ServiceList (io.fabric8.kubernetes.api.model.ServiceList)1 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)1 Volume (io.fabric8.kubernetes.api.model.Volume)1 VolumeBuilder (io.fabric8.kubernetes.api.model.VolumeBuilder)1 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)1