Skip to content

Commit dd6b981

Browse files
committed
fix: skip namespace check on cluster scoped rbac resources for auth reconcile
Signed-off-by: Christopher Coco <[email protected]>
1 parent e8539be commit dd6b981

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

gitops-engine/pkg/utils/kube/resource_ops.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,14 @@ func (k *kubectlResourceOperations) authReconcile(ctx context.Context, obj *unst
603603
if err != nil {
604604
return "", fmt.Errorf("error creating kube client: %w", err)
605605
}
606+
607+
clusterScoped := obj.GetKind() == "ClusterRole" || obj.GetKind() == "ClusterRoleBinding"
608+
606609
// `kubectl auth reconcile` has a side effect of auto-creating namespaces if it doesn't exist.
607610
// See: https://github.com/kubernetes/kubernetes/issues/71185. This is behavior which we do
608611
// not want. We need to check if the namespace exists, before know if it is safe to run this
609612
// command. Skip this for dryRuns.
610-
if dryRunStrategy == cmdutil.DryRunNone && obj.GetNamespace() != "" {
613+
if dryRunStrategy == cmdutil.DryRunNone && obj.GetNamespace() != "" && !clusterScoped {
611614
_, err = kubeClient.CoreV1().Namespaces().Get(ctx, obj.GetNamespace(), metav1.GetOptions{})
612615
if err != nil {
613616
return "", fmt.Errorf("error getting namespace %s: %w", obj.GetNamespace(), err)

0 commit comments

Comments
 (0)