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);
}
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());
}
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());
}
Aggregations