use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.
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));
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method testEvalNamespaceKubeAdmin.
@Test
public void testEvalNamespaceKubeAdmin() throws Exception {
namespaceFactory = spy(new KubernetesNamespaceFactory("che-<username>", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool));
doReturn(empty()).when(namespaceFactory).fetchNamespace(anyString());
String namespace = namespaceFactory.evaluateNamespaceName(new NamespaceResolutionContext("workspace123", "kube:admin", "kube:admin"));
assertTrue(namespace.startsWith("che-kube-admin-"));
assertEquals(namespace.length(), 21);
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method testEvalNamespaceSkipsNamespaceFromUserPreferencesIfUserAllowedPropertySetFalse.
@Test
public void testEvalNamespaceSkipsNamespaceFromUserPreferencesIfUserAllowedPropertySetFalse() throws Exception {
namespaceFactory = new KubernetesNamespaceFactory("che-<userid>-<username>", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool);
Map<String, String> prefs = new HashMap<>();
// returned but ignored
prefs.put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, "che-123");
prefs.put(NAMESPACE_TEMPLATE_ATTRIBUTE, "che-<userid>");
when(preferenceManager.find(anyString())).thenReturn(prefs);
String namespace = namespaceFactory.evaluateNamespaceName(new NamespaceResolutionContext("workspace123", "user123", "jondoe"));
assertEquals(namespace, "che-user123-jondoe");
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method testEvalNamespaceNameWhenPreparedNamespacesFound.
@Test
public void testEvalNamespaceNameWhenPreparedNamespacesFound() throws InfrastructureException {
List<Namespace> namespaces = Arrays.asList(new NamespaceBuilder().withNewMetadata().withName("ns1").withAnnotations(Map.of(NAMESPACE_ANNOTATION_NAME, "jondoe")).endMetadata().withNewStatus().withNewPhase("Active").endStatus().build(), new NamespaceBuilder().withNewMetadata().withName("ns2").withAnnotations(Map.of(NAMESPACE_ANNOTATION_NAME, "jondoe")).endMetadata().withNewStatus().withNewPhase("Active").endStatus().build());
doReturn(namespaces).when(namespaceList).getItems();
namespaceFactory = new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool);
String namespace = namespaceFactory.evaluateNamespaceName(new NamespaceResolutionContext("workspace123", "user123", "jondoe"));
assertEquals(namespace, "ns1");
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method testAllConfiguratorsAreCalledWhenCreatingNamespace.
@Test
public void testAllConfiguratorsAreCalledWhenCreatingNamespace() throws InfrastructureException {
// given
String namespaceName = "testNamespaceName";
NamespaceConfigurator configurator1 = Mockito.mock(NamespaceConfigurator.class);
NamespaceConfigurator configurator2 = Mockito.mock(NamespaceConfigurator.class);
Set<NamespaceConfigurator> namespaceConfigurators = Set.of(configurator1, configurator2);
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, namespaceConfigurators, clientFactory, cheClientFactory, userManager, preferenceManager, pool));
EnvironmentContext.getCurrent().setSubject(new SubjectImpl("jondoe", "123", null, false));
KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class);
when(toReturnNamespace.getName()).thenReturn(namespaceName);
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "old-che");
doReturn(toReturnNamespace).when(namespaceFactory).get(identity);
// when
KubernetesNamespace namespace = namespaceFactory.getOrCreate(identity);
// then
NamespaceResolutionContext resolutionCtx = new NamespaceResolutionContext("workspace123", "123", "jondoe");
verify(configurator1).configure(resolutionCtx, namespaceName);
verify(configurator2).configure(resolutionCtx, namespaceName);
assertEquals(namespace, toReturnNamespace);
}
Aggregations