use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class KubernetesNamespaceFactoryTest method shouldCreatePreferencesConfigmapIfNotExists.
@Test
public void shouldCreatePreferencesConfigmapIfNotExists() throws Exception {
// given
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, Set.of(new PreferencesConfigMapConfigurator(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.configMaps()).thenReturn(mixedOperation);
when(mixedOperation.inNamespace(anyString())).thenReturn(namespaceOperation);
when(namespaceResource.get()).thenReturn(null);
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
namespaceFactory.getOrCreate(identity);
// then
ArgumentCaptor<ConfigMap> configMapCaptor = ArgumentCaptor.forClass(ConfigMap.class);
verify(namespaceOperation).create(configMapCaptor.capture());
ConfigMap configmap = configMapCaptor.getValue();
Assert.assertEquals(configmap.getMetadata().getName(), PREFERENCES_CONFIGMAP_NAME);
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class KubernetesNamespaceFactoryTest method shouldCreateAndBindCredentialsSecretRole.
@Test
public void shouldCreateAndBindCredentialsSecretRole() throws Exception {
// given
var serviceAccountConfigurator = new WorkspaceServiceAccountConfigurator("serviceAccount", "cr2, cr3", clientFactory);
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, Set.of(serviceAccountConfigurator), 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(clientFactory.create(any())).thenReturn(k8sClient);
when(cheClientFactory.create()).thenReturn(k8sClient);
// when
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
namespaceFactory.getOrCreate(identity);
// then
Optional<Role> roleOptional = k8sClient.rbac().roles().inNamespace("workspace123").list().getItems().stream().filter(r -> r.getMetadata().getName().equals(SECRETS_ROLE_NAME)).findAny();
assertTrue(roleOptional.isPresent());
PolicyRule rule = roleOptional.get().getRules().get(0);
assertEquals(rule.getResources(), singletonList("secrets"));
assertEquals(rule.getResourceNames(), singletonList(CREDENTIALS_SECRET_NAME));
assertEquals(rule.getApiGroups(), singletonList(""));
assertEquals(rule.getVerbs(), Arrays.asList("get", "patch"));
assertTrue(k8sClient.rbac().roleBindings().inNamespace("workspace123").list().getItems().stream().anyMatch(rb -> rb.getMetadata().getName().equals("serviceAccount-secrets")));
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class StartSynchronizerTest method shouldNotHaveAnyEventSubscribersBeforeStart.
@Test
public void shouldNotHaveAnyEventSubscribersBeforeStart() throws Exception {
// given
runtimeId = new RuntimeIdentityImpl("workspace123", "envName", "ownerId", "infraNamespace");
EventService eventService = new EventService();
// when
startSynchronizer = new StartSynchronizer(eventService, 5, runtimeId);
// then
assertSubscriberTypesNumber(eventService, 0);
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class StartSynchronizerTest method shouldUnsubscribeEventsWhenItIsCompleted.
@Test
public void shouldUnsubscribeEventsWhenItIsCompleted() throws Exception {
// given
runtimeId = new RuntimeIdentityImpl("workspace123", "envName", "ownerId", "infraNamespace");
EventService eventService = new EventService();
startSynchronizer = new StartSynchronizer(eventService, 5, runtimeId);
startSynchronizer.start();
// when
startSynchronizer.complete();
// then
assertSubscribersNumber(eventService, KubernetesRuntimeStoppingEvent.class, 0);
assertSubscribersNumber(eventService, KubernetesRuntimeStoppedEvent.class, 0);
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class StartSynchronizerTest method shouldUnsubscribeEventsWhenItIscCompleteExceptionally.
@Test
public void shouldUnsubscribeEventsWhenItIscCompleteExceptionally() throws Exception {
// given
runtimeId = new RuntimeIdentityImpl("workspace123", "envName", "ownerId", "infraNamespace");
EventService eventService = new EventService();
startSynchronizer = new StartSynchronizer(eventService, 5, runtimeId);
startSynchronizer.start();
// when
startSynchronizer.completeExceptionally(new Exception());
// then
assertSubscribersNumber(eventService, KubernetesRuntimeStoppingEvent.class, 0);
assertSubscribersNumber(eventService, KubernetesRuntimeStoppedEvent.class, 0);
}
Aggregations