diff --git a/controllers/cloud_profile.go b/controllers/cloud_profile.go index 30be5b4..29549bb 100644 --- a/controllers/cloud_profile.go +++ b/controllers/cloud_profile.go @@ -37,7 +37,7 @@ func (r *Reconciler) reconcileCloudProfile(ctx context.Context, log logr.Logger, var cloudProfile gardenerv1beta1.CloudProfile cloudProfile.Name = mcp.Name - _, err := controllerutil.CreateOrPatch(ctx, r.Client, &cloudProfile, func() error { + op, err := controllerutil.CreateOrPatch(ctx, r.Client, &cloudProfile, func() error { if err := controllerutil.SetControllerReference(mcp, &cloudProfile, r.Scheme()); err != nil { return err } @@ -60,6 +60,7 @@ func (r *Reconciler) reconcileCloudProfile(ctx context.Context, log logr.Logger, gardenerv1beta1.SetObjectDefaults_CloudProfile(&cloudProfile) return errors.Join(errs...) }) + log.V(1).Info("CloudProfile patch operation", "operation", op) if err != nil { statusErr := r.patchStatusAndCondition(ctx, mcp, v1alpha1.FailedReconcileStatus, metav1.Condition{ Type: CloudProfileAppliedConditionType, @@ -72,6 +73,7 @@ func (r *Reconciler) reconcileCloudProfile(ctx context.Context, log logr.Logger, return fmt.Errorf("failed to patch ManagedCloudProfile status: %w", statusErr) } if apierrors.IsInvalid(err) { + log.Error(err, "CloudProfile is invalid, skipping retry") return nil } return fmt.Errorf("failed to create or patch CloudProfile: %w", err) diff --git a/controllers/managedcloudprofile_controller.go b/controllers/managedcloudprofile_controller.go index 0963cb7..201083e 100644 --- a/controllers/managedcloudprofile_controller.go +++ b/controllers/managedcloudprofile_controller.go @@ -49,6 +49,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, client.IgnoreNotFound(err) } + log.V(1).Info("reconcile triggered", "generation", mcp.Generation, "resourceVersion", mcp.ResourceVersion) + if err := r.reconcileCloudProfile(ctx, log, &mcp); err != nil { return ctrl.Result{}, err } @@ -61,14 +63,17 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } func (r *Reconciler) patchStatusAndCondition(ctx context.Context, mcp *v1alpha1.ManagedCloudProfile, status v1alpha1.ReconcileStatus, cond metav1.Condition) error { + log := ctrl.LoggerFrom(ctx) original := mcp.DeepCopy() mcp.Status.Status = status if cond.Type != "" { mcp.Status.Conditions = applyCondition(mcp.Status.Conditions, cond) } if equality.Semantic.DeepEqual(original.Status, mcp.Status) { + log.V(1).Info("MCP status patch skipped, no change") return nil } + log.V(1).Info("MCP status patch issued", "status", status, "condition", cond.Type) return r.Status().Patch(ctx, mcp, client.MergeFrom(original)) }