Skip to content

Commit 404628b

Browse files
author
OpenShift Bot
authored
Merge pull request openshift#15142 from liggitt/role-controller-cleanup
Merged by openshift-bot
2 parents c52694b + 719d2cf commit 404628b

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

pkg/authorization/controller/authorizationsync/origin_to_rbac_clusterrole_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ func (c *OriginClusterRoleToRBACClusterRoleController) syncClusterRole(name stri
7070
// if the origin role doesn't exist, just delete the rbac role
7171
if apierrors.IsNotFound(originErr) {
7272
// orphan on delete to minimize fanout. We ought to clean the rest via controller too.
73-
return c.rbacClient.ClusterRoles().Delete(name, nil)
73+
deleteErr := c.rbacClient.ClusterRoles().Delete(name, nil)
74+
if apierrors.IsNotFound(deleteErr) {
75+
return nil
76+
}
77+
return deleteErr
7478
}
7579

7680
// determine if we need to create, update or do nothing
@@ -133,15 +137,17 @@ func (c *OriginClusterRoleToRBACClusterRoleController) clusterPolicyEventHandler
133137
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
134138
if !ok {
135139
utilruntime.HandleError(fmt.Errorf("Couldn't get object from tombstone %#v", obj))
140+
return
136141
}
137142
originContainerObj, ok = tombstone.Obj.(*authorizationapi.ClusterPolicy)
138143
if !ok {
139144
utilruntime.HandleError(fmt.Errorf("Tombstone contained object that is not a runtime.Object %#v", obj))
145+
return
140146
}
141147
}
142148

143149
for _, originObj := range originContainerObj.Roles {
144-
c.originIndexer.Add(originObj)
150+
c.originIndexer.Delete(originObj)
145151
key, err := controller.KeyFunc(originObj)
146152
if err != nil {
147153
utilruntime.HandleError(err)

pkg/authorization/controller/authorizationsync/origin_to_rbac_clusterrolebinding_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ func (c *OriginClusterRoleBindingToRBACClusterRoleBindingController) syncCluster
7070
// if the origin roleBinding doesn't exist, just delete the rbac roleBinding
7171
if apierrors.IsNotFound(originErr) {
7272
// orphan on delete to minimize fanout. We ought to clean the rest via controller too.
73-
return c.rbacClient.ClusterRoleBindings().Delete(name, nil)
73+
deleteErr := c.rbacClient.ClusterRoleBindings().Delete(name, nil)
74+
if apierrors.IsNotFound(deleteErr) {
75+
return nil
76+
}
77+
return deleteErr
7478
}
7579

7680
// determine if we need to create, update or do nothing
@@ -133,15 +137,17 @@ func (c *OriginClusterRoleBindingToRBACClusterRoleBindingController) clusterPoli
133137
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
134138
if !ok {
135139
utilruntime.HandleError(fmt.Errorf("Couldn't get object from tombstone %#v", obj))
140+
return
136141
}
137142
originContainerObj, ok = tombstone.Obj.(*authorizationapi.ClusterPolicyBinding)
138143
if !ok {
139144
utilruntime.HandleError(fmt.Errorf("Tombstone contained object that is not a runtime.Object %#v", obj))
145+
return
140146
}
141147
}
142148

143149
for _, originObj := range originContainerObj.RoleBindings {
144-
c.originIndexer.Add(originObj)
150+
c.originIndexer.Delete(originObj)
145151
key, err := controller.KeyFunc(originObj)
146152
if err != nil {
147153
utilruntime.HandleError(err)

pkg/authorization/controller/authorizationsync/origin_to_rbac_role_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ func (c *OriginRoleToRBACRoleController) syncRole(key string) error {
7575
// if the origin role doesn't exist, just delete the rbac role
7676
if apierrors.IsNotFound(originErr) {
7777
// orphan on delete to minimize fanout. We ought to clean the rest via controller too.
78-
return c.rbacClient.Roles(namespace).Delete(name, nil)
78+
deleteErr := c.rbacClient.Roles(namespace).Delete(name, nil)
79+
if apierrors.IsNotFound(deleteErr) {
80+
return nil
81+
}
82+
return deleteErr
7983
}
8084

8185
// determine if we need to create, update or do nothing
@@ -138,15 +142,17 @@ func (c *OriginRoleToRBACRoleController) policyEventHandler() cache.ResourceEven
138142
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
139143
if !ok {
140144
utilruntime.HandleError(fmt.Errorf("Couldn't get object from tombstone %#v", obj))
145+
return
141146
}
142147
originContainerObj, ok = tombstone.Obj.(*authorizationapi.Policy)
143148
if !ok {
144149
utilruntime.HandleError(fmt.Errorf("Tombstone contained object that is not a runtime.Object %#v", obj))
150+
return
145151
}
146152
}
147153

148154
for _, originObj := range originContainerObj.Roles {
149-
c.originIndexer.Add(originObj)
155+
c.originIndexer.Delete(originObj)
150156
key, err := controller.KeyFunc(originObj)
151157
if err != nil {
152158
utilruntime.HandleError(err)

pkg/authorization/controller/authorizationsync/origin_to_rbac_rolebinding_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ func (c *OriginRoleBindingToRBACRoleBindingController) syncRoleBinding(key strin
7575
// if the origin roleBinding doesn't exist, just delete the rbac roleBinding
7676
if apierrors.IsNotFound(originErr) {
7777
// orphan on delete to minimize fanout. We ought to clean the rest via controller too.
78-
return c.rbacClient.RoleBindings(namespace).Delete(name, nil)
78+
deleteErr := c.rbacClient.RoleBindings(namespace).Delete(name, nil)
79+
if apierrors.IsNotFound(deleteErr) {
80+
return nil
81+
}
82+
return deleteErr
7983
}
8084

8185
// determine if we need to create, update or do nothing
@@ -138,15 +142,17 @@ func (c *OriginRoleBindingToRBACRoleBindingController) policyBindingEventHandler
138142
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
139143
if !ok {
140144
utilruntime.HandleError(fmt.Errorf("Couldn't get object from tombstone %#v", obj))
145+
return
141146
}
142147
originContainerObj, ok = tombstone.Obj.(*authorizationapi.PolicyBinding)
143148
if !ok {
144149
utilruntime.HandleError(fmt.Errorf("Tombstone contained object that is not a runtime.Object %#v", obj))
150+
return
145151
}
146152
}
147153

148154
for _, originObj := range originContainerObj.RoleBindings {
149-
c.originIndexer.Add(originObj)
155+
c.originIndexer.Delete(originObj)
150156
key, err := controller.KeyFunc(originObj)
151157
if err != nil {
152158
utilruntime.HandleError(err)

0 commit comments

Comments
 (0)