Skip to content

Commit

Permalink
Merge branch 'master' into appstudio-gitops-operator
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-veeramalla committed Sep 17, 2024
2 parents ec7b865 + b50e9e1 commit 743af15
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions controllers/gitopsservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,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 @@ -369,6 +377,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 @@ -920,3 +937,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
}

0 comments on commit 743af15

Please sign in to comment.