From d9a79e11f25fc0e9acd5706d4d8075ca8512b402 Mon Sep 17 00:00:00 2001 From: Olivier Sallou Date: Thu, 9 Nov 2017 15:12:38 +0100 Subject: [PATCH] If workspace base image does not have labels, skip merge of image labels (#7252) * If image does not have labels, skip merge Relates to #7249 If image does not have labels in config, the merge fails with nullpointerexception. This patch does the merge only if labels!=null Signed-off-by: Olivier Sallou --- .../traefik/TraefikCreateContainerInterceptor.java | 5 ++++- .../traefik/TraefikCreateContainerInterceptorTest.java | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/plugin-traefik/plugin-traefik-docker/src/main/java/org/eclipse/che/plugin/traefik/TraefikCreateContainerInterceptor.java b/plugins/plugin-traefik/plugin-traefik-docker/src/main/java/org/eclipse/che/plugin/traefik/TraefikCreateContainerInterceptor.java index 86552421f71..657a48ce2e5 100644 --- a/plugins/plugin-traefik/plugin-traefik-docker/src/main/java/org/eclipse/che/plugin/traefik/TraefikCreateContainerInterceptor.java +++ b/plugins/plugin-traefik/plugin-traefik-docker/src/main/java/org/eclipse/che/plugin/traefik/TraefikCreateContainerInterceptor.java @@ -86,7 +86,10 @@ public Object invoke(MethodInvocation methodInvocation) throws Throwable { // Now merge all labels final Map allLabels = new HashMap<>(containerLabels); - allLabels.putAll(imageLabels); + if (imageLabels != null) { + // If image has some labels, merge them + allLabels.putAll(imageLabels); + } // Get all ports exposed by the container and by the image // it is under the form "22/tcp" diff --git a/plugins/plugin-traefik/plugin-traefik-docker/src/test/java/org/eclipse/che/plugin/traefik/TraefikCreateContainerInterceptorTest.java b/plugins/plugin-traefik/plugin-traefik-docker/src/test/java/org/eclipse/che/plugin/traefik/TraefikCreateContainerInterceptorTest.java index 329c9bf1808..afe67cd2b47 100644 --- a/plugins/plugin-traefik/plugin-traefik-docker/src/test/java/org/eclipse/che/plugin/traefik/TraefikCreateContainerInterceptorTest.java +++ b/plugins/plugin-traefik/plugin-traefik-docker/src/test/java/org/eclipse/che/plugin/traefik/TraefikCreateContainerInterceptorTest.java @@ -114,6 +114,16 @@ protected void setup() throws Exception { when(imageInfoConfig.getEnv()).thenReturn(envImageConfig); } + @Test + public void testRulesWithNullImageLabels() throws Throwable { + when(imageInfoConfig.getLabels()).thenReturn(null); + containerLabels.put("foo1", "bar"); + + traefikCreateContainerInterceptor.invoke(methodInvocation); + + Assert.assertFalse(containerLabels.containsKey("traefik.service-tomcat8.frontend.rule")); + } + @Test public void testRules() throws Throwable { containerLabels.put("foo1", "bar");