Search in sources :

Example 16 with NamespaceResolutionContext

use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project devspaces-images by redhat-developer.

the class WorkspaceServiceAccountConfiguratorTest method setUp.

@BeforeMethod
public void setUp() throws InfrastructureException {
    configurator = spy(new WorkspaceServiceAccountConfigurator(TEST_SERVICE_ACCOUNT, TEST_CLUSTER_ROLES, clientFactory));
    // when(configurator.doCreateServiceAccount(TEST_WORKSPACE_ID,
    // TEST_NAMESPACE_NAME)).thenReturn(kubeWSA);
    serverMock = new KubernetesServer(true, true);
    serverMock.before();
    client = spy(serverMock.getClient());
    lenient().when(clientFactory.create(TEST_WORKSPACE_ID)).thenReturn(client);
    namespaceResolutionContext = new NamespaceResolutionContext(TEST_WORKSPACE_ID, TEST_USER_ID, TEST_USERNAME);
}
Also used : NamespaceResolutionContext(org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext) KubernetesServer(io.fabric8.kubernetes.client.server.mock.KubernetesServer) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 17 with NamespaceResolutionContext

use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project devspaces-images by redhat-developer.

the class OpenShiftProjectFactoryTest method testEvalNamespaceNameWhenPreparedNamespacesFound.

@Test
public void testEvalNamespaceNameWhenPreparedNamespacesFound() throws InfrastructureException {
    List<Project> projects = Arrays.asList(createProject("ns1", "project1", "desc1", "Active", Map.of(NAMESPACE_ANNOTATION_NAME, "jondoe")), createProject("ns3", "project3", "desc3", "Active", Map.of(NAMESPACE_ANNOTATION_NAME, "some_other_user")), createProject("ns2", "project2", "desc2", "Active", Map.of(NAMESPACE_ANNOTATION_NAME, "jondoe")));
    doReturn(projects).when(projectList).getItems();
    projectFactory = new OpenShiftProjectFactory("<userid>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, true, emptySet(), clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, userManager, preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER);
    String namespace = projectFactory.evaluateNamespaceName(new NamespaceResolutionContext("workspace123", "user123", "jondoe"));
    assertEquals(namespace, "ns1");
}
Also used : NamespaceResolutionContext(org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext) Project(io.fabric8.openshift.api.model.Project) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 18 with NamespaceResolutionContext

use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project devspaces-images by redhat-developer.

the class OpenShiftProjectFactoryTest method testAllConfiguratorsAreCalledWhenCreatingProject.

@Test
public void testAllConfiguratorsAreCalledWhenCreatingProject() throws InfrastructureException {
    // given
    String projectName = "testprojectname";
    NamespaceConfigurator configurator1 = Mockito.mock(NamespaceConfigurator.class);
    NamespaceConfigurator configurator2 = Mockito.mock(NamespaceConfigurator.class);
    Set<NamespaceConfigurator> namespaceConfigurators = Set.of(configurator1, configurator2);
    projectFactory = spy(new OpenShiftProjectFactory("<username>-che", true, true, true, NAMESPACE_LABELS, "try_placeholder_here=<username>", true, namespaceConfigurators, clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, userManager, preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER));
    EnvironmentContext.getCurrent().setSubject(new SubjectImpl("jondoe", "123", null, false));
    OpenShiftProject toReturnProject = mock(OpenShiftProject.class);
    when(toReturnProject.getName()).thenReturn(projectName);
    RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "old-che");
    doReturn(toReturnProject).when(projectFactory).get(identity);
    // when
    OpenShiftProject project = projectFactory.getOrCreate(identity);
    // then
    NamespaceResolutionContext resolutionCtx = new NamespaceResolutionContext("workspace123", "123", "jondoe");
    verify(configurator1).configure(resolutionCtx, projectName);
    verify(configurator2).configure(resolutionCtx, projectName);
    assertEquals(project, toReturnProject);
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) NamespaceResolutionContext(org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext) NamespaceConfigurator(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.NamespaceConfigurator) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 19 with NamespaceResolutionContext

use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project devspaces-images by redhat-developer.

the class WorkspaceManagerTest method evaluatesLegacyInfraNamespaceIfMissingOnWorkspaceStart.

@Test
public void evaluatesLegacyInfraNamespaceIfMissingOnWorkspaceStart() throws Exception {
    DevfileImpl devfile = mock(DevfileImpl.class);
    WorkspaceImpl workspace = createAndMockWorkspace(devfile, NAMESPACE_1, new HashMap<>());
    workspace.getAttributes().remove(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
    when(runtimes.evalInfrastructureNamespace(any())).thenReturn("evaluated-legacy");
    mockAnyWorkspaceStart();
    workspaceManager.startWorkspace(workspace.getId(), null, emptyMap());
    verify(runtimes).startAsync(eq(workspace), eq(null), anyMap());
    verify(workspaceDao, times(2)).update(workspaceCaptor.capture());
    assertEquals(workspaceCaptor.getAllValues().get(0).getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE), "evaluated-legacy");
    verify(runtimes).evalInfrastructureNamespace(new NamespaceResolutionContext(workspace.getId(), USER_ID, NAMESPACE_1));
}
Also used : NamespaceResolutionContext(org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Test(org.testng.annotations.Test)

Example 20 with NamespaceResolutionContext

use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project devspaces-images by redhat-developer.

the class WorkspaceManagerTest method evaluatesInfraNamespaceIfMissingOnWorkspaceCreation.

@Test
public void evaluatesInfraNamespaceIfMissingOnWorkspaceCreation() throws Exception {
    when(runtimes.evalInfrastructureNamespace(any())).thenReturn("evaluated");
    final WorkspaceConfig cfg = createConfig();
    final WorkspaceImpl workspace = workspaceManager.createWorkspace(cfg, NAMESPACE_1, null);
    assertNotNull(workspace);
    assertNotNull(workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE), "evaluated");
    verify(workspaceDao).create(workspace);
    verify(runtimes).evalInfrastructureNamespace(new NamespaceResolutionContext(workspace.getId(), USER_ID, NAMESPACE_1));
}
Also used : NamespaceResolutionContext(org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceConfig(org.eclipse.che.api.core.model.workspace.WorkspaceConfig) Test(org.testng.annotations.Test)

Aggregations

NamespaceResolutionContext (org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext)56 Test (org.testng.annotations.Test)30 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 KubernetesServer (io.fabric8.kubernetes.client.server.mock.KubernetesServer)14 BeforeMethod (org.testng.annotations.BeforeMethod)14 HashMap (java.util.HashMap)8 KubernetesNamespaceMetaImpl (org.eclipse.che.workspace.infrastructure.kubernetes.api.server.impls.KubernetesNamespaceMetaImpl)8 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)6 KubernetesNamespaceMeta (org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta)6 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)4 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)4 RuntimeIdentityImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl)4 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)4 SubjectImpl (org.eclipse.che.commons.subject.SubjectImpl)4 NamespaceConfigurator (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.NamespaceConfigurator)4 Namespace (io.fabric8.kubernetes.api.model.Namespace)2 NamespaceBuilder (io.fabric8.kubernetes.api.model.NamespaceBuilder)2 Project (io.fabric8.openshift.api.model.Project)2