Skip to content

Commit 99abefa

Browse files
rootxrishabhdaemon1024
authored andcommitted
fix(operator): recommended policies deletion logic
Signed-off-by: rootxrishabh <risrock02@gmail.com> Signed-off-by: Rishabh Soni <risrock02@gmail.com>
1 parent 01f6823 commit 99abefa

File tree

1 file changed

+2
-1
lines changed
  • pkg/KubeArmorOperator/internal/controller

1 file changed

+2
-1
lines changed

pkg/KubeArmorOperator/internal/controller/cluster.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ func (clusterWatcher *ClusterWatcher) WatchRecommendedPolicies() error {
11981198
continue
11991199
}
12001200
csp.Spec.Selector.MatchExpressions = common.RecommendedPolicies.MatchExpressions
1201+
csp.Annotations["app.kubernetes.io/managed-by"] = "Kubearmor Operator"
12011202
_, err = clusterWatcher.Secv1Client.SecurityV1().KubeArmorClusterPolicies().Create(context.Background(), csp, metav1.CreateOptions{})
12021203
if err != nil && !metav1errors.IsAlreadyExists(err) {
12031204
clusterWatcher.Log.Warnf("error creating csp %s", csp.GetName())
@@ -1222,7 +1223,7 @@ func (clusterWatcher *ClusterWatcher) WatchRecommendedPolicies() error {
12221223
clusterWatcher.Log.Info("created csp", csp.GetName())
12231224
}
12241225
case false:
1225-
if !policy.IsDir() {
1226+
if !policy.IsDir() && csp.Annotations["app.kubernetes.io/managed-by"] == "Kubearmor Operator" {
12261227
err = clusterWatcher.Secv1Client.SecurityV1().KubeArmorClusterPolicies().Delete(context.Background(), csp.GetName(), metav1.DeleteOptions{})
12271228
if err != nil && !metav1errors.IsNotFound(err) {
12281229
clusterWatcher.Log.Warnf("error deleting csp %s", csp.GetName())

0 commit comments

Comments
 (0)