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();
}
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);
}
}
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);
}
Aggregations