Skip to content

Commit 259462e

Browse files
vparfonovclaude
andcommitted
LOG-9424: Make legacy SCC role cleanup non-blocking
The cleanup of old {sa}-scc Role resources introduced in #3308 uses k8sClient.List which goes through the namespace-scoped cache. When a CLF is created in a namespace the cache has not yet indexed, the List fails with "unknown namespace for the cache", blocking the entire reconciliation and preventing collector workloads from being created. Extract cleanup into a best-effort helper that logs errors instead of returning them. The old role will be cleaned up on the next successful reconciliation cycle. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ba8a51b commit 259462e

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

internal/auth/rbac.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package auth
33
import (
44
"context"
55
"fmt"
6+
7+
log "github.com/ViaQ/logerr/v2/log/static"
68
"github.com/openshift/cluster-logging-operator/internal/reconcile"
79
"github.com/openshift/cluster-logging-operator/internal/runtime"
810
"github.com/openshift/cluster-logging-operator/internal/utils"
@@ -27,32 +29,32 @@ func ReconcileRBAC(k8sClient client.Client, rbacName, saNamespace, saName string
2729
return err
2830
}
2931

30-
// Cleanup old resources with previous naming scheme
32+
// Best-effort cleanup of old resources with previous naming scheme.
33+
// Errors are logged but not returned to avoid blocking reconciliation
34+
// (e.g., namespace-scoped cache may not know about newly created namespaces).
35+
cleanupLegacySCCRole(k8sClient, saNamespace, saName)
36+
37+
return nil
38+
}
39+
40+
func cleanupLegacySCCRole(k8sClient client.Client, saNamespace, saName string) {
3141
oldRoleName := fmt.Sprintf("%s-scc", saName)
3242

33-
// List all RoleBindings in the namespace to check if any reference the old role
3443
roleBindings := &rbacv1.RoleBindingList{}
3544
if err := k8sClient.List(context.TODO(), roleBindings, client.InNamespace(saNamespace)); err != nil {
36-
return err
45+
log.V(3).Info("skipping legacy SCC role cleanup: unable to list rolebindings", "namespace", saNamespace, "error", err)
46+
return
3747
}
3848

39-
// Check if any RoleBinding references the old role
40-
hasReferences := false
4149
for _, rb := range roleBindings.Items {
4250
if rb.RoleRef.Name == oldRoleName {
43-
hasReferences = true
44-
break
51+
return
4552
}
4653
}
4754

48-
// Only delete the old role if no RoleBindings reference it
49-
if !hasReferences {
50-
if err := reconcile.DeleteRole(k8sClient, saNamespace, oldRoleName); err != nil {
51-
return err
52-
}
55+
if err := reconcile.DeleteRole(k8sClient, saNamespace, oldRoleName); err != nil {
56+
log.V(3).Info("skipping legacy SCC role cleanup: unable to delete old role", "namespace", saNamespace, "role", oldRoleName, "error", err)
5357
}
54-
55-
return nil
5658
}
5759

5860
// NewMetaDataReaderClusterRoleBinding stubs a clusterrolebinding to allow reading of pod metadata (i.e. labels)

0 commit comments

Comments
 (0)