Search in sources :

Example 1 with ClusterRoleList

use of io.fabric8.kubernetes.api.model.rbac.ClusterRoleList in project kubernetes-client by fabric8io.

the class ClusterRoleIT method list.

@Test
public void list() {
    ClusterRoleList clusterRoleList = client.rbac().clusterRoles().list();
    boolean found = false;
    assertNotNull(clusterRoleList);
    assertNotNull(clusterRoleList.getItems());
    for (ClusterRole clusterRole : clusterRoleList.getItems()) {
        if (clusterRole.getMetadata().getName().equals("node-reader-list")) {
            assertEquals("ClusterRole", clusterRole.getKind());
            assertNotNull(clusterRole.getMetadata());
            assertEquals("node-reader-list", clusterRole.getMetadata().getName());
            assertNotNull(clusterRole.getRules());
            assertEquals(1, clusterRole.getRules().size());
            assertNotNull(clusterRole.getRules().get(0).getApiGroups());
            assertEquals(1, clusterRole.getRules().get(0).getApiGroups().size());
            assertEquals("", clusterRole.getRules().get(0).getApiGroups().get(0));
            assertNotNull(clusterRole.getRules().get(0).getResourceNames());
            assertNotNull(clusterRole.getRules().get(0).getResources());
            assertEquals(1, clusterRole.getRules().get(0).getResources().size());
            assertEquals("secrets", clusterRole.getRules().get(0).getResources().get(0));
            assertNotNull(clusterRole.getRules().get(0).getVerbs());
            assertEquals(3, clusterRole.getRules().get(0).getVerbs().size());
            assertEquals("get", clusterRole.getRules().get(0).getVerbs().get(0));
            assertEquals("watch", clusterRole.getRules().get(0).getVerbs().get(1));
            assertEquals("list", clusterRole.getRules().get(0).getVerbs().get(2));
            found = true;
        }
    }
    assertTrue(found);
}
Also used : ClusterRoleList(io.fabric8.kubernetes.api.model.rbac.ClusterRoleList) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) Test(org.junit.Test)

Example 2 with ClusterRoleList

use of io.fabric8.kubernetes.api.model.rbac.ClusterRoleList in project kubernetes-client by fabric8io.

the class ClusterRoleIT method delete.

@Test
public void delete() {
    ClusterRoleList clusterRoleListBefore = client.rbac().clusterRoles().list();
    boolean deleted = client.rbac().clusterRoles().withName("node-reader-delete").delete();
    assertTrue(deleted);
    DeleteEntity<ClusterRole> deleteEntity = new DeleteEntity<>(ClusterRole.class, client, "node-reader", null);
    await().atMost(30, TimeUnit.SECONDS).until(deleteEntity);
    ClusterRoleList clusterRoleListAfter = client.rbac().clusterRoles().list();
    assertEquals(clusterRoleListBefore.getItems().size() - 1, clusterRoleListAfter.getItems().size());
}
Also used : DeleteEntity(io.fabric8.commons.DeleteEntity) ClusterRoleList(io.fabric8.kubernetes.api.model.rbac.ClusterRoleList) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) Test(org.junit.Test)

Example 3 with ClusterRoleList

use of io.fabric8.kubernetes.api.model.rbac.ClusterRoleList in project kubernetes-client by fabric8io.

the class ClusterRoleCrudTest method crudTest.

@Test
void crudTest() {
    ClusterRole kubernetesClusterRole = new ClusterRoleBuilder().withNewMetadata().withName("node-reader").endMetadata().addToRules(0, new PolicyRuleBuilder().addToApiGroups(0, "").addToNonResourceURLs(0, "/healthz").addToResourceNames(0, "my-node").addToResources(0, "nodes").addToVerbs(0, "get").addToVerbs(1, "watch").addToVerbs(2, "list").build()).build();
    // test of creation
    kubernetesClusterRole = client.rbac().clusterRoles().create(kubernetesClusterRole);
    assertNotNull(kubernetesClusterRole);
    assertEquals("ClusterRole", kubernetesClusterRole.getKind());
    assertEquals("rbac.authorization.k8s.io/v1", kubernetesClusterRole.getApiVersion());
    assertNotNull(kubernetesClusterRole.getMetadata());
    assertEquals("node-reader", kubernetesClusterRole.getMetadata().getName());
    assertNotNull(kubernetesClusterRole.getRules());
    assertEquals(1, kubernetesClusterRole.getRules().size());
    assertNotNull(kubernetesClusterRole.getRules().get(0).getApiGroups());
    assertEquals(1, kubernetesClusterRole.getRules().get(0).getApiGroups().size());
    assertEquals("", kubernetesClusterRole.getRules().get(0).getApiGroups().get(0));
    assertNotNull(kubernetesClusterRole.getRules().get(0).getNonResourceURLs());
    assertEquals(1, kubernetesClusterRole.getRules().get(0).getNonResourceURLs().size());
    assertEquals("/healthz", kubernetesClusterRole.getRules().get(0).getNonResourceURLs().get(0));
    assertNotNull(kubernetesClusterRole.getRules().get(0).getResourceNames());
    assertEquals(1, kubernetesClusterRole.getRules().get(0).getResourceNames().size());
    assertEquals("my-node", kubernetesClusterRole.getRules().get(0).getResourceNames().get(0));
    assertNotNull(kubernetesClusterRole.getRules().get(0).getResources());
    assertEquals(1, kubernetesClusterRole.getRules().get(0).getResources().size());
    assertEquals("nodes", kubernetesClusterRole.getRules().get(0).getResources().get(0));
    assertNotNull(kubernetesClusterRole.getRules().get(0).getVerbs());
    assertEquals(3, kubernetesClusterRole.getRules().get(0).getVerbs().size());
    assertEquals("get", kubernetesClusterRole.getRules().get(0).getVerbs().get(0));
    assertEquals("watch", kubernetesClusterRole.getRules().get(0).getVerbs().get(1));
    assertEquals("list", kubernetesClusterRole.getRules().get(0).getVerbs().get(2));
    // test of list
    ClusterRoleList kubernetesClusterRoleList = client.rbac().clusterRoles().list();
    assertNotNull(kubernetesClusterRoleList);
    assertNotNull(kubernetesClusterRoleList.getItems());
    assertEquals(1, kubernetesClusterRoleList.getItems().size());
    assertNotNull(kubernetesClusterRoleList.getItems().get(0));
    assertEquals("ClusterRole", kubernetesClusterRoleList.getItems().get(0).getKind());
    assertEquals("rbac.authorization.k8s.io/v1", kubernetesClusterRoleList.getItems().get(0).getApiVersion());
    assertNotNull(kubernetesClusterRoleList.getItems().get(0).getMetadata());
    assertEquals("node-reader", kubernetesClusterRoleList.getItems().get(0).getMetadata().getName());
    assertNotNull(kubernetesClusterRoleList.getItems().get(0).getRules());
    assertEquals(1, kubernetesClusterRoleList.getItems().get(0).getRules().size());
    assertNotNull(kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getApiGroups());
    assertEquals(1, kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getApiGroups().size());
    assertEquals("", kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getApiGroups().get(0));
    assertNotNull(kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getNonResourceURLs());
    assertEquals(1, kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getNonResourceURLs().size());
    assertEquals("/healthz", kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getNonResourceURLs().get(0));
    assertNotNull(kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getResourceNames());
    assertEquals(1, kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getResourceNames().size());
    assertEquals("my-node", kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getResourceNames().get(0));
    assertNotNull(kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getResources());
    assertEquals(1, kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getResources().size());
    assertEquals("nodes", kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getResources().get(0));
    assertNotNull(kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getVerbs());
    assertEquals(3, kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getVerbs().size());
    assertEquals("get", kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getVerbs().get(0));
    assertEquals("watch", kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getVerbs().get(1));
    assertEquals("list", kubernetesClusterRoleList.getItems().get(0).getRules().get(0).getVerbs().get(2));
    // test of updation
    kubernetesClusterRole = client.rbac().clusterRoles().withName("node-reader").edit(c -> new ClusterRoleBuilder(c).editRule(0).addToApiGroups(1, "extensions").endRule().build());
    assertNotNull(kubernetesClusterRole);
    assertEquals("ClusterRole", kubernetesClusterRole.getKind());
    assertEquals("rbac.authorization.k8s.io/v1", kubernetesClusterRole.getApiVersion());
    assertNotNull(kubernetesClusterRole.getMetadata());
    assertEquals("node-reader", kubernetesClusterRole.getMetadata().getName());
    assertNotNull(kubernetesClusterRole.getRules());
    assertEquals(1, kubernetesClusterRole.getRules().size());
    assertNotNull(kubernetesClusterRole.getRules().get(0).getApiGroups());
    assertEquals(2, kubernetesClusterRole.getRules().get(0).getApiGroups().size());
    assertEquals("", kubernetesClusterRole.getRules().get(0).getApiGroups().get(0));
    assertEquals("extensions", kubernetesClusterRole.getRules().get(0).getApiGroups().get(1));
    assertNotNull(kubernetesClusterRole.getRules().get(0).getNonResourceURLs());
    assertEquals(1, kubernetesClusterRole.getRules().get(0).getNonResourceURLs().size());
    assertEquals("/healthz", kubernetesClusterRole.getRules().get(0).getNonResourceURLs().get(0));
    assertNotNull(kubernetesClusterRole.getRules().get(0).getResourceNames());
    assertEquals(1, kubernetesClusterRole.getRules().get(0).getResourceNames().size());
    assertEquals("my-node", kubernetesClusterRole.getRules().get(0).getResourceNames().get(0));
    assertNotNull(kubernetesClusterRole.getRules().get(0).getResources());
    assertEquals(1, kubernetesClusterRole.getRules().get(0).getResources().size());
    assertEquals("nodes", kubernetesClusterRole.getRules().get(0).getResources().get(0));
    assertNotNull(kubernetesClusterRole.getRules().get(0).getVerbs());
    assertEquals(3, kubernetesClusterRole.getRules().get(0).getVerbs().size());
    assertEquals("get", kubernetesClusterRole.getRules().get(0).getVerbs().get(0));
    assertEquals("watch", kubernetesClusterRole.getRules().get(0).getVerbs().get(1));
    assertEquals("list", kubernetesClusterRole.getRules().get(0).getVerbs().get(2));
    // test of deletion
    boolean deleted = client.rbac().clusterRoles().delete();
    assertTrue(deleted);
    kubernetesClusterRoleList = client.rbac().clusterRoles().list();
    assertEquals(0, kubernetesClusterRoleList.getItems().size());
}
Also used : ClusterRoleBuilder(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBuilder) Test(org.junit.jupiter.api.Test) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Logger(org.slf4j.Logger) EnableKubernetesMockClient(io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) ClusterRoleList(io.fabric8.kubernetes.api.model.rbac.ClusterRoleList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) LoggerFactory(org.slf4j.LoggerFactory) PolicyRuleBuilder(io.fabric8.kubernetes.api.model.rbac.PolicyRuleBuilder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ClusterRoleBuilder(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBuilder) ClusterRoleList(io.fabric8.kubernetes.api.model.rbac.ClusterRoleList) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) PolicyRuleBuilder(io.fabric8.kubernetes.api.model.rbac.PolicyRuleBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with ClusterRoleList

use of io.fabric8.kubernetes.api.model.rbac.ClusterRoleList in project kubernetes-client by fabric8io.

the class ClusterRoleTest method list.

@Test
void list() {
    // Given
    server.expect().get().withPath("/apis/authorization.openshift.io/v1/clusterroles").andReturn(HttpURLConnection.HTTP_OK, new ClusterRoleListBuilder().addToItems(createNewClusterRole("test-list")).build()).once();
    // When
    ClusterRoleList clusterRoleList = client.clusterRoles().list();
    // Then
    assertThat(clusterRoleList).isNotNull();
    assertThat(clusterRoleList.getItems()).hasSize(1);
    assertThat(clusterRoleList.getItems().get(0)).hasFieldOrPropertyWithValue("metadata.name", "test-list");
}
Also used : ClusterRoleList(io.fabric8.openshift.api.model.ClusterRoleList) ClusterRoleListBuilder(io.fabric8.openshift.api.model.ClusterRoleListBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterRole (io.fabric8.kubernetes.api.model.rbac.ClusterRole)3 ClusterRoleList (io.fabric8.kubernetes.api.model.rbac.ClusterRoleList)3 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 DeleteEntity (io.fabric8.commons.DeleteEntity)1 ClusterRoleBuilder (io.fabric8.kubernetes.api.model.rbac.ClusterRoleBuilder)1 PolicyRuleBuilder (io.fabric8.kubernetes.api.model.rbac.PolicyRuleBuilder)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 EnableKubernetesMockClient (io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient)1 ClusterRoleList (io.fabric8.openshift.api.model.ClusterRoleList)1 ClusterRoleListBuilder (io.fabric8.openshift.api.model.ClusterRoleListBuilder)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1