Skip to content

Commit

Permalink
improved status logging (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
EronWright authored Nov 7, 2024
2 parents 0b5b8e4 + cbe21e8 commit ddd4ac4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
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

0 comments on commit ddd4ac4

Please sign in to comment.