Search in sources :

Example 1 with PREFERENCES_CONFIGMAP_NAME

use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.PREFERENCES_CONFIGMAP_NAME in project che-server by eclipse-che.

the class KubernetesWorkspaceServiceAccountTest method shouldCreatePreferencesConfigmapRole.

@Test
public void shouldCreatePreferencesConfigmapRole() throws Exception {
    KubernetesClient localK8sClient = spy(serverMock.getClient());
    when(clientFactory.create(anyString())).thenReturn(localK8sClient);
    // when
    serviceAccount.prepare();
    // then
    RoleList rl = k8sClient.rbac().roles().inNamespace(NAMESPACE).list();
    Optional<Role> roleOptional = rl.getItems().stream().filter(r -> r.getMetadata().getName().equals(CONFIGMAPS_ROLE_NAME)).findFirst();
    assertTrue(roleOptional.isPresent());
    PolicyRule rule = roleOptional.get().getRules().get(0);
    assertEquals(rule.getResources(), singletonList("configmaps"));
    assertEquals(rule.getResourceNames(), singletonList(PREFERENCES_CONFIGMAP_NAME));
    assertEquals(rule.getApiGroups(), singletonList(""));
    assertEquals(rule.getVerbs(), Arrays.asList("get", "patch"));
    RoleBindingList rbl = k8sClient.rbac().roleBindings().inNamespace(NAMESPACE).list();
    assertTrue(rbl.getItems().stream().anyMatch(rb -> rb.getMetadata().getName().equals(SA_NAME + "-configmaps")));
}
Also used : Role(io.fabric8.kubernetes.api.model.rbac.Role) Arrays(java.util.Arrays) KubernetesClientFactory(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesClientFactory) Listeners(org.testng.annotations.Listeners) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RoleBindingList(io.fabric8.kubernetes.api.model.rbac.RoleBindingList) Mock(org.mockito.Mock) Role(io.fabric8.kubernetes.api.model.rbac.Role) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Mockito.spy(org.mockito.Mockito.spy) Collections.singletonList(java.util.Collections.singletonList) RoleBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBuilder) SECRETS_ROLE_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.SECRETS_ROLE_NAME) CONFIGMAPS_ROLE_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.CONFIGMAPS_ROLE_NAME) RoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder) KubernetesServer(io.fabric8.kubernetes.client.server.mock.KubernetesServer) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ServiceAccountBuilder(io.fabric8.kubernetes.api.model.ServiceAccountBuilder) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) CREDENTIALS_SECRET_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.CREDENTIALS_SECRET_NAME) Mockito.when(org.mockito.Mockito.when) PolicyRule(io.fabric8.kubernetes.api.model.rbac.PolicyRule) RoleList(io.fabric8.kubernetes.api.model.rbac.RoleList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Assert.assertTrue(org.testng.Assert.assertTrue) Optional(java.util.Optional) METRICS_ROLE_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.METRICS_ROLE_NAME) Collections(java.util.Collections) PREFERENCES_CONFIGMAP_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.PREFERENCES_CONFIGMAP_NAME) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PolicyRule(io.fabric8.kubernetes.api.model.rbac.PolicyRule) RoleList(io.fabric8.kubernetes.api.model.rbac.RoleList) RoleBindingList(io.fabric8.kubernetes.api.model.rbac.RoleBindingList) Test(org.testng.annotations.Test)

Example 2 with PREFERENCES_CONFIGMAP_NAME

use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.PREFERENCES_CONFIGMAP_NAME in project devspaces-images by redhat-developer.

the class KubernetesWorkspaceServiceAccountTest method shouldCreatePreferencesConfigmapRole.

@Test
public void shouldCreatePreferencesConfigmapRole() throws Exception {
    KubernetesClient localK8sClient = spy(serverMock.getClient());
    when(clientFactory.create(anyString())).thenReturn(localK8sClient);
    // when
    serviceAccount.prepare();
    // then
    RoleList rl = k8sClient.rbac().roles().inNamespace(NAMESPACE).list();
    Optional<Role> roleOptional = rl.getItems().stream().filter(r -> r.getMetadata().getName().equals(CONFIGMAPS_ROLE_NAME)).findFirst();
    assertTrue(roleOptional.isPresent());
    PolicyRule rule = roleOptional.get().getRules().get(0);
    assertEquals(rule.getResources(), singletonList("configmaps"));
    assertEquals(rule.getResourceNames(), singletonList(PREFERENCES_CONFIGMAP_NAME));
    assertEquals(rule.getApiGroups(), singletonList(""));
    assertEquals(rule.getVerbs(), Arrays.asList("get", "patch"));
    RoleBindingList rbl = k8sClient.rbac().roleBindings().inNamespace(NAMESPACE).list();
    assertTrue(rbl.getItems().stream().anyMatch(rb -> rb.getMetadata().getName().equals(SA_NAME + "-configmaps")));
}
Also used : Role(io.fabric8.kubernetes.api.model.rbac.Role) Arrays(java.util.Arrays) KubernetesClientFactory(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesClientFactory) Listeners(org.testng.annotations.Listeners) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RoleBindingList(io.fabric8.kubernetes.api.model.rbac.RoleBindingList) Mock(org.mockito.Mock) Role(io.fabric8.kubernetes.api.model.rbac.Role) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Mockito.spy(org.mockito.Mockito.spy) Collections.singletonList(java.util.Collections.singletonList) RoleBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBuilder) SECRETS_ROLE_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.SECRETS_ROLE_NAME) CONFIGMAPS_ROLE_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.CONFIGMAPS_ROLE_NAME) RoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder) KubernetesServer(io.fabric8.kubernetes.client.server.mock.KubernetesServer) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ServiceAccountBuilder(io.fabric8.kubernetes.api.model.ServiceAccountBuilder) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) CREDENTIALS_SECRET_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.CREDENTIALS_SECRET_NAME) Mockito.when(org.mockito.Mockito.when) PolicyRule(io.fabric8.kubernetes.api.model.rbac.PolicyRule) RoleList(io.fabric8.kubernetes.api.model.rbac.RoleList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Assert.assertTrue(org.testng.Assert.assertTrue) Optional(java.util.Optional) METRICS_ROLE_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.METRICS_ROLE_NAME) Collections(java.util.Collections) PREFERENCES_CONFIGMAP_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.PREFERENCES_CONFIGMAP_NAME) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PolicyRule(io.fabric8.kubernetes.api.model.rbac.PolicyRule) RoleList(io.fabric8.kubernetes.api.model.rbac.RoleList) RoleBindingList(io.fabric8.kubernetes.api.model.rbac.RoleBindingList) Test(org.testng.annotations.Test)

Aggregations

ServiceAccountBuilder (io.fabric8.kubernetes.api.model.ServiceAccountBuilder)2 PolicyRule (io.fabric8.kubernetes.api.model.rbac.PolicyRule)2 Role (io.fabric8.kubernetes.api.model.rbac.Role)2 RoleBindingBuilder (io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder)2 RoleBindingList (io.fabric8.kubernetes.api.model.rbac.RoleBindingList)2 RoleBuilder (io.fabric8.kubernetes.api.model.rbac.RoleBuilder)2 RoleList (io.fabric8.kubernetes.api.model.rbac.RoleList)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 KubernetesServer (io.fabric8.kubernetes.client.server.mock.KubernetesServer)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Collections.singletonList (java.util.Collections.singletonList)2 Optional (java.util.Optional)2 Set (java.util.Set)2 KubernetesClientFactory (org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesClientFactory)2 CONFIGMAPS_ROLE_NAME (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.CONFIGMAPS_ROLE_NAME)2 CREDENTIALS_SECRET_NAME (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.CREDENTIALS_SECRET_NAME)2 METRICS_ROLE_NAME (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.METRICS_ROLE_NAME)2 PREFERENCES_CONFIGMAP_NAME (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.PREFERENCES_CONFIGMAP_NAME)2 SECRETS_ROLE_NAME (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.SECRETS_ROLE_NAME)2