Skip to content

Commit 95be886

Browse files
rksharma95daemon1024
authored andcommitted
log status update and csp policy messages on change only
Signed-off-by: rksharma95 <[email protected]>
1 parent 938a05e commit 95be886

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pkg/KubeArmorOperator/internal/controller/cluster.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -927,14 +927,14 @@ func (clusterWatcher *ClusterWatcher) UpdateCrdStatus(cfg, phase, message string
927927
// retry the update
928928
return false, nil
929929
}
930+
clusterWatcher.Log.Info("Config CR Status Updated Successfully")
930931
}
931932
return true, nil
932933
})
933934
if err != nil {
934935
clusterWatcher.Log.Errorf("Error updating the ConfigCR status %s", err)
935936
return
936937
}
937-
clusterWatcher.Log.Info("Config CR Status Updated Successfully")
938938
}
939939

940940
func (clusterWatcher *ClusterWatcher) UpdateKubeArmorConfigMap(cfg *opv1.KubeArmorConfig) {
@@ -1141,19 +1141,19 @@ func (clusterWatcher *ClusterWatcher) WatchRecommendedPolicies() error {
11411141
var yamlBytes []byte
11421142
policies, err := recommend.CRDFs.ReadDir(".")
11431143
if err != nil {
1144-
clusterWatcher.Log.Warnf("error reading policies FS", err)
1144+
clusterWatcher.Log.Warnf("error reading policies FS %s", err)
11451145
return err
11461146
}
11471147
for _, policy := range policies {
11481148
csp := &secv1.KubeArmorClusterPolicy{}
11491149
if !policy.IsDir() {
11501150
yamlBytes, err = recommend.CRDFs.ReadFile(policy.Name())
11511151
if err != nil {
1152-
clusterWatcher.Log.Warnf("error reading csp", policy.Name())
1152+
clusterWatcher.Log.Warnf("error reading csp %s", policy.Name())
11531153
continue
11541154
}
11551155
if err := runtime.DecodeInto(scheme.Codecs.UniversalDeserializer(), yamlBytes, csp); err != nil {
1156-
clusterWatcher.Log.Warnf("error decoding csp", policy.Name())
1156+
clusterWatcher.Log.Warnf("error decoding csp %s", policy.Name())
11571157
continue
11581158
}
11591159
}
@@ -1163,31 +1163,31 @@ func (clusterWatcher *ClusterWatcher) WatchRecommendedPolicies() error {
11631163
clusterWatcher.Log.Infof("excluding csp ", csp.Name)
11641164
err = clusterWatcher.Secv1Client.SecurityV1().KubeArmorClusterPolicies().Delete(context.Background(), csp.GetName(), metav1.DeleteOptions{})
11651165
if err != nil && !metav1errors.IsNotFound(err) {
1166-
clusterWatcher.Log.Warnf("error deleting csp", csp.GetName())
1166+
clusterWatcher.Log.Warnf("error deleting csp %s", csp.GetName())
11671167
} else if err == nil {
1168-
clusterWatcher.Log.Infof("deleted csp", csp.GetName())
1168+
clusterWatcher.Log.Infof("deleted csp :%s", csp.GetName())
11691169
}
11701170
continue
11711171
}
11721172
csp.Spec.Selector.MatchExpressions = common.RecommendedPolicies.MatchExpressions
11731173
_, err = clusterWatcher.Secv1Client.SecurityV1().KubeArmorClusterPolicies().Create(context.Background(), csp, metav1.CreateOptions{})
11741174
if err != nil && !metav1errors.IsAlreadyExists(err) {
1175-
clusterWatcher.Log.Warnf("error creating csp", csp.GetName())
1175+
clusterWatcher.Log.Warnf("error creating csp %s", csp.GetName())
11761176
continue
11771177
} else if metav1errors.IsAlreadyExists(err) {
11781178
pol, err := clusterWatcher.Secv1Client.SecurityV1().KubeArmorClusterPolicies().Get(context.Background(), csp.GetName(), metav1.GetOptions{})
11791179
if err != nil {
1180-
clusterWatcher.Log.Warnf("error getting csp", csp.GetName())
1180+
clusterWatcher.Log.Warnf("error getting csp %s", csp.GetName())
11811181
continue
11821182
}
11831183
if !reflect.DeepEqual(pol.Spec.Selector.MatchExpressions, common.RecommendedPolicies.MatchExpressions) {
11841184
pol.Spec.Selector.MatchExpressions = common.RecommendedPolicies.MatchExpressions
11851185
_, err := clusterWatcher.Secv1Client.SecurityV1().KubeArmorClusterPolicies().Update(context.Background(), pol, metav1.UpdateOptions{})
11861186
if err != nil {
1187-
clusterWatcher.Log.Warnf("error updating csp", csp.GetName())
1187+
clusterWatcher.Log.Warnf("error updating csp %s", csp.GetName())
11881188
continue
11891189
} else {
1190-
clusterWatcher.Log.Info("updated csp", csp.GetName())
1190+
clusterWatcher.Log.Infof("updated csp %s", csp.GetName())
11911191
}
11921192
}
11931193
} else {
@@ -1197,10 +1197,10 @@ func (clusterWatcher *ClusterWatcher) WatchRecommendedPolicies() error {
11971197
if !policy.IsDir() {
11981198
err = clusterWatcher.Secv1Client.SecurityV1().KubeArmorClusterPolicies().Delete(context.Background(), csp.GetName(), metav1.DeleteOptions{})
11991199
if err != nil && !metav1errors.IsNotFound(err) {
1200-
clusterWatcher.Log.Warnf("error deleting csp", csp.GetName())
1200+
clusterWatcher.Log.Warnf("error deleting csp %s", csp.GetName())
12011201
continue
1202-
} else {
1203-
clusterWatcher.Log.Info("deleted csp", csp.GetName())
1202+
} else if err == nil {
1203+
clusterWatcher.Log.Info("deleted csp %s", csp.GetName())
12041204
}
12051205
}
12061206
}

pkg/KubeArmorOperator/internal/controller/resources.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func deploySnitch(nodename string, runtime string) *batchv1.Job {
322322
VolumeSource: corev1.VolumeSource{
323323
HostPath: &corev1.HostPathVolumeSource{
324324
Path: "/etc/apparmor.d/",
325-
Type: &common.HostPathDirectoryOrCreate,
325+
Type: &common.HostPathDirectory,
326326
},
327327
},
328328
},

0 commit comments

Comments
 (0)