Skip to content

Commit

Permalink
Merge pull request #240 from joelsmith/kedamain
Browse files Browse the repository at this point in the history
Reconcile changes to audit policy
  • Loading branch information
joelsmith authored Aug 6, 2024
2 parents 35181ac + af5b219 commit f0e1d40
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions controllers/keda/kedacontroller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,21 +759,21 @@ func (r *KedaControllerReconciler) ensureMetricsServerAuditLogPolicyConfigMap(ct
realPolicy.Rules = policy.Rules
realPolicy.OmitStages = policy.OmitStages
realPolicy.OmitManagedFields = policy.OmitManagedFields
dataBytes, err := yaml.Marshal(realPolicy)
if err != nil {
logger.Error(err, "failed to Marshal Auditlog Policy struct")
return err
}

configMap := &corev1.ConfigMap{}
err := r.Client.Get(ctx, types.NamespacedName{Name: auditlogPolicyConfigMap, Namespace: instance.Namespace}, configMap)
err = r.Client.Get(ctx, types.NamespacedName{Name: auditlogPolicyConfigMap, Namespace: instance.Namespace}, configMap)
if err != nil {
if errors.IsNotFound(err) {
// create ConfigMap if not found
configMap.Name = auditlogPolicyConfigMap
configMap.Namespace = instance.Namespace
configMap.Data = make(map[string]string)

dataBytes, err := yaml.Marshal(realPolicy)
if err != nil {
logger.Error(err, "failed to Marshal Auditlog Policy struct")
return err
}
configMap.Data[auditPolicyFile] = string(dataBytes)

if err := controllerutil.SetControllerReference(instance, configMap, r.Scheme); err != nil {
Expand All @@ -794,6 +794,10 @@ func (r *KedaControllerReconciler) ensureMetricsServerAuditLogPolicyConfigMap(ct
}

configMapUpdate := false
if configMap.Data[auditPolicyFile] != string(dataBytes) {
configMapUpdate = true
configMap.Data[auditPolicyFile] = string(dataBytes)
}

if err := controllerutil.SetControllerReference(instance, configMap, r.Scheme); err != nil {
if !goerrors.Is(err, &controllerutil.AlreadyOwnedError{}) {
Expand Down

0 comments on commit f0e1d40

Please sign in to comment.