use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method testUsernamePlaceholderInAnnotationsIsEvaluated.
@Test
public void testUsernamePlaceholderInAnnotationsIsEvaluated() throws InfrastructureException {
// given
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, "try_placeholder_here=<username>", emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool));
EnvironmentContext.getCurrent().setSubject(new SubjectImpl("jondoe", "123", null, false));
KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class);
prepareNamespace(toReturnNamespace);
doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any());
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "old-che");
KubernetesNamespace namespace = namespaceFactory.getOrCreate(identity);
// then
assertEquals(toReturnNamespace, namespace);
verify(toReturnNamespace).prepare(eq(false), any(), eq(Map.of("try_placeholder_here", "jondoe")));
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method shouldPrepareWorkspaceServiceAccountIfItIsConfiguredAndNamespaceIsNotPredefined.
@Test
public void shouldPrepareWorkspaceServiceAccountIfItIsConfiguredAndNamespaceIsNotPredefined() throws Exception {
// given
var serviceAccountCfg = spy(new WorkspaceServiceAccountConfigurator("serviceAccount", "", clientFactory));
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, Set.of(serviceAccountCfg), clientFactory, cheClientFactory, userManager, preferenceManager, pool));
KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class);
prepareNamespace(toReturnNamespace);
when(toReturnNamespace.getName()).thenReturn("workspace123");
doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any());
KubernetesWorkspaceServiceAccount serviceAccount = mock(KubernetesWorkspaceServiceAccount.class);
doReturn(serviceAccount).when(serviceAccountCfg).doCreateServiceAccount(any(), any());
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
namespaceFactory.getOrCreate(identity);
// then
verify(serviceAccountCfg).doCreateServiceAccount("workspace123", "workspace123");
verify(serviceAccount).prepare();
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method shouldRequireNamespacePriorExistenceIfDifferentFromDefaultAndUserDefinedIsNotAllowed.
@Test
public void shouldRequireNamespacePriorExistenceIfDifferentFromDefaultAndUserDefinedIsNotAllowed() throws Exception {
// There is only one scenario where this can happen. The workspace was created and started in
// some default namespace. Then server was reconfigured to use a different default namespace
// AND the namespace of the workspace was MANUALLY deleted in the cluster. In this case, we
// should NOT try to re-create the namespace because it would be created in a namespace that
// is not configured. We DO allow it to start if the namespace still exists though.
// given
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool));
KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class);
prepareNamespace(toReturnNamespace);
doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any());
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "old-che");
KubernetesNamespace namespace = namespaceFactory.getOrCreate(identity);
// then
assertEquals(toReturnNamespace, namespace);
verify(toReturnNamespace).prepare(eq(false), any(), any());
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method shouldNotCreatePreferencesConfigmapIfExists.
@Test
public void shouldNotCreatePreferencesConfigmapIfExists() throws Exception {
// given
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool));
KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class);
prepareNamespace(toReturnNamespace);
doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any());
MixedOperation mixedOperation = mock(MixedOperation.class);
lenient().when(k8sClient.configMaps()).thenReturn(mixedOperation);
lenient().when(mixedOperation.inNamespace(anyString())).thenReturn(namespaceOperation);
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
namespaceFactory.getOrCreate(identity);
// then
verify(namespaceOperation, never()).create(any());
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method shouldNotCreateCredentialsSecretIfExists.
@Test
public void shouldNotCreateCredentialsSecretIfExists() throws Exception {
// given
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool));
KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class);
prepareNamespace(toReturnNamespace);
doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any());
MixedOperation mixedOperation = mock(MixedOperation.class);
lenient().when(k8sClient.secrets()).thenReturn(mixedOperation);
lenient().when(mixedOperation.inNamespace(anyString())).thenReturn(namespaceOperation);
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
namespaceFactory.getOrCreate(identity);
// then
verify(namespaceOperation, never()).create(any());
}
Aggregations