Skip to content

Commit

Permalink
Add ObservedGeneration to MachinePool Controller
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Spagnolo <[email protected]>
  • Loading branch information
spagno committed Jun 26, 2020
1 parent 8f0d03b commit 6fc0e58
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions exp/api/v1alpha3/machinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ type MachinePoolStatus struct {
// InfrastructureReady is the state of the infrastructure provider.
// +optional
InfrastructureReady bool `json:"infrastructureReady"`

// ObservedGeneration is the latest generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

// ANCHOR_END: MachinePoolStatus
Expand Down
7 changes: 6 additions & 1 deletion exp/controllers/machinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ func (r *MachinePoolReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, rete
// TODO(jpang): add support for metrics.

// Always attempt to patch the object and status after each reconciliation.
if err := patchHelper.Patch(ctx, mp); err != nil {
// Patch ObservedGeneration only if the reconciliation completed successfully
patchOpts := []patch.Option{}
if reterr == nil {
patchOpts = append(patchOpts, patch.WithStatusObservedGeneration{})
}
if err := patchHelper.Patch(ctx, mp, patchOpts...); err != nil {
reterr = kerrors.NewAggregate([]error{reterr, err})
}
}()
Expand Down
2 changes: 2 additions & 0 deletions exp/controllers/machinepool_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ func TestReconcileMachinePoolRequest(t *testing.T) {
NodeRefs: []corev1.ObjectReference{
{Name: "test"},
},
ObservedGeneration: 1,
},
},
expected: expected{
Expand Down Expand Up @@ -372,6 +373,7 @@ func TestReconcileMachinePoolRequest(t *testing.T) {
NodeRefs: []corev1.ObjectReference{
{Name: "test"},
},
ObservedGeneration: 1,
},
},
expected: expected{
Expand Down

0 comments on commit 6fc0e58

Please sign in to comment.