Skip to content
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

improved status logging #742

Merged
merged 2 commits into from
Nov 7, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
## Unreleased

- Improved support for using custom program sources. [#741](https://github.com/pulumi/pulumi-kubernetes-operator/pull/741)
- Improved Status logging. [#742](https://github.com/pulumi/pulumi-kubernetes-operator/pull/742)

## 2.0.0-beta.1 (2024-10-18)

Expand Down
10 changes: 10 additions & 0 deletions operator/internal/controller/auto/update_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (r *UpdateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to update the status: %w", err)
}
l = log.FromContext(ctx).WithValues("revision", obj.ResourceVersion)

// Get the workspace and check that it is ready
w := &autov1alpha1.Workspace{}
Expand Down Expand Up @@ -257,6 +258,7 @@ func newReconcileSession(client client.Client, obj *autov1alpha1.Update) *reconc
}

func (rs *reconcileSession) updateStatus(ctx context.Context, obj *autov1alpha1.Update) error {
oldRevision := obj.ResourceVersion
obj.Status.ObservedGeneration = obj.Generation
rs.progressing.ObservedGeneration = obj.Generation
meta.SetStatusCondition(&obj.Status.Conditions, *rs.progressing)
Expand All @@ -266,6 +268,13 @@ func (rs *reconcileSession) updateStatus(ctx context.Context, obj *autov1alpha1.
meta.SetStatusCondition(&obj.Status.Conditions, *rs.complete)
err := rs.client.Status().Update(ctx, obj)
if err == nil {
if obj.ResourceVersion != oldRevision {
l := log.FromContext(ctx).WithValues("revision", obj.ResourceVersion)
l.Info("Status updated",
"observedGeneration", obj.Status.ObservedGeneration,
"message", obj.Status.Message,
"conditions", obj.Status.Conditions)
}
return nil
}
return fmt.Errorf("updating status: %w", err)
Expand Down Expand Up @@ -426,6 +435,7 @@ func (r *UpdateReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

return ctrl.NewControllerManagedBy(mgr).
Named("update-controller").
For(&autov1alpha1.Update{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&autov1alpha1.Workspace{},
handler.EnqueueRequestsFromMapFunc(r.mapWorkspaceToUpdate),
Expand Down
10 changes: 8 additions & 2 deletions operator/internal/controller/auto/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,21 @@ func (r *WorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}
}
updateStatus := func() error {
oldRevision := w.ResourceVersion
w.Status.ObservedGeneration = w.Generation
ready.ObservedGeneration = w.Generation
meta.SetStatusCondition(&w.Status.Conditions, *ready)
err := r.Status().Update(ctx, w)
if err != nil {
l.Error(err, "updating status")
} else {
l = log.FromContext(ctx).WithValues("revision", w.ResourceVersion)
l.V(1).Info("Status updated")
if w.ResourceVersion != oldRevision {
l = log.FromContext(ctx).WithValues("revision", w.ResourceVersion)
l.Info("Status updated",
"observedGeneration", w.Status.ObservedGeneration,
"address", w.Status.Address,
"conditions", w.Status.Conditions)
}
}

return err
Expand Down
12 changes: 10 additions & 2 deletions operator/internal/controller/pulumi/stack_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,20 @@ func (r *StackReconciler) Reconcile(ctx context.Context, request ctrl.Request) (
}

saveStatus := func() error {
oldRevision := instance.ResourceVersion
if err := r.Status().Update(ctx, instance); err != nil {
log.Error(err, "unable to save object status")
return err
}
log = ctrllog.FromContext(ctx).WithValues("revision", instance.ResourceVersion)
log.V(1).Info("Status updated")
if instance.ResourceVersion != oldRevision {
log = ctrllog.FromContext(ctx).WithValues("revision", instance.ResourceVersion)
log.Info("Status updated",
"observedGeneration", instance.Status.ObservedGeneration,
"observedReconcileRequest", instance.Status.ObservedReconcileRequest,
"lastUpdate", instance.Status.LastUpdate,
"currentUpdate", instance.Status.CurrentUpdate,
"conditions", instance.Status.Conditions)
}
return nil
}

Expand Down