Search in sources :

Example 41 with KubernetesNamespaceMeta

use of org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta in project devspaces-images by redhat-developer.

the class OpenShiftProjectFactoryTest method shouldReturnPreparedNamespacesWhenFound.

@Test
public void shouldReturnPreparedNamespacesWhenFound() throws InfrastructureException {
    // given
    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);
    EnvironmentContext.getCurrent().setSubject(new SubjectImpl("jondoe", "123", null, false));
    // when
    List<KubernetesNamespaceMeta> availableNamespaces = projectFactory.list();
    // then
    assertEquals(availableNamespaces.size(), 2);
    assertEquals(availableNamespaces.get(0).getName(), "ns1");
    assertEquals(availableNamespaces.get(1).getName(), "ns2");
}
Also used : Project(io.fabric8.openshift.api.model.Project) KubernetesNamespaceMeta(org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Test(org.testng.annotations.Test)

Example 42 with KubernetesNamespaceMeta

use of org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta in project devspaces-images by redhat-developer.

the class OpenShiftProjectFactoryTest method shouldReturnDefaultProjectWhenItDoesNotExistAndUserDefinedIsNotAllowed.

@Test
public void shouldReturnDefaultProjectWhenItDoesNotExistAndUserDefinedIsNotAllowed() throws Exception {
    throwOnTryToGetProjectByName(USER_NAME + "-che", new KubernetesClientException("forbidden", 403, null));
    projectFactory = new OpenShiftProjectFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, true, emptySet(), clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, userManager, preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER);
    List<KubernetesNamespaceMeta> availableNamespaces = projectFactory.list();
    assertEquals(availableNamespaces.size(), 1);
    KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(0);
    assertEquals(defaultNamespace.getName(), USER_NAME + "-che");
    assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true");
    assertNull(defaultNamespace.getAttributes().get(// no phase - means such project does not exist
    PHASE_ATTRIBUTE));
}
Also used : KubernetesNamespaceMeta(org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) Test(org.testng.annotations.Test)

Aggregations

KubernetesNamespaceMeta (org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta)42 Test (org.testng.annotations.Test)34 KubernetesNamespaceMetaImpl (org.eclipse.che.workspace.infrastructure.kubernetes.api.server.impls.KubernetesNamespaceMetaImpl)20 Secret (io.fabric8.kubernetes.api.model.Secret)18 PersonalAccessToken (org.eclipse.che.api.factory.server.scm.PersonalAccessToken)18 SubjectImpl (org.eclipse.che.commons.subject.SubjectImpl)16 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)10 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)10 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)10 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 KubernetesNamespace (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace)8 KubernetesSecrets (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesSecrets)8 NamespaceBuilder (io.fabric8.kubernetes.api.model.NamespaceBuilder)6 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)6 NamespaceResolutionContext (org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext)6 Namespace (io.fabric8.kubernetes.api.model.Namespace)4 Status (io.fabric8.kubernetes.api.model.Status)4 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)4 Project (io.fabric8.openshift.api.model.Project)3 SecretList (io.fabric8.kubernetes.api.model.SecretList)2