8000 fix: Immediately patch lastPrepareError instead of doing it at the end of the reconciliation by codablock · Pull Request #1315 · kluctl/kluctl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Immediately patch lastPrepareError instead of doing it at the end of the reconciliation #1315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
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
7 cha 10000 nges: 5 additions & 2 deletions pkg/controllers/kluctldeployment_controller_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ func (r *KluctlDeploymentReconciler) reconcileManualRequest(ctx context.Context,
return false, nil
}

obj.Status.LastPrepareError = ""

doError := func(resultId string, err error) (bool, error) {
err2 := r.patchFailPrepare(ctx, obj, err)
if err2 != nil {
Expand All @@ -205,6 +203,11 @@ func (r *KluctlDeploymentReconciler) reconcileManualRequest(ctx context.Context,
return doError("", err)
}

err = r.patchStatus(ctx, client.ObjectKeyFromObject(obj), func(status *kluctlv1.KluctlDeploymentStatus) error {
status.LastPrepareError = ""
return nil
})

objectsHash, err := targetContext.DeploymentCollection.CalcObjectsHash()
if err != nil {
return doError("", err)
Expand Down
23 changes: 19 additions & 4 deletions pkg/controllers/kluctldeployment_controller_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,30 @@ func (r *KluctlDeploymentReconciler) patchFail(ctx context.Context, obj *kluctlv
}

func (r *KluctlDeploymentReconciler) patchFailPrepare(ctx context.Context, obj *kluctlv1.KluctlDeployment, err error) error {
obj.Status.LastPrepareError = err.Error()
patchErr1 := r.patchStatus(ctx, client.ObjectKeyFromObject(obj), func(status *kluctlv1.KluctlDeploymentStatus) error {
status.LastPrepareError = err.Error()
return nil
})

var err2 *multierror.Error
var statusErr error
if errors2.As(err, &err2) {
// prepare errors tend to be extremely long, which makes tools like k9s unusable
err = fmt.Errorf("prepare failed with %d errors. Check status.lastPrepareError for details", len(err2.Errors))
statusErr = fmt.Errorf("prepare failed with %d errors. Check status.lastPrepareError for details", len(err2.Errors))
} else {
err = fmt.Errorf("prepare failed. Check status.lastPrepareError for details")
statusErr = fmt.Errorf("prepare failed. Check status.lastPrepareError for details")
}
return r.patchFail(ctx, obj, kluctlv1.PrepareFailedReason, err)

patchErr2 := r.patchFail(ctx, obj, kluctlv1.PrepareFailedReason, statusErr)

if patchErr1 != nil {
err = multierror.Append(err, patchErr1)
}
if patchErr2 != nil {
err = multierror.Append(err, patchErr2)
}

return err
}

func (r *KluctlDeploymentReconciler) patchProgressingCondition(ctx context.Context, obj *kluctlv1.KluctlDeployment, message string, keepOldReadyStatus bool) error {
Expand Down
0