Search in sources :

Example 1 with ClusterRoleBindingList

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

the class ClusterRoleBindingIT method list.

@Test
public void list() {
    ClusterRoleBindingList clusterRoleBindingList = client.rbac().clusterRoleBindings().list();
    boolean found = false;
    assertNotNull(clusterRoleBindingList);
    assertNotNull(clusterRoleBindingList.getItems());
    for (ClusterRoleBinding clusterRoleBinding : clusterRoleBindingList.getItems()) {
        if (clusterRoleBinding.getMetadata().getName().equals("read-nodes-list")) {
            assertEquals("ClusterRoleBinding", clusterRoleBinding.getKind());
            assertNotNull(clusterRoleBinding.getMetadata());
            assertEquals("read-nodes-list", clusterRoleBinding.getMetadata().getName());
            assertNotNull(clusterRoleBinding.getSubjects());
            assertEquals(1, clusterRoleBinding.getSubjects().size());
            assertEquals("rbac.authorization.k8s.io", clusterRoleBinding.getSubjects().get(0).getApiGroup());
            assertEquals("User", clusterRoleBinding.getSubjects().get(0).getKind());
            assertEquals("jane", clusterRoleBinding.getSubjects().get(0).getName());
            assertEquals("default", clusterRoleBinding.getSubjects().get(0).getNamespace());
            assertNotNull(clusterRoleBinding.getRoleRef());
            assertEquals("ClusterRole", clusterRoleBinding.getRoleRef().getKind());
            assertEquals("secret-reader", clusterRoleBinding.getRoleRef().getName());
            found = true;
        }
    }
    assertTrue(found);
}
Also used : ClusterRoleBindingList(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingList) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) Test(org.junit.Test)

Example 2 with ClusterRoleBindingList

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

the class ClusterRoleBindingCrudTest method crudTest.

@Test
void crudTest() {
    ClusterRoleBinding kubernetesClusterRoleBinding = new ClusterRoleBindingBuilder().withNewMetadata().withName("read-nodes").endMetadata().addToSubjects(0, new SubjectBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("User").withName("jane").withNamespace("default").build()).withRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("ClusterRole").withName("node-reader").build()).build();
    // test of creation
    kubernetesClusterRoleBinding = client.rbac().clusterRoleBindings().create(kubernetesClusterRoleBinding);
    assertNotNull(kubernetesClusterRoleBinding);
    assertEquals("ClusterRoleBinding", kubernetesClusterRoleBinding.getKind());
    assertEquals("rbac.authorization.k8s.io/v1", kubernetesClusterRoleBinding.getApiVersion());
    assertNotNull(kubernetesClusterRoleBinding.getMetadata());
    assertEquals("read-nodes", kubernetesClusterRoleBinding.getMetadata().getName());
    assertNotNull(kubernetesClusterRoleBinding.getSubjects());
    assertEquals(1, kubernetesClusterRoleBinding.getSubjects().size());
    assertEquals("rbac.authorization.k8s.io", kubernetesClusterRoleBinding.getSubjects().get(0).getApiGroup());
    assertEquals("User", kubernetesClusterRoleBinding.getSubjects().get(0).getKind());
    assertEquals("jane", kubernetesClusterRoleBinding.getSubjects().get(0).getName());
    assertEquals("default", kubernetesClusterRoleBinding.getSubjects().get(0).getNamespace());
    assertNotNull(kubernetesClusterRoleBinding.getRoleRef());
    assertEquals("ClusterRole", kubernetesClusterRoleBinding.getRoleRef().getKind());
    assertEquals("node-reader", kubernetesClusterRoleBinding.getRoleRef().getName());
    assertEquals("rbac.authorization.k8s.io", kubernetesClusterRoleBinding.getRoleRef().getApiGroup());
    // test of list
    ClusterRoleBindingList kubernetesClusterRoleBindingList = client.rbac().clusterRoleBindings().list();
    assertNotNull(kubernetesClusterRoleBindingList);
    assertNotNull(kubernetesClusterRoleBindingList.getItems());
    assertEquals(1, kubernetesClusterRoleBindingList.getItems().size());
    assertNotNull(kubernetesClusterRoleBindingList.getItems().get(0));
    assertEquals("ClusterRoleBinding", kubernetesClusterRoleBindingList.getItems().get(0).getKind());
    assertEquals("rbac.authorization.k8s.io/v1", kubernetesClusterRoleBindingList.getItems().get(0).getApiVersion());
    assertNotNull(kubernetesClusterRoleBindingList.getItems().get(0).getMetadata());
    assertEquals("read-nodes", kubernetesClusterRoleBindingList.getItems().get(0).getMetadata().getName());
    assertNotNull(kubernetesClusterRoleBindingList.getItems().get(0).getSubjects());
    assertEquals(1, kubernetesClusterRoleBindingList.getItems().get(0).getSubjects().size());
    assertEquals("rbac.authorization.k8s.io", kubernetesClusterRoleBindingList.getItems().get(0).getSubjects().get(0).getApiGroup());
    assertEquals("User", kubernetesClusterRoleBindingList.getItems().get(0).getSubjects().get(0).getKind());
    assertEquals("jane", kubernetesClusterRoleBindingList.getItems().get(0).getSubjects().get(0).getName());
    assertEquals("default", kubernetesClusterRoleBindingList.getItems().get(0).getSubjects().get(0).getNamespace());
    assertNotNull(kubernetesClusterRoleBindingList.getItems().get(0).getRoleRef());
    assertEquals("ClusterRole", kubernetesClusterRoleBindingList.getItems().get(0).getRoleRef().getKind());
    assertEquals("node-reader", kubernetesClusterRoleBindingList.getItems().get(0).getRoleRef().getName());
    assertEquals("rbac.authorization.k8s.io", kubernetesClusterRoleBindingList.getItems().get(0).getRoleRef().getApiGroup());
    // test of updation
    kubernetesClusterRoleBinding = client.rbac().clusterRoleBindings().withName("read-nodes").edit(c -> new ClusterRoleBindingBuilder(c).editSubject(0).withName("jane-new").endSubject().build());
    assertNotNull(kubernetesClusterRoleBinding);
    assertEquals("ClusterRoleBinding", kubernetesClusterRoleBinding.getKind());
    assertEquals("rbac.authorization.k8s.io/v1", kubernetesClusterRoleBinding.getApiVersion());
    assertNotNull(kubernetesClusterRoleBinding.getMetadata());
    assertEquals("read-nodes", kubernetesClusterRoleBinding.getMetadata().getName());
    assertNotNull(kubernetesClusterRoleBinding.getSubjects());
    assertEquals(1, kubernetesClusterRoleBinding.getSubjects().size());
    assertEquals("rbac.authorization.k8s.io", kubernetesClusterRoleBinding.getSubjects().get(0).getApiGroup());
    assertEquals("User", kubernetesClusterRoleBinding.getSubjects().get(0).getKind());
    assertEquals("jane-new", kubernetesClusterRoleBinding.getSubjects().get(0).getName());
    assertEquals("default", kubernetesClusterRoleBinding.getSubjects().get(0).getNamespace());
    assertNotNull(kubernetesClusterRoleBinding.getRoleRef());
    assertEquals("ClusterRole", kubernetesClusterRoleBinding.getRoleRef().getKind());
    assertEquals("node-reader", kubernetesClusterRoleBinding.getRoleRef().getName());
    assertEquals("rbac.authorization.k8s.io", kubernetesClusterRoleBinding.getRoleRef().getApiGroup());
    // test of deletion
    boolean deleted = client.rbac().clusterRoleBindings().delete();
    assertTrue(deleted);
    kubernetesClusterRoleBindingList = client.rbac().clusterRoleBindings().list();
    assertEquals(0, kubernetesClusterRoleBindingList.getItems().size());
}
Also used : ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Logger(org.slf4j.Logger) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder) LoggerFactory(org.slf4j.LoggerFactory) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder) Test(org.junit.jupiter.api.Test) EnableKubernetesMockClient(io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ClusterRoleBindingList(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ClusterRoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingBuilder) ClusterRoleBindingList(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingList) ClusterRoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingBuilder) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with ClusterRoleBindingList

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

the class ClusterRoleBindingIT method delete.

@Test
public void delete() {
    ClusterRoleBindingList clusterRoleBindingListBefore = client.rbac().clusterRoleBindings().list();
    boolean deleted = client.rbac().clusterRoleBindings().withName("read-nodes-delete").delete();
    assertTrue(deleted);
    DeleteEntity<ClusterRoleBinding> clusterRoleBindingDeleteEntity = new DeleteEntity<>(ClusterRoleBinding.class, client, "read-nodes", null);
    await().atMost(30, TimeUnit.SECONDS).until(clusterRoleBindingDeleteEntity);
    ClusterRoleBindingList clusterRoleBindingListAfter = client.rbac().clusterRoleBindings().list();
    assertEquals(clusterRoleBindingListBefore.getItems().size() - 1, clusterRoleBindingListAfter.getItems().size());
}
Also used : ClusterRoleBindingList(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingList) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) DeleteEntity(io.fabric8.commons.DeleteEntity) Test(org.junit.Test)

Aggregations

ClusterRoleBinding (io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding)3 ClusterRoleBindingList (io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingList)3 Test (org.junit.Test)2 DeleteEntity (io.fabric8.commons.DeleteEntity)1 ClusterRoleBindingBuilder (io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingBuilder)1 RoleRefBuilder (io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)1 SubjectBuilder (io.fabric8.kubernetes.api.model.rbac.SubjectBuilder)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 EnableKubernetesMockClient (io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient)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 Test (org.junit.jupiter.api.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1