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 44ca01a406e9..480e7b1fa2a6 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 @@ -1450,12 +1450,14 @@ private List getVolumeMountsFrom(String[] volumes, String workspace PersistentVolumeClaim pvc = getClaimCheWorkspace(); if (pvc != null) { String subPath = getWorkspaceSubpath(volumes); - VolumeMount vm = new VolumeMountBuilder() + if (subPath != null) { + VolumeMount vm = new VolumeMountBuilder() .withMountPath(cheWorkspaceProjectsStorage) .withName(workspacesPersistentVolumeClaim) .withSubPath(subPath) .build(); - vms.add(vm); + vms.add(vm); + } } return vms; } diff --git a/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/kubernetes/KubernetesLabelConverter.java b/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/kubernetes/KubernetesLabelConverter.java index e499117decd9..f2c4c17cacc0 100644 --- a/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/kubernetes/KubernetesLabelConverter.java +++ b/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/kubernetes/KubernetesLabelConverter.java @@ -64,31 +64,33 @@ public static String getCheServerLabelPrefix() { */ public static Map labelsToNames(Map labels) { Map names = new HashMap<>(); - for (Map.Entry label : labels.entrySet()) { - - if (!hasConversionProblems(label)) { - - String key = label.getKey(); - String value = label.getValue(); - - // Convert keys: e.g. "che:server:4401/tcp:ref" -> - // "che.server.4401-tcp.ref" - key = convertLabelKey(key); - // Convert values: e.g. "/api" -> ".api" -- note values may - // include '-' e.g. "tomcat-debug" - value = convertLabelValue(value); - - // Add padding since DNS names must start and end with - // alphanumeric characters - key = addPadding(key); - value = addPadding(value); - - if (matchesKubernetesLabelRegex(key) && matchesKubernetesLabelRegex(value)) { - names.put(key, value); - } else { - LOG.error( - "Could not convert label {} into Kubernetes annotation: labels must be alphanumeric with ':' and '/'", - label.toString()); + if (labels != null) { + for (Map.Entry label : labels.entrySet()) { + + if (!hasConversionProblems(label)) { + + String key = label.getKey(); + String value = label.getValue(); + + // Convert keys: e.g. "che:server:4401/tcp:ref" -> + // "che.server.4401-tcp.ref" + key = convertLabelKey(key); + // Convert values: e.g. "/api" -> ".api" -- note values may + // include '-' e.g. "tomcat-debug" + value = convertLabelValue(value); + + // Add padding since DNS names must start and end with + // alphanumeric characters + key = addPadding(key); + value = addPadding(value); + + if (matchesKubernetesLabelRegex(key) && matchesKubernetesLabelRegex(value)) { + names.put(key, value); + } else { + LOG.error( + "Could not convert label {} into Kubernetes annotation: labels must be alphanumeric with ':' and '/'", + label.toString()); + } } } } @@ -103,25 +105,27 @@ public static Map labelsToNames(Map labels) { */ public static Map namesToLabels(Map names) { Map labels = new HashMap<>(); - for (Map.Entry entry: names.entrySet()){ - String key = entry.getKey(); - String value = entry.getValue(); - - // Remove padding - Matcher keyMatcher = CHE_SERVER_LABEL_KEY.matcher(key); - Matcher valueMatcher = CHE_SERVER_LABEL_KEY.matcher(value); - if (!keyMatcher.matches() || !valueMatcher.matches()) { - continue; - } - key = keyMatcher.group(1); - value = valueMatcher.group(1); + if (names != null) { + for (Map.Entry entry: names.entrySet()){ + String key = entry.getKey(); + String value = entry.getValue(); + + // Remove padding + Matcher keyMatcher = CHE_SERVER_LABEL_KEY.matcher(key); + Matcher valueMatcher = CHE_SERVER_LABEL_KEY.matcher(value); + if (!keyMatcher.matches() || !valueMatcher.matches()) { + continue; + } + key = keyMatcher.group(1); + value = valueMatcher.group(1); - // Convert key: e.g. "che.server.4401_tcp.ref" -> "che:server:4401/tcp:ref" - key = key.replaceAll("\\.", ":").replaceAll("_", "/"); - // Convert value: e.g. Convert values: e.g. "_api" -> "/api" - value = value.replaceAll("_", "/"); + // Convert key: e.g. "che.server.4401_tcp.ref" -> "che:server:4401/tcp:ref" + key = key.replaceAll("\\.", ":").replaceAll("_", "/"); + // Convert value: e.g. Convert values: e.g. "_api" -> "/api" + value = value.replaceAll("_", "/"); - labels.put(key, value); + labels.put(key, value); + } } return labels; }