Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion controllers/cloud_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package controllers

import (
"context"
"encoding/json"
"errors"
"fmt"

Expand Down Expand Up @@ -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
}
Expand All @@ -60,6 +63,18 @@ 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 && 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))
}
Comment on lines +67 to +77
if err != nil {
statusErr := r.patchStatusAndCondition(ctx, mcp, v1alpha1.FailedReconcileStatus, metav1.Condition{
Type: CloudProfileAppliedConditionType,
Expand All @@ -72,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)
Expand Down
5 changes: 5 additions & 0 deletions controllers/managedcloudprofile_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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))
}

Expand Down