diff --git a/controllers/job/job_controller.go b/controllers/job/job_controller.go index 2287eaad..42f3a6b7 100644 --- a/controllers/job/job_controller.go +++ b/controllers/job/job_controller.go @@ -208,8 +208,6 @@ func (in *ReconcileJob) createJob(ctx context.Context, deployment coh.CoherenceR } func (in *ReconcileJob) updateJob(ctx context.Context, deployment coh.CoherenceResource, job *batchv1.Job, storage utils.Storage, logger logr.Logger) (reconcile.Result, error) { - logger.Info("Updating job") - // get the desired resource state from the store resource, found := storage.GetLatest().GetResource(coh.ResourceTypeJob, job.Name) if !found { @@ -231,6 +229,10 @@ func (in *ReconcileJob) updateJob(ctx context.Context, deployment coh.CoherenceR // Patch the Job if required, returning a bool to indicate whether a patch was applied. func (in *ReconcileJob) patchJob(ctx context.Context, deployment coh.CoherenceResource, job, desired *batchv1.Job, storage utils.Storage, logger logr.Logger) (reconcile.Result, error) { hashMatches := in.HashLabelsMatch(job, storage) + if hashMatches { + return reconcile.Result{}, nil + } + resource, _ := storage.GetPrevious().GetResource(coh.ResourceTypeJob, job.GetName()) original := &batchv1.Job{} @@ -320,8 +322,6 @@ func (in *ReconcileJob) patchJob(ctx context.Context, deployment coh.CoherenceRe return reconcile.Result{}, nil } - logger.Info("Updating Job") - // now apply the patch patched, err := in.ApplyThreeWayPatchWithCallback(ctx, current.GetName(), current, patch, data, callback) @@ -334,10 +334,6 @@ func (in *ReconcileJob) patchJob(ctx context.Context, deployment coh.CoherenceRe return reconcile.Result{Requeue: true}, nil } - if patched && hashMatches { - logger.Info("Patch applied to job even though hashes matched (possible external update)") - } - return reconcile.Result{}, nil } diff --git a/controllers/reconciler/base_controller.go b/controllers/reconciler/base_controller.go index 4cef12f1..46759a15 100644 --- a/controllers/reconciler/base_controller.go +++ b/controllers/reconciler/base_controller.go @@ -434,7 +434,7 @@ func (in *CommonReconciler) ApplyThreeWayPatchWithCallback(ctx context.Context, callback() } - in.GetLog().WithValues().Info(fmt.Sprintf("Patching %s/%s with %s", kind, name, string(data))) + in.GetLog().WithValues().Info(fmt.Sprintf("Patching %s/%s", kind, name), "Patch", string(data)) err := in.GetManager().GetClient().Patch(ctx, current, patch) if err != nil { return false, errors.Wrapf(err, "failed to patch %s/%s with %s", kind, name, string(data)) @@ -461,7 +461,7 @@ func (in *CommonReconciler) CreateThreeWayPatch(name string, original, desired, // log the patch kind := current.GetObjectKind().GroupVersionKind().Kind - in.GetLog().Info(fmt.Sprintf("Created patch for %s/%s %s", kind, name, string(data))) + in.GetLog().Info(fmt.Sprintf("Created patch for %s/%s", kind, name), "Patch", string(data)) return client.RawPatch(in.patchType, data), data, nil } @@ -877,9 +877,12 @@ func (in *ReconcileSecondaryResource) Delete(ctx context.Context, namespace, nam // Update possibly updates the resource if the current state differs from the desired state. func (in *ReconcileSecondaryResource) Update(ctx context.Context, name string, current client.Object, storage utils.Storage, logger logr.Logger) error { - logger.Info(fmt.Sprintf("Updating %v", in.Kind)) - hashMatches := in.HashLabelsMatch(current, storage) + if hashMatches { + logger.Info(fmt.Sprintf("Nothing to update for %v, hashes match", in.Kind)) + return nil + } + original, _ := storage.GetPrevious().GetResource(in.Kind, name) desired, found := storage.GetLatest().GetResource(in.Kind, name) if !found { @@ -889,7 +892,7 @@ func (in *ReconcileSecondaryResource) Update(ctx context.Context, name string, c patched, err := in.ThreeWayPatch(ctx, name, current, original.Spec, desired.Spec) if patched && hashMatches { - logger.Info(fmt.Sprintf("Patch applied to %v even though hashes matched (possible external update)", in.Kind)) + logger.Info(fmt.Sprintf("Patch applied to %v", in.Kind)) } return err } diff --git a/controllers/servicemonitor/servicemonitor_controller.go b/controllers/servicemonitor/servicemonitor_controller.go index 3796e2b8..278dabd2 100644 --- a/controllers/servicemonitor/servicemonitor_controller.go +++ b/controllers/servicemonitor/servicemonitor_controller.go @@ -186,9 +186,13 @@ func (in *ReconcileServiceMonitor) CreateServiceMonitor(ctx context.Context, nam // UpdateServiceMonitor possibly updates the ServiceMonitor if the current state differs from the desired state. func (in *ReconcileServiceMonitor) UpdateServiceMonitor(ctx context.Context, namespace, name string, current *monitoring.ServiceMonitor, storage utils.Storage, logger logr.Logger) error { - logger.Info(fmt.Sprintf("Updating %v", in.Kind)) - hashMatches := in.HashLabelsMatch(current, storage) + if hashMatches { + logger.Info(fmt.Sprintf("Nothing to update for %v, hashes match", in.Kind)) + return nil + } + + logger.Info(fmt.Sprintf("Updating %v", in.Kind)) original, _ := storage.GetPrevious().GetResource(in.Kind, name) desired, found := storage.GetLatest().GetResource(in.Kind, name) if !found { diff --git a/controllers/statefulset/statefulset_controller.go b/controllers/statefulset/statefulset_controller.go index 8dae5a70..bcefb12a 100644 --- a/controllers/statefulset/statefulset_controller.go +++ b/controllers/statefulset/statefulset_controller.go @@ -298,8 +298,6 @@ func (in *ReconcileStatefulSet) createStatefulSet(ctx context.Context, deploymen } func (in *ReconcileStatefulSet) updateStatefulSet(ctx context.Context, deployment coh.CoherenceResource, current *appsv1.StatefulSet, storage utils.Storage, logger logr.Logger) (reconcile.Result, error) { - logger.Info("Updating statefulSet") - var err error result := reconcile.Result{} @@ -350,6 +348,10 @@ func (in *ReconcileStatefulSet) updateStatefulSet(ctx context.Context, deploymen // Patch the StatefulSet if required, returning a bool to indicate whether a patch was applied. func (in *ReconcileStatefulSet) patchStatefulSet(ctx context.Context, deployment coh.CoherenceResource, current, desired *appsv1.StatefulSet, storage utils.Storage, logger logr.Logger) (reconcile.Result, error) { hashMatches := in.HashLabelsMatch(current, storage) + if hashMatches { + return reconcile.Result{}, nil + } + resource, _ := storage.GetPrevious().GetResource(coh.ResourceTypeStatefulSet, current.GetName()) original := &appsv1.StatefulSet{} @@ -452,8 +454,6 @@ func (in *ReconcileStatefulSet) patchStatefulSet(ctx context.Context, deployment return reconcile.Result{}, nil } - logger.Info("Updating StatefulSet") - if deploymentSpec.CheckHABeforeUpdate() { // Check we have the expected number of ready replicas if readyReplicas != currentReplicas { @@ -498,10 +498,6 @@ func (in *ReconcileStatefulSet) patchStatefulSet(ctx context.Context, deployment return reconcile.Result{Requeue: true}, nil } - if patched && hashMatches { - logger.Info("Patch applied to statefulSet even though hashes matched (possible external update)") - } - return reconcile.Result{}, nil }