Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions controllers/gitopsservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ func (r *ReconcileGitopsService) Reconcile(ctx context.Context, request reconcil
} else {
return reconcile.Result{}, err
}
} else {
needUpdate, updateNameSpace := ensurePodSecurityLabels(namespaceRef)
if needUpdate {
err = r.Client.Update(context.TODO(), updateNameSpace)
if err != nil {
return reconcile.Result{}, err
}
}
}

gitopsserviceNamespacedName := types.NamespacedName{
Expand Down Expand Up @@ -372,6 +380,15 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
return reconcile.Result{}, err
}
}

needUpdate, updateNameSpace := ensurePodSecurityLabels(argocdNS)
if needUpdate {
err = r.Client.Update(context.TODO(), updateNameSpace)
if err != nil {
return reconcile.Result{}, err
}
}

}

// Set GitopsService instance as the owner and controller
Expand Down Expand Up @@ -917,3 +934,25 @@ func policyRuleForBackendServiceClusterRole() []rbacv1.PolicyRule {
},
}
}

func ensurePodSecurityLabels(namespace *corev1.Namespace) (bool, *corev1.Namespace) {

pssLabels := map[string]string{
"pod-security.kubernetes.io/enforce": "restricted",
"pod-security.kubernetes.io/enforce-version": "v1.29",
"pod-security.kubernetes.io/audit": "restricted",
"pod-security.kubernetes.io/audit-version": "latest",
"pod-security.kubernetes.io/warn": "restricted",
"pod-security.kubernetes.io/warn-version": "latest",
}

changed := false
for pssKey, pssVal := range pssLabels {
if nsVal, exists := namespace.Labels[pssKey]; !exists || nsVal != pssVal {
namespace.Labels[pssKey] = pssVal
changed = true
}

}
return changed, namespace
}