Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add creation of k8s secrets during deploying of broker #13546

Merged
merged 1 commit into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,6 +86,10 @@ public List<ChePlugin> 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()) {
Expand Down Expand Up @@ -112,6 +117,11 @@ public List<ChePlugin> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down