From 59782706a9b0e4e30c611b201f75bdfc6fd40d42 Mon Sep 17 00:00:00 2001 From: killianmuldoon Date: Tue, 24 Jan 2023 16:05:03 +0000 Subject: [PATCH] Add observedGeneration to ClusterClass status --- api/v1beta1/clusterclass_types.go | 4 ++++ api/v1beta1/zz_generated.openapi.go | 7 +++++++ config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml | 5 +++++ .../controllers/clusterclass/clusterclass_controller.go | 8 ++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/api/v1beta1/clusterclass_types.go b/api/v1beta1/clusterclass_types.go index f5ab05c77754..d9ecb15ae7b5 100644 --- a/api/v1beta1/clusterclass_types.go +++ b/api/v1beta1/clusterclass_types.go @@ -556,6 +556,10 @@ type ClusterClassStatus struct { // Conditions defines current observed state of the ClusterClass. // +optional Conditions Conditions `json:"conditions,omitempty"` + + // ObservedGeneration is the latest generation observed by the controller. + // +optional + ObservedGeneration int64 `json:"observedGeneration,omitempty"` } // GetConditions returns the set of conditions for this object. diff --git a/api/v1beta1/zz_generated.openapi.go b/api/v1beta1/zz_generated.openapi.go index 66bdbfb762b7..a496c284f5ad 100644 --- a/api/v1beta1/zz_generated.openapi.go +++ b/api/v1beta1/zz_generated.openapi.go @@ -437,6 +437,13 @@ func schema_sigsk8sio_cluster_api_api_v1beta1_ClusterClassStatus(ref common.Refe }, }, }, + "observedGeneration": { + SchemaProps: spec.SchemaProps{ + Description: "ObservedGeneration is the latest generation observed by the controller.", + Type: []string{"integer"}, + Format: "int64", + }, + }, }, }, }, diff --git a/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml b/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml index e73daa58fb89..b369462229e8 100644 --- a/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml +++ b/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml @@ -1440,6 +1440,11 @@ spec: - type type: object type: array + observedGeneration: + description: ObservedGeneration is the latest generation observed + by the controller. + format: int64 + type: integer type: object type: object served: true diff --git a/internal/controllers/clusterclass/clusterclass_controller.go b/internal/controllers/clusterclass/clusterclass_controller.go index 88d478bb2903..bca73f4592a4 100644 --- a/internal/controllers/clusterclass/clusterclass_controller.go +++ b/internal/controllers/clusterclass/clusterclass_controller.go @@ -99,12 +99,16 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re } defer func() { - if err := patchHelper.Patch(ctx, clusterClass); 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, clusterClass, patchOpts...); err != nil { reterr = kerrors.NewAggregate([]error{reterr, errors.Wrapf(err, "failed to patch %s", tlog.KObj{Obj: clusterClass})}) return } }() - return r.reconcile(ctx, clusterClass) }