From 5a4c0ee9e4f59e4b45655022205a27eee7804ba8 Mon Sep 17 00:00:00 2001 From: Sergii Leshchenko Date: Fri, 14 Jun 2019 15:59:46 +0300 Subject: [PATCH] Add creation of k8s secrets during deploying of broker Signed-off-by: Sergii Leshchenko --- .../wsplugins/brokerphases/DeployBroker.java | 10 ++++++++++ .../wsplugins/brokerphases/DeployBrokerTest.java | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/DeployBroker.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/DeployBroker.java index 4452a7ce7f1..92b07f049eb 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/DeployBroker.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/DeployBroker.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableSet; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.api.model.Secret; import io.opentracing.Span; import io.opentracing.Tracer; import java.util.List; @@ -85,6 +86,10 @@ public List execute() throws InfrastructureException { namespace.configMaps().create(configMap); } + for (Secret secret : brokerEnvironment.getSecrets().values()) { + namespace.secrets().create(secret); + } + Pod pluginBrokerPod = getPluginBrokerPod(brokerEnvironment.getPodsCopy()); if (factory.isConfigured()) { @@ -112,6 +117,11 @@ public List execute() throws InfrastructureException { } catch (InfrastructureException e) { LOG.error("Brokers pod removal failed. Error: " + e.getLocalizedMessage(), e); } + try { + namespace.secrets().delete(); + } catch (InfrastructureException ex) { + LOG.error("Brokers secret removal failed. Error: " + ex.getLocalizedMessage(), ex); + } try { namespace.configMaps().delete(); } catch (InfrastructureException ex) { diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/DeployBrokerTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/DeployBrokerTest.java index 77637d5d1be..08d0db1a647 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/DeployBrokerTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/brokerphases/DeployBrokerTest.java @@ -26,6 +26,7 @@ import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.PodBuilder; +import io.fabric8.kubernetes.api.model.Secret; import io.opentracing.Tracer; import java.util.List; import java.util.Set; @@ -35,6 +36,7 @@ import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesConfigsMaps; import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesDeployments; import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace; +import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesSecrets; import org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListener; import org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListenerFactory; import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.BrokersResult; @@ -59,9 +61,11 @@ public class DeployBrokerTest { @Mock private KubernetesNamespace k8sNamespace; @Mock private KubernetesDeployments k8sDeployments; @Mock private KubernetesConfigsMaps k8sConfigMaps; + @Mock private KubernetesSecrets k8sSecrets; @Mock private KubernetesEnvironment k8sEnvironment; @Mock private ConfigMap configMap; + @Mock private Secret tlsSecret; private Pod pod; @Mock private BrokersResult brokersResult; @@ -90,10 +94,12 @@ public void setUp() throws Exception { when(k8sNamespace.configMaps()).thenReturn(k8sConfigMaps); when(k8sNamespace.deployments()).thenReturn(k8sDeployments); + when(k8sNamespace.secrets()).thenReturn(k8sSecrets); pod = new PodBuilder().withNewMetadata().withName(PLUGIN_BROKER_POD_NAME).endMetadata().build(); when(k8sEnvironment.getPodsCopy()).thenReturn(ImmutableMap.of(PLUGIN_BROKER_POD_NAME, pod)); when(k8sEnvironment.getConfigMaps()).thenReturn(ImmutableMap.of("configMap", configMap)); + when(k8sEnvironment.getSecrets()).thenReturn(ImmutableMap.of("secret", tlsSecret)); when(k8sDeployments.create(any())).thenReturn(pod); } @@ -107,10 +113,12 @@ public void shouldDeployPluginBrokerEnvironment() throws Exception { assertSame(result, plugins); verify(k8sConfigMaps).create(configMap); verify(k8sDeployments).create(pod); + verify(k8sSecrets).create(tlsSecret); verify(k8sDeployments).stopWatch(); verify(k8sDeployments).delete(); verify(k8sConfigMaps).delete(); + verify(k8sSecrets).delete(); } @Test