use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project devspaces-images by redhat-developer.
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());
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity 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.core.model.workspace.runtime.RuntimeIdentity 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.core.model.workspace.runtime.RuntimeIdentity in project devspaces-images by redhat-developer.
the class KubernetesMachinesCacheTest method shouldGetMachines.
@Test
public void shouldGetMachines() throws Exception {
// given
RuntimeIdentity runtimeId = runtimeStates[0].getRuntimeId();
// when
machineCache.getMachines(runtimeId);
// then
Map<String, KubernetesMachineImpl> fetched = machineCache.getMachines(runtimeId);
assertEquals(fetched.size(), 2);
assertTrue(fetched.keySet().containsAll(asList("machine1", "machine2")));
assertTrue(fetched.values().containsAll(asList(machines[0], machines[1])));
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project devspaces-images by redhat-developer.
the class KubernetesMachinesCacheTest method shouldUpdateServerStatus.
@Test
public void shouldUpdateServerStatus() throws Exception {
// given
RuntimeIdentity runtimeId = runtimeStates[0].getRuntimeId();
// when
machineCache.updateServerStatus(runtimeId, machines[0].getName(), "server1", ServerStatus.RUNNING);
// then
KubernetesServerImpl fetchedServer = machineCache.getServer(runtimeId, "machine1", "server1");
assertEquals(fetchedServer.getStatus(), ServerStatus.RUNNING);
}
Aggregations