Skip to content

Commit

Permalink
fix #3155: clusterRoles() and clusterRoleBindings() return NonNamespa…
Browse files Browse the repository at this point in the history
…cedOperation in RbacAPIGroupClient

* Fixes #2526

Updated CHEATSHEET.md
Added example for how to configure okhttp logging-interceptor.

* Updated PR

* Updated changes

* Changed clusterRoleBindings and clusterRoles to return NonNamespace Operation instead of Mixed operation

* Changed clusterRoleBindings and clusterRoles to return NonNamespace Operation instead of Mixed operation
  • Loading branch information
MUzairS15 authored Jun 7, 2021
1 parent 3d92523 commit 3140498
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.fabric8.kubernetes.api.model.rbac.*;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.RbacAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.internal.rbac.v1.ClusterRoleBindingOperationsImpl;
Expand Down Expand Up @@ -46,12 +47,12 @@ public MixedOperation<RoleBinding, RoleBindingList, Resource<RoleBinding>> roleB
}

@Override
public MixedOperation<ClusterRole, ClusterRoleList, Resource<ClusterRole>> clusterRoles() {
public NonNamespaceOperation<ClusterRole, ClusterRoleList, Resource<ClusterRole>> clusterRoles() {
return new ClusterRoleOperationsImpl(httpClient, getConfiguration());
}

@Override
public MixedOperation<ClusterRoleBinding, ClusterRoleBindingList, Resource<ClusterRoleBinding>> clusterRoleBindings() {
public NonNamespaceOperation<ClusterRoleBinding, ClusterRoleBindingList, Resource<ClusterRoleBinding>> clusterRoleBindings() {
return new ClusterRoleBindingOperationsImpl(httpClient, getConfiguration());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public interface RbacAPIGroupDSL extends Client{

MixedOperation<RoleBinding, RoleBindingList, Resource<RoleBinding>> roleBindings();

MixedOperation<ClusterRole, ClusterRoleList, Resource<ClusterRole>> clusterRoles();
NonNamespaceOperation<ClusterRole, ClusterRoleList, Resource<ClusterRole>> clusterRoles();

MixedOperation<ClusterRoleBinding, ClusterRoleBindingList, Resource<ClusterRoleBinding>> clusterRoleBindings();
NonNamespaceOperation<ClusterRoleBinding, ClusterRoleBindingList, Resource<ClusterRoleBinding>> clusterRoleBindings();

}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void createClusterRoleBindingK8s() {
assertNotNull(clusterRoleBindingCreated);
assertNotNull(clusterRoleBindingCreated.getMetadata().getUid());
assertEquals(name, clusterRoleBindingCreated.getMetadata().getName());
client.rbac().clusterRoleBindings().inNamespace(session.getNamespace()).withName(name).delete();
client.rbac().clusterRoleBindings().withName(name).delete();
}

@Test
Expand All @@ -151,13 +151,13 @@ public void createClusterRoleK8s() {
.build();

// When
ClusterRole createdClusterRole = client.rbac().clusterRoles().inNamespace(session.getNamespace()).create(clusterRole);
ClusterRole createdClusterRole = client.rbac().clusterRoles().create(clusterRole);

// Then
assertNotNull(createdClusterRole);
assertNotNull(createdClusterRole.getMetadata().getUid());
assertEquals(name, createdClusterRole.getMetadata().getName());
client.rbac().clusterRoles().inNamespace(session.getNamespace()).withName(name).delete();
client.rbac().clusterRoles().withName(name).delete();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void init() {
.build()
)
.build();
client.rbac().clusterRoles().inNamespace(currentNamespace).createOrReplace(impersonatorRole);
client.rbac().clusterRoles().createOrReplace(impersonatorRole);

// Create Service Account
serviceAccount1 = new ServiceAccountBuilder()
Expand Down Expand Up @@ -109,7 +109,7 @@ public void init() {
)
.build();

client.rbac().clusterRoleBindings().inNamespace(currentNamespace).createOrReplace(impersonatorRoleBinding);
client.rbac().clusterRoleBindings().createOrReplace(impersonatorRoleBinding);
}


Expand Down Expand Up @@ -153,11 +153,11 @@ public void cleanup() {
requestConfig.setImpersonateGroups((String) null);

// DeleteEntity Cluster Role
client.rbac().clusterRoles().inNamespace(currentNamespace).delete(impersonatorRole);
client.rbac().clusterRoles().delete(impersonatorRole);
await().atMost(30, TimeUnit.SECONDS).until(kubernetesClusterRoleIsDeleted());

// DeleteEntity Cluster Role binding
client.rbac().clusterRoleBindings().inNamespace(currentNamespace).delete(impersonatorRoleBinding);
client.rbac().clusterRoleBindings().delete(impersonatorRoleBinding);
await().atMost(30, TimeUnit.SECONDS).until(kubernetesClusterRoleBindingIsDeleted());

// DeleteEntity project
Expand All @@ -178,11 +178,11 @@ private Callable<Boolean> projectIsDeleted() {
}

private Callable<Boolean> kubernetesClusterRoleBindingIsDeleted() {
return () -> client.rbac().clusterRoleBindings().inNamespace(currentNamespace).withName("impersonator-role").get() == null;
return () -> client.rbac().clusterRoleBindings().withName("impersonator-role").get() == null;
}

private Callable<Boolean> kubernetesClusterRoleIsDeleted() {
return () -> client.rbac().clusterRoles().inNamespace(currentNamespace).withName("impersonator").get() == null;
return () -> client.rbac().clusterRoles().withName("impersonator").get() == null;
}


Expand Down

0 comments on commit 3140498

Please sign in to comment.