use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.
the class KubernetesRuntimeStateCacheTest method shouldThrowExceptionUpdateCommands.
@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Runtime state for workspace with id 'non-existent-ws' was not found")
public void shouldThrowExceptionUpdateCommands() throws Exception {
// given
CommandImpl newCommand = new CommandImpl("new", "build", "custom");
// when
runtimesStatesCache.updateCommands(new RuntimeIdentityImpl("non-existent-ws", "defEnv", "acc1", "infraNamespace"), singletonList(newCommand));
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method shouldCreateExecAndViewRolesAndBindings.
@Test
public void shouldCreateExecAndViewRolesAndBindings() throws Exception {
// given
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, Set.of(new WorkspaceServiceAccountConfigurator("serviceAccount", "", clientFactory)), clientFactory, cheClientFactory, userManager, preferenceManager, pool));
KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class);
prepareNamespace(toReturnNamespace);
when(toReturnNamespace.getName()).thenReturn("workspace123");
doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any());
when(k8sClient.supportsApiPath(eq("/apis/metrics.k8s.io"))).thenReturn(true);
when(clientFactory.create(any())).thenReturn(k8sClient);
when(cheClientFactory.create()).thenReturn(k8sClient);
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
namespaceFactory.getOrCreate(identity);
// then
ServiceAccountList sas = k8sClient.serviceAccounts().inNamespace("workspace123").list();
assertEquals(sas.getItems().size(), 1);
assertEquals(sas.getItems().get(0).getMetadata().getName(), "serviceAccount");
RoleList roles = k8sClient.rbac().roles().inNamespace("workspace123").list();
assertEquals(roles.getItems().stream().map(r -> r.getMetadata().getName()).collect(Collectors.toSet()), Sets.newHashSet("workspace-configmaps", "workspace-view", "workspace-metrics", "workspace-secrets", "exec"));
Role role1 = roles.getItems().get(0);
Role role2 = roles.getItems().get(1);
assertFalse(role1.getRules().containsAll(role2.getRules()) && role2.getRules().containsAll(role1.getRules()), "exec and view roles should not be the same");
RoleBindingList bindings = k8sClient.rbac().roleBindings().inNamespace("workspace123").list();
assertEquals(bindings.getItems().stream().map(r -> r.getMetadata().getName()).collect(Collectors.toSet()), Sets.newHashSet("serviceAccount-metrics", "serviceAccount-view", "serviceAccount-exec", "serviceAccount-configmaps", "serviceAccount-secrets"));
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method shouldCreateCredentialsSecretIfNotExists.
@Test
public void shouldCreateCredentialsSecretIfNotExists() throws Exception {
// given
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, Set.of(new CredentialsSecretConfigurator(clientFactory)), clientFactory, cheClientFactory, userManager, preferenceManager, pool));
KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class);
when(toReturnNamespace.getName()).thenReturn("namespaceName");
doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any());
MixedOperation mixedOperation = mock(MixedOperation.class);
when(k8sClient.secrets()).thenReturn(mixedOperation);
when(mixedOperation.inNamespace(anyString())).thenReturn(namespaceOperation);
when(namespaceResource.get()).thenReturn(null);
when(cheClientFactory.create()).thenReturn(k8sClient);
when(clientFactory.create()).thenReturn(k8sClient);
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
namespaceFactory.getOrCreate(identity);
// then
ArgumentCaptor<Secret> secretsCaptor = ArgumentCaptor.forClass(Secret.class);
verify(namespaceOperation).create(secretsCaptor.capture());
Secret secret = secretsCaptor.getValue();
Assert.assertEquals(secret.getMetadata().getName(), CREDENTIALS_SECRET_NAME);
Assert.assertEquals(secret.getType(), "opaque");
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.
the class KubernetesNamespaceFactoryTest method shouldReturnDefaultNamespaceWhenCreatingIsNotIsNotAllowed.
@Test
public void shouldReturnDefaultNamespaceWhenCreatingIsNotIsNotAllowed() throws Exception {
// given
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", false, 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-default");
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 BrokerStatusListenerTest method shouldDoNothingIfEventWithForeignWorkspaceIdIsReceived.
@Test
public void shouldDoNothingIfEventWithForeignWorkspaceIdIsReceived() {
// given
BrokerEvent event = new BrokerEvent().withRuntimeId(new RuntimeIdentityImpl("foreignWorkspace", null, null, null));
// when
brokerStatusListener.onEvent(event);
// then
verifyNoMoreInteractions(brokersResult);
}
Aggregations