File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -551,7 +551,11 @@ func (o *RoleModificationOptions) RemoveRole() error {
551
551
for _ , roleBinding := range roleBindings {
552
552
roleBinding .Subjects = removeSubjects (roleBinding .Subjects , subjectsToRemove )
553
553
554
- err := o .RoleBindingAccessor .UpdateRoleBinding (roleBinding )
554
+ if len (roleBinding .Subjects ) > 0 {
555
+ err = o .RoleBindingAccessor .UpdateRoleBinding (roleBinding )
556
+ } else {
557
+ err = o .RoleBindingAccessor .DeleteRoleBinding (roleBinding .Name )
558
+ }
555
559
if err != nil {
556
560
return err
557
561
}
Original file line number Diff line number Diff line change @@ -121,6 +121,7 @@ type RoleBindingAccessor interface {
121
121
GetRoleBinding (name string ) (* authorizationapi.RoleBinding , error )
122
122
UpdateRoleBinding (binding * authorizationapi.RoleBinding ) error
123
123
CreateRoleBinding (binding * authorizationapi.RoleBinding ) error
124
+ DeleteRoleBinding (name string ) error
124
125
}
125
126
126
127
// LocalRoleBindingAccessor operates against role bindings in namespace
@@ -181,6 +182,10 @@ func (a LocalRoleBindingAccessor) CreateRoleBinding(binding *authorizationapi.Ro
181
182
return err
182
183
}
183
184
185
+ func (a LocalRoleBindingAccessor ) DeleteRoleBinding (name string ) error {
186
+ return a .Client .RoleBindings (a .BindingNamespace ).Delete (name , & metav1.DeleteOptions {})
187
+ }
188
+
184
189
// ClusterRoleBindingAccessor operates against cluster scoped role bindings
185
190
type ClusterRoleBindingAccessor struct {
186
191
Client authorizationtypedclient.ClusterRoleBindingsGetter
@@ -249,3 +254,7 @@ func (a ClusterRoleBindingAccessor) CreateRoleBinding(binding *authorizationapi.
249
254
_ , err := a .Client .ClusterRoleBindings ().Create (clusterBinding )
250
255
return err
251
256
}
257
+
258
+ func (a ClusterRoleBindingAccessor ) DeleteRoleBinding (name string ) error {
259
+ return a .Client .ClusterRoleBindings ().Delete (name , & metav1.DeleteOptions {})
260
+ }
You can’t perform that action at this time.
0 commit comments