From f538239200f138d65d62cfffa13d6bb9a80461fd Mon Sep 17 00:00:00 2001 From: Mario Loriedo Date: Mon, 27 Mar 2017 11:58:08 +0200 Subject: [PATCH] Fix dockerImageConfig is null (since v1.5 of OpenShift API) --- .../openshift/client/OpenShiftConnector.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java b/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java index 086a94408f3..b518efa4247 100644 --- a/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java +++ b/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java @@ -124,6 +124,7 @@ import io.fabric8.kubernetes.client.dsl.ExecWatch; import io.fabric8.kubernetes.client.dsl.LogWatch; import io.fabric8.kubernetes.client.utils.InputStreamPumper; +import io.fabric8.openshift.api.model.Image; import io.fabric8.openshift.api.model.ImageStream; import io.fabric8.openshift.api.model.ImageStreamTag; import io.fabric8.openshift.api.model.Route; @@ -896,12 +897,21 @@ private ImageInfo getImageInfoFromTag(ImageStreamTag imageStreamTag) { // except that the capitalization is inconsistent, breaking deserialization. Top level elements // are lowercased with underscores, while nested elements conform to FieldNamingPolicy.UPPER_CAMEL_CASE. // We're only converting the config fields for brevity; this means that other fields are null. - String dockerImageConfig = imageStreamTag.getImage().getDockerImageConfig(); - ImageInfo info = GSON.fromJson(dockerImageConfig.replaceFirst("config", "Config") - .replaceFirst("container_config", "ContainerConfig"), - ImageInfo.class); - - return info; + Image tagImage = imageStreamTag.getImage(); + String dockerImageConfig = tagImage.getDockerImageConfig(); + + if (!isNullOrEmpty(dockerImageConfig)) { + LOG.info("imageStreamTag dockerImageConfig is not empty. Using it to get image info"); + ImageInfo info = GSON.fromJson(dockerImageConfig.replaceFirst("config", "Config") + .replaceFirst("container_config", "ContainerConfig"), + ImageInfo.class); + return info; + } else { + LOG.info("imageStreamTag dockerImageConfig empty. Using dockerImageMetadata to get image info"); + String dockerImageMetadata = GSON.toJson(tagImage.getAdditionalProperties().get("dockerImageMetadata")); + ImageInfo info = GSON.fromJson(dockerImageMetadata, ImageInfo.class); + return info; + } } protected String getCheWorkspaceId(CreateContainerParams createContainerParams) {