Skip to content

Commit

Permalink
cleanup before workspace start (#16498)
Browse files Browse the repository at this point in the history
* cleanup before workspace start

Signed-off-by: Michal Vala <mvala@redhat.com>

* fix and add tests

Signed-off-by: Michal Vala <mvala@redhat.com>

* test that cleanup is done first, before workspace deployment

Signed-off-by: Michal Vala <mvala@redhat.com>
  • Loading branch information
sparkoo committed Apr 1, 2020
1 parent 9d2b189 commit 983d0a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ protected void internalStart(Map<String, String> startOptions) throws Infrastruc
startSynchronizer.setStartThread();
startSynchronizer.start();

namespace.cleanUp();

// Tooling side car provisioner should be applied before other provisioners
// because new machines may be provisioned there
toolingProvisioner.provision(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
import org.testng.annotations.BeforeMethod;
Expand Down Expand Up @@ -410,6 +412,7 @@ public void startsKubernetesEnvironment() throws Exception {
verify(services).create(any());
verify(secrets).create(any());
verify(configMaps).create(any());
verify(namespace).cleanUp();
verify(namespace.deployments(), times(1)).watchEvents(any());
verify(eventService, times(4)).publish(any());
verifyOrderedEventsChains(
Expand All @@ -421,6 +424,19 @@ public void startsKubernetesEnvironment() throws Exception {
verify(namespace.deployments(), times(1)).stopWatch();
}

@Test
public void testCleanupHappensFirst() throws InfrastructureException {
internalRuntime.start(emptyMap());

InOrder cleanupInOrderExecutionVerification =
Mockito.inOrder(namespace, deployments, toolingProvisioner);
cleanupInOrderExecutionVerification.verify(namespace).cleanUp();
cleanupInOrderExecutionVerification
.verify(toolingProvisioner)
.provision(any(), any(), any(), any());
cleanupInOrderExecutionVerification.verify(deployments).deploy(any(Pod.class));
}

@Test
public void startKubernetesEnvironmentWithDeploymentsInsteadOfPods() throws Exception {
when(k8sEnv.getPodsCopy()).thenReturn(emptyMap());
Expand Down Expand Up @@ -617,7 +633,7 @@ public void throwsInternalInfrastructureExceptionWhenRuntimeErrorOccurs() throws
try {
internalRuntime.start(emptyMap());
} catch (Exception rethrow) {
verify(namespace).cleanUp();
verify(namespace, times(2)).cleanUp();
verify(namespace, never()).services();
verify(namespace, never()).ingresses();
throw rethrow;
Expand Down Expand Up @@ -663,7 +679,7 @@ public void throwsInfrastructureExceptionWhenErrorOccursAndCleanupFailed() throw
try {
internalRuntime.start(emptyMap());
} catch (Exception rethrow) {
verify(namespace).cleanUp();
verify(namespace, times(2)).cleanUp();
verify(namespace).services();
verify(namespace, never()).ingresses();
throw rethrow;
Expand Down

0 comments on commit 983d0a5

Please sign in to comment.