From e41994d14cf6f027888149982c9f22b3e9c2e3df Mon Sep 17 00:00:00 2001 From: Sergii Leshchenko Date: Thu, 10 Jan 2019 09:31:55 +0200 Subject: [PATCH] Use meaningful value for plugin broker container name instead of generated one Signed-off-by: Sergii Leshchenko --- .../BrokerEnvironmentFactory.java | 2 +- .../BrokerEnvironmentFactoryTest.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/BrokerEnvironmentFactory.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/BrokerEnvironmentFactory.java index a2cd6adafea..cab7ea5c29c 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/BrokerEnvironmentFactory.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/BrokerEnvironmentFactory.java @@ -170,7 +170,7 @@ private Container newContainer( @Nullable String brokerVolumeName) { final ContainerBuilder cb = new ContainerBuilder() - .withName(generateUniqueName(CONTAINER_NAME_SUFFIX)) + .withName(image.toLowerCase().replaceAll("[^\\d\\w-]", "-")) .withImage(image) .withArgs( "-push-endpoint", diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/BrokerEnvironmentFactoryTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/BrokerEnvironmentFactoryTest.java index 3be066cef90..deaf92f4ce7 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/BrokerEnvironmentFactoryTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/BrokerEnvironmentFactoryTest.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableMap; import io.fabric8.kubernetes.api.model.Container; import io.fabric8.kubernetes.api.model.EnvVar; +import io.fabric8.kubernetes.api.model.PodSpec; import java.util.Collection; import java.util.List; import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity; @@ -121,6 +122,7 @@ public void testInitBrokerContainer() throws Exception { List initContainers = brokersConfigs.pod.getSpec().getInitContainers(); assertEquals(initContainers.size(), 1); Container initContainer = initContainers.get(0); + assertEquals(initContainer.getName(), "init-image"); assertEquals(initContainer.getImage(), INIT_IMAGE); assertEquals(initContainer.getImagePullPolicy(), IMAGE_PULL_POLICY); assertEquals( @@ -139,4 +141,27 @@ public void testInitBrokerContainer() throws Exception { assertEquals(Containers.getRamLimit(initContainer), 262144000); assertEquals(Containers.getRamLimit(initContainer), 262144000); } + + @Test + public void shouldNameContainersAfterPluginBrokerImage() throws Exception { + // given + Collection metas = singletonList(new PluginMeta().type(SUPPORTED_TYPE)); + ArgumentCaptor captor = ArgumentCaptor.forClass(BrokersConfigs.class); + + // when + factory.create(metas, runtimeId, new BrokersResult()); + + // then + verify(factory).doCreate(captor.capture()); + BrokersConfigs brokersConfigs = captor.getValue(); + PodSpec brokerPodSpec = brokersConfigs.pod.getSpec(); + + List initContainers = brokerPodSpec.getInitContainers(); + assertEquals(initContainers.size(), 1); + assertEquals(initContainers.get(0).getName(), "init-image"); + + List containers = brokerPodSpec.getContainers(); + assertEquals(containers.size(), 1); + assertEquals(containers.get(0).getName(), "testrepo-image-tag"); + } }