Skip to content

Commit

Permalink
Fix OpenShiftConnector.inspectImage() to resolve issue in OS 3.6+
Browse files Browse the repository at this point in the history
OpenShiftConnector.inspectImage() uses pods to figure out a workspaces
docker image. Previously, this was not a problem as it would match
the imagestream tag we create earlier. However, in OpenShift 3.6 and
higher, it seems like pods created by deployments use the sha256 of
the image as an identifier, and so this fails. This means that
workspaces fail to start due to imagestream not found.

To resolve this issue, we instead get the image name through the
deployment, which does have the correct value.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
  • Loading branch information
amisevsk authored and ibuziuk committed Aug 16, 2017
1 parent 0cada6b commit 2cd0ab0
Showing 1 changed file with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -558,24 +558,39 @@ public ContainerInfo inspectContainer(String containerId) throws IOException {
return null;
}

List<Container> podContainers = pod.getSpec().getContainers();
if (podContainers.size() > 1) {
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;
}

Deployment deployment;
try (OpenShiftClient client = new DefaultOpenShiftClient()) {
deployment = client.extensions().deployments().withName(deploymentName).get();
if (deployment == null) {
LOG.warn("No deployment matching label {}={} found", OPENSHIFT_DEPLOYMENT_LABEL,
deploymentName);
return null;
}
}

List<Container> deploymentContainers = deployment.getSpec()
.getTemplate()
.getSpec()
.getContainers();
if (deploymentContainers.size() > 1) {
throw new OpenShiftException("Multiple Containers found in Pod.");
} else if (podContainers.size() < 1 || isNullOrEmpty(podContainers.get(0).getImage())) {
} else if (deploymentContainers.size() < 1 || isNullOrEmpty(deploymentContainers.get(0).getImage())) {
throw new OpenShiftException(String.format("Container %s not found", containerId));
}
String podPullSpec = podContainers.get(0).getImage();
String podPullSpec = deploymentContainers.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) {
Expand Down

0 comments on commit 2cd0ab0

Please sign in to comment.