From 4e50832f8a72d9867d9ed520bf420247d20fff0d Mon Sep 17 00:00:00 2001 From: Sergii Kabashniuk Date: Fri, 23 Jul 2021 15:36:52 +0300 Subject: [PATCH 1/6] feat: REST Service on the Che server-side that will initiate k8s namespace provisioning --- .../server/KubernetesNamespaceService.java | 22 +++++++++++++++++++ .../namespace/KubernetesNamespaceFactory.java | 16 ++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java index 1940a353134..621d70bb9a1 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java @@ -22,10 +22,13 @@ import java.util.stream.Collectors; import javax.inject.Inject; import javax.ws.rs.GET; +import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import org.eclipse.che.api.core.rest.Service; import org.eclipse.che.api.workspace.server.spi.InfrastructureException; +import org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext; +import org.eclipse.che.commons.env.EnvironmentContext; import org.eclipse.che.dto.server.DtoFactory; import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta; import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.dto.KubernetesNamespaceMetaDto; @@ -63,6 +66,25 @@ public List getNamespaces() throws InfrastructureExc return namespaceFactory.list().stream().map(this::asDto).collect(Collectors.toList()); } + @POST + @Path("provision") + @Produces(APPLICATION_JSON) + @ApiOperation( + value = "Provision k8s namespaces where user is able to create workspaces", + notes = + "This operation can be performed only by authorized user." + + "This is under beta and may be significant changed", + response = KubernetesNamespaceMetaDto.class) + @ApiResponses({ + @ApiResponse(code = 200, message = "The namespaces successfully provisioned"), + @ApiResponse(code = 500, message = "Internal server error occurred during namespaces provisioning") + }) + public KubernetesNamespaceMetaDto provision() throws InfrastructureException { + return asDto( + namespaceFactory.provision( + new NamespaceResolutionContext(EnvironmentContext.getCurrent().getSubject()))); + } + private KubernetesNamespaceMetaDto asDto(KubernetesNamespaceMeta kubernetesNamespaceMeta) { return DtoFactory.newDto(KubernetesNamespaceMetaDto.class) .withName(kubernetesNamespaceMeta.getName()) diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java index 5ac78d01d9f..a74ea35c786 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java @@ -50,6 +50,7 @@ import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity; import org.eclipse.che.api.user.server.PreferenceManager; import org.eclipse.che.api.user.server.UserManager; +import org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl; import org.eclipse.che.api.workspace.server.spi.InfrastructureException; import org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext; import org.eclipse.che.commons.annotation.Nullable; @@ -338,6 +339,21 @@ public KubernetesNamespace getOrCreate(RuntimeIdentity identity) throws Infrastr return namespace; } + public KubernetesNamespaceMeta provision(NamespaceResolutionContext namespaceResolutionContext) + throws InfrastructureException { + KubernetesNamespace namespace = + getOrCreate( + new RuntimeIdentityImpl( + "wsid", + "env", + namespaceResolutionContext.getUserId(), + evaluateNamespaceName(namespaceResolutionContext))); + + return fetchNamespace(namespace.getName()) + .orElseThrow( + () -> new InfrastructureException("Not able to find namespace" + namespace.getName())); + } + public KubernetesNamespace get(RuntimeIdentity identity) throws InfrastructureException { String workspaceId = identity.getWorkspaceId(); String namespaceName = identity.getInfrastructureNamespace(); From 491972ee77a2899001e66816869330ce94dfc6ed Mon Sep 17 00:00:00 2001 From: Sergii Kabashniuk Date: Thu, 29 Jul 2021 13:18:53 +0300 Subject: [PATCH 2/6] Add more tests --- .../server/KubernetesNamespaceService.java | 4 +- .../namespace/KubernetesNamespaceFactory.java | 2 +- .../KubernetesNamespaceServiceTest.java | 81 +++++++++++++ .../KubernetesNamespaceFactoryTest.java | 113 ++++++++++++++++++ 4 files changed, 198 insertions(+), 2 deletions(-) diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java index 621d70bb9a1..d5a40f0bd41 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java @@ -77,7 +77,9 @@ public List getNamespaces() throws InfrastructureExc response = KubernetesNamespaceMetaDto.class) @ApiResponses({ @ApiResponse(code = 200, message = "The namespaces successfully provisioned"), - @ApiResponse(code = 500, message = "Internal server error occurred during namespaces provisioning") + @ApiResponse( + code = 500, + message = "Internal server error occurred during namespaces provisioning") }) public KubernetesNamespaceMetaDto provision() throws InfrastructureException { return asDto( diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java index a74ea35c786..63a444f6aed 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java @@ -351,7 +351,7 @@ public KubernetesNamespaceMeta provision(NamespaceResolutionContext namespaceRes return fetchNamespace(namespace.getName()) .orElseThrow( - () -> new InfrastructureException("Not able to find namespace" + namespace.getName())); + () -> new InfrastructureException("Not able to find namespace " + namespace.getName())); } public KubernetesNamespace get(RuntimeIdentity identity) throws InfrastructureException { diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceServiceTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceServiceTest.java index faf373df2d4..9fa5ac97eff 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceServiceTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceServiceTest.java @@ -16,6 +16,7 @@ import static org.everrest.assured.JettyHttpServer.ADMIN_USER_NAME; import static org.everrest.assured.JettyHttpServer.ADMIN_USER_PASSWORD; import static org.everrest.assured.JettyHttpServer.SECURE_PATH; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.testng.Assert.assertEquals; @@ -24,15 +25,25 @@ import com.jayway.restassured.response.Response; import java.util.Collections; import java.util.List; +import org.eclipse.che.api.core.rest.ApiExceptionMapper; import org.eclipse.che.api.core.rest.CheJsonProvider; +import org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext; +import org.eclipse.che.commons.env.EnvironmentContext; +import org.eclipse.che.commons.subject.Subject; +import org.eclipse.che.commons.subject.SubjectImpl; import org.eclipse.che.dto.server.DtoFactory; import org.eclipse.che.workspace.infrastructure.kubernetes.api.server.impls.KubernetesNamespaceMetaImpl; import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.dto.KubernetesNamespaceMetaDto; import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespaceFactory; import org.everrest.assured.EverrestJetty; +import org.everrest.core.Filter; +import org.everrest.core.GenericContainerRequest; +import org.everrest.core.RequestFilter; +import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.testng.MockitoTestNGListener; +import org.testng.Assert; import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -44,6 +55,14 @@ @Listeners(value = {EverrestJetty.class, MockitoTestNGListener.class}) public class KubernetesNamespaceServiceTest { + @SuppressWarnings("unused") + private static final ApiExceptionMapper MAPPER = new ApiExceptionMapper(); + + @SuppressWarnings("unused") + private static final EnvironmentFilter FILTER = new EnvironmentFilter(); + + private static final Subject SUBJECT = new SubjectImpl("john", "id-123", "token", false); + @SuppressWarnings("unused") // is declared for deploying by everrest-assured private CheJsonProvider jsonProvider = new CheJsonProvider(Collections.emptySet()); @@ -73,7 +92,69 @@ public void shouldReturnNamespaces() throws Exception { verify(namespaceFactory).list(); } + @Test + public void shouldProvisionNamespace() throws Exception { + // given + KubernetesNamespaceMetaImpl namespaceMeta = + new KubernetesNamespaceMetaImpl( + "ws-namespace", ImmutableMap.of("phase", "active", "default", "true")); + when(namespaceFactory.provision(any(NamespaceResolutionContext.class))) + .thenReturn(namespaceMeta); + // when + final Response response = + given() + .auth() + .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) + .when() + .post(SECURE_PATH + "/kubernetes/namespace/provision"); + // then + + assertEquals(response.getStatusCode(), 200); + KubernetesNamespaceMetaDto actual = unwrapDto(response, KubernetesNamespaceMetaDto.class); + assertEquals(actual.getName(), namespaceMeta.getName()); + assertEquals(actual.getAttributes(), namespaceMeta.getAttributes()); + verify(namespaceFactory).provision(any(NamespaceResolutionContext.class)); + } + + @Test + public void shouldProvisionNamespaceWithCorrectContext() throws Exception { + // given + KubernetesNamespaceMetaImpl namespaceMeta = + new KubernetesNamespaceMetaImpl( + "ws-namespace", ImmutableMap.of("phase", "active", "default", "true")); + when(namespaceFactory.provision(any(NamespaceResolutionContext.class))) + .thenReturn(namespaceMeta); + // when + final Response response = + given() + .auth() + .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) + .when() + .post(SECURE_PATH + "/kubernetes/namespace/provision"); + // then + + assertEquals(response.getStatusCode(), 200); + ArgumentCaptor captor = + ArgumentCaptor.forClass(NamespaceResolutionContext.class); + verify(namespaceFactory).provision(captor.capture()); + NamespaceResolutionContext actualContext = captor.getValue(); + assertEquals(actualContext.getUserId(), SUBJECT.getUserId()); + assertEquals(actualContext.getUserName(), SUBJECT.getUserName()); + Assert.assertNull(actualContext.getWorkspaceId()); + } + private static List unwrapDtoList(Response response, Class dtoClass) { return DtoFactory.getInstance().createListDtoFromJson(response.body().print(), dtoClass); } + + private static T unwrapDto(Response response, Class dtoClass) { + return DtoFactory.getInstance().createDtoFromJson(response.body().print(), dtoClass); + } + + @Filter + public static class EnvironmentFilter implements RequestFilter { + public void doFilter(GenericContainerRequest request) { + EnvironmentContext.getCurrent().setSubject(SUBJECT); + } + } } diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java index 0cd0e49cef8..0e9f68dde6f 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java @@ -57,6 +57,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -76,6 +77,7 @@ import org.eclipse.che.inject.ConfigurationException; import org.eclipse.che.workspace.infrastructure.kubernetes.CheServerKubernetesClientFactory; import org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesClientFactory; +import org.eclipse.che.workspace.infrastructure.kubernetes.api.server.impls.KubernetesNamespaceMetaImpl; import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta; import org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSharedPool; import org.mockito.ArgumentCaptor; @@ -988,6 +990,117 @@ public void testEvalNamespaceNameWhenPreparedNamespacesFound() throws Infrastruc assertEquals(namespace, "ns1"); } + @Test + public void shouldHandleProvision() throws InfrastructureException { + // given + namespaceFactory = + spy( + new KubernetesNamespaceFactory( + "", + "", + "-che", + false, + true, + NAMESPACE_LABELS, + NAMESPACE_ANNOTATIONS, + clientFactory, + cheClientFactory, + userManager, + preferenceManager, + pool)); + KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class); + when(toReturnNamespace.getName()).thenReturn("jondoe-che"); + doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any()); + KubernetesNamespaceMetaImpl namespaceMeta = + new KubernetesNamespaceMetaImpl( + "jondoe-che", ImmutableMap.of("phase", "active", "default", "true")); + doReturn(Optional.of(namespaceMeta)).when(namespaceFactory).fetchNamespace(eq("jondoe-che")); + + // when + NamespaceResolutionContext context = + new NamespaceResolutionContext("workspace123", "user123", "jondoe"); + KubernetesNamespaceMeta actual = namespaceFactory.provision(context); + + // then + assertEquals(actual, namespaceMeta); + } + + @Test( + expectedExceptions = InfrastructureException.class, + expectedExceptionsMessageRegExp = "Not able to find namespace jondoe-cha-cha-cha") + public void shouldFailToProvisionIfNotAbleToFindNamespace() throws InfrastructureException { + // given + namespaceFactory = + spy( + new KubernetesNamespaceFactory( + "", + "", + "-cha-cha-cha", + false, + true, + NAMESPACE_LABELS, + NAMESPACE_ANNOTATIONS, + clientFactory, + cheClientFactory, + userManager, + preferenceManager, + pool)); + KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class); + when(toReturnNamespace.getName()).thenReturn("jondoe-cha-cha-cha"); + doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any()); + KubernetesNamespaceMetaImpl namespaceMeta = + new KubernetesNamespaceMetaImpl( + "jondoe-cha-cha-cha", ImmutableMap.of("phase", "active", "default", "true")); + doReturn(Optional.empty()).when(namespaceFactory).fetchNamespace(eq("jondoe-cha-cha-cha")); + + // when + NamespaceResolutionContext context = + new NamespaceResolutionContext("workspace123", "user123", "jondoe"); + KubernetesNamespaceMeta actual = namespaceFactory.provision(context); + + // then + assertEquals(actual, namespaceMeta); + } + + @Test( + expectedExceptions = InfrastructureException.class, + expectedExceptionsMessageRegExp = "Error occurred when tried to fetch default namespace") + public void shouldFail2ProvisionIfNotAbleToFindNamespace() throws InfrastructureException { + // given + namespaceFactory = + spy( + new KubernetesNamespaceFactory( + "", + "", + "-cha-cha-cha", + false, + true, + NAMESPACE_LABELS, + NAMESPACE_ANNOTATIONS, + clientFactory, + cheClientFactory, + userManager, + preferenceManager, + pool)); + KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class); + when(toReturnNamespace.getName()).thenReturn("jondoe-cha-cha-cha"); + doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any()); + KubernetesNamespaceMetaImpl namespaceMeta = + new KubernetesNamespaceMetaImpl( + "jondoe-cha-cha-cha", ImmutableMap.of("phase", "active", "default", "true")); + doThrow(new InfrastructureException("Error occurred when tried to fetch default namespace")) + .when(namespaceFactory) + .fetchNamespace(eq("jondoe-cha-cha-cha")); + + // when + NamespaceResolutionContext context = + new NamespaceResolutionContext("workspace123", "user123", "jondoe"); + KubernetesNamespaceMeta actual = namespaceFactory.provision(context); + + // then + assertEquals(actual, namespaceMeta); + } + @Test public void testUsernamePlaceholderInLabelsIsNotEvaluated() throws InfrastructureException { List namespaces = From b8079b2cc19c6b1af49418d061e44fcbb09a5044 Mon Sep 17 00:00:00 2001 From: Sergii Kabashniuk Date: Fri, 30 Jul 2021 12:22:39 +0300 Subject: [PATCH 3/6] fixup! Merge remote-tracking branch 'upstream/main' into che20165 Signed-off-by: Sergii Kabashniuk --- .../api/server/KubernetesNamespaceService.java | 4 ++-- .../namespace/KubernetesNamespaceFactoryTest.java | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java index d5a40f0bd41..f0d6b3af104 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java @@ -72,8 +72,8 @@ public List getNamespaces() throws InfrastructureExc @ApiOperation( value = "Provision k8s namespaces where user is able to create workspaces", notes = - "This operation can be performed only by authorized user." - + "This is under beta and may be significant changed", + "This operation can be performed only by an authorized user." + + " This is a beta feature that may be significantly changed.", response = KubernetesNamespaceMetaDto.class) @ApiResponses({ @ApiResponse(code = 200, message = "The namespaces successfully provisioned"), diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java index 0e9f68dde6f..aacfe08d773 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java @@ -1022,7 +1022,8 @@ public void shouldHandleProvision() throws InfrastructureException { KubernetesNamespaceMeta actual = namespaceFactory.provision(context); // then - assertEquals(actual, namespaceMeta); + assertEquals(actual.getName(), "jondoe-che"); + assertEquals(actual.getAttributes(), ImmutableMap.of("phase", "active", "default", "true")); } @Test( @@ -1059,7 +1060,8 @@ public void shouldFailToProvisionIfNotAbleToFindNamespace() throws Infrastructur KubernetesNamespaceMeta actual = namespaceFactory.provision(context); // then - assertEquals(actual, namespaceMeta); + assertEquals(actual.getName(), "jondoe-cha-cha-cha"); + assertEquals(actual.getAttributes(), ImmutableMap.of("phase", "active", "default", "true")); } @Test( @@ -1098,7 +1100,8 @@ public void shouldFail2ProvisionIfNotAbleToFindNamespace() throws Infrastructure KubernetesNamespaceMeta actual = namespaceFactory.provision(context); // then - assertEquals(actual, namespaceMeta); + assertEquals(actual.getName(), "jondoe-cha-cha-cha"); + assertEquals(actual.getAttributes(), ImmutableMap.of("phase", "active", "default", "true")); } @Test From a89b6a80bd06ecd5bc226bca0c6090541d44d76e Mon Sep 17 00:00:00 2001 From: Sergii Kabashniuk Date: Fri, 30 Jul 2021 13:27:12 +0300 Subject: [PATCH 4/6] fixup! Merge remote-tracking branch 'upstream/main' into che20165 Signed-off-by: Sergii Kabashniuk --- .../kubernetes/namespace/KubernetesNamespaceFactory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java index 63a444f6aed..61da8059e4d 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java @@ -344,8 +344,8 @@ public KubernetesNamespaceMeta provision(NamespaceResolutionContext namespaceRes KubernetesNamespace namespace = getOrCreate( new RuntimeIdentityImpl( - "wsid", - "env", + null, + null, namespaceResolutionContext.getUserId(), evaluateNamespaceName(namespaceResolutionContext))); From cbfd3181db281a78122aa078214d13d390040f36 Mon Sep 17 00:00:00 2001 From: Sergii Kabashniuk Date: Fri, 30 Jul 2021 14:17:13 +0300 Subject: [PATCH 5/6] fixup! fixup! Merge remote-tracking branch 'upstream/main' into che20165 Signed-off-by: Sergii Kabashniuk --- .../namespace/KubernetesNamespaceFactoryTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java index aacfe08d773..8fbc849d664 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java @@ -33,6 +33,7 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; import ch.qos.logback.classic.spi.LoggingEvent; import ch.qos.logback.core.Appender; @@ -1057,11 +1058,10 @@ public void shouldFailToProvisionIfNotAbleToFindNamespace() throws Infrastructur // when NamespaceResolutionContext context = new NamespaceResolutionContext("workspace123", "user123", "jondoe"); - KubernetesNamespaceMeta actual = namespaceFactory.provision(context); + namespaceFactory.provision(context); // then - assertEquals(actual.getName(), "jondoe-cha-cha-cha"); - assertEquals(actual.getAttributes(), ImmutableMap.of("phase", "active", "default", "true")); + fail("should not reach this point since exception has to be thrown"); } @Test( @@ -1097,11 +1097,10 @@ public void shouldFail2ProvisionIfNotAbleToFindNamespace() throws Infrastructure // when NamespaceResolutionContext context = new NamespaceResolutionContext("workspace123", "user123", "jondoe"); - KubernetesNamespaceMeta actual = namespaceFactory.provision(context); + namespaceFactory.provision(context); // then - assertEquals(actual.getName(), "jondoe-cha-cha-cha"); - assertEquals(actual.getAttributes(), ImmutableMap.of("phase", "active", "default", "true")); + fail("should not reach this point since exception has to be thrown"); } @Test From f969ee74dd595baa8d2a7b683692b12cf5747bc7 Mon Sep 17 00:00:00 2001 From: Sergii Kabashniuk Date: Mon, 2 Aug 2021 13:15:50 +0300 Subject: [PATCH 6/6] fixup! fixup! fixup! Merge remote-tracking branch 'upstream/main' into che20165 Signed-off-by: Sergii Kabashniuk --- .../kubernetes/api/server/KubernetesNamespaceService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java index f0d6b3af104..fd19ca736cf 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java @@ -70,16 +70,16 @@ public List getNamespaces() throws InfrastructureExc @Path("provision") @Produces(APPLICATION_JSON) @ApiOperation( - value = "Provision k8s namespaces where user is able to create workspaces", + value = "Provision k8s namespace where user is able to create workspaces", notes = "This operation can be performed only by an authorized user." + " This is a beta feature that may be significantly changed.", response = KubernetesNamespaceMetaDto.class) @ApiResponses({ - @ApiResponse(code = 200, message = "The namespaces successfully provisioned"), + @ApiResponse(code = 200, message = "The namespace successfully provisioned"), @ApiResponse( code = 500, - message = "Internal server error occurred during namespaces provisioning") + message = "Internal server error occurred during namespace provisioning") }) public KubernetesNamespaceMetaDto provision() throws InfrastructureException { return asDto(