Skip to content

Commit

Permalink
fix(operator): recommended policies deletion logic
Browse files Browse the repository at this point in the history
Signed-off-by: rootxrishabh <[email protected]>
Signed-off-by: Rishabh Soni <[email protected]>
  • Loading branch information
rootxrishabh authored and daemon1024 committed Feb 28, 2025
1 parent 01f6823 commit 99abefa
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/KubeArmorOperator/internal/controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,7 @@ func (clusterWatcher *ClusterWatcher) WatchRecommendedPolicies() error {
continue
}
csp.Spec.Selector.MatchExpressions = common.RecommendedPolicies.MatchExpressions
csp.Annotations["app.kubernetes.io/managed-by"] = "Kubearmor Operator"
_, err = clusterWatcher.Secv1Client.SecurityV1().KubeArmorClusterPolicies().Create(context.Background(), csp, metav1.CreateOptions{})
if err != nil && !metav1errors.IsAlreadyExists(err) {
clusterWatcher.Log.Warnf("error creating csp %s", csp.GetName())
Expand All @@ -1222,7 +1223,7 @@ func (clusterWatcher *ClusterWatcher) WatchRecommendedPolicies() error {
clusterWatcher.Log.Info("created csp", csp.GetName())
}
case false:
if !policy.IsDir() {
if !policy.IsDir() && csp.Annotations["app.kubernetes.io/managed-by"] == "Kubearmor Operator" {
err = clusterWatcher.Secv1Client.SecurityV1().KubeArmorClusterPolicies().Delete(context.Background(), csp.GetName(), metav1.DeleteOptions{})
if err != nil && !metav1errors.IsNotFound(err) {
clusterWatcher.Log.Warnf("error deleting csp %s", csp.GetName())
Expand Down

0 comments on commit 99abefa

Please sign in to comment.