From c6c924fdde90153cef476a1b74f2a14a7ee10446 Mon Sep 17 00:00:00 2001 From: Aliaksei Dziauho Date: Thu, 3 Sep 2026 16:53:46 +0200 Subject: [PATCH 1/2] add debug logs Signed-off-by: Aliaksei Dziauho --- controllers/cloud_profile.go | 11 ++++++++++- controllers/managedcloudprofile_controller.go | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/controllers/cloud_profile.go b/controllers/cloud_profile.go index 30be5b4..4c9a7ee 100644 --- a/controllers/cloud_profile.go +++ b/controllers/cloud_profile.go @@ -4,6 +4,7 @@ package controllers import ( "context" + "encoding/json" "errors" "fmt" @@ -37,7 +38,9 @@ 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 { + var specBefore gardenerv1beta1.CloudProfileSpec + op, err := controllerutil.CreateOrPatch(ctx, r.Client, &cloudProfile, func() error { + specBefore = *cloudProfile.Spec.DeepCopy() if err := controllerutil.SetControllerReference(mcp, &cloudProfile, r.Scheme()); err != nil { return err } @@ -60,6 +63,12 @@ func (r *Reconciler) reconcileCloudProfile(ctx context.Context, log logr.Logger, gardenerv1beta1.SetObjectDefaults_CloudProfile(&cloudProfile) return errors.Join(errs...) }) + log.Info("CloudProfile patch operation", "operation", op) + if op == controllerutil.OperationResultUpdated { + beforeJSON, _ := json.Marshal(specBefore) + afterJSON, _ := json.Marshal(cloudProfile.Spec) + log.V(1).Info("CloudProfile spec diff", "before", string(beforeJSON), "after", string(afterJSON)) + } if err != nil { statusErr := r.patchStatusAndCondition(ctx, mcp, v1alpha1.FailedReconcileStatus, metav1.Condition{ Type: CloudProfileAppliedConditionType, 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)) } From 797770fd85f843a2565bb8e9acd35d08489d39a2 Mon Sep 17 00:00:00 2001 From: Aliaksei Dziauho Date: Thu, 3 Sep 2026 17:07:04 +0200 Subject: [PATCH 2/2] log spec diff Signed-off-by: Aliaksei Dziauho --- controllers/cloud_profile.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/controllers/cloud_profile.go b/controllers/cloud_profile.go index 4c9a7ee..9027663 100644 --- a/controllers/cloud_profile.go +++ b/controllers/cloud_profile.go @@ -64,9 +64,15 @@ func (r *Reconciler) reconcileCloudProfile(ctx context.Context, log logr.Logger, return errors.Join(errs...) }) log.Info("CloudProfile patch operation", "operation", op) - if op == controllerutil.OperationResultUpdated { - beforeJSON, _ := json.Marshal(specBefore) - afterJSON, _ := json.Marshal(cloudProfile.Spec) + if op == controllerutil.OperationResultUpdated && log.V(1).Enabled() { + beforeJSON, err := json.Marshal(specBefore) + if err != nil { + log.Error(err, "failed to marshal spec before") + } + afterJSON, err := json.Marshal(cloudProfile.Spec) + if err != nil { + log.Error(err, "failed to marshal spec after") + } log.V(1).Info("CloudProfile spec diff", "before", string(beforeJSON), "after", string(afterJSON)) } if err != nil { @@ -81,6 +87,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)