From 0b4586253cc2926d20f77e784db80e33d241e642 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Thu, 19 Nov 2020 12:59:13 +0100 Subject: [PATCH] Add LastHandledReconcileAt to source statuses Signed-off-by: Hidde Beydals --- api/v1beta1/bucket_types.go | 2 + api/v1beta1/gitrepository_types.go | 2 + api/v1beta1/helmchart_types.go | 2 + api/v1beta1/helmrepository_types.go | 2 + api/v1beta1/zz_generated.deepcopy.go | 4 ++ .../source.toolkit.fluxcd.io_buckets.yaml | 4 ++ ...rce.toolkit.fluxcd.io_gitrepositories.yaml | 4 ++ .../source.toolkit.fluxcd.io_helmcharts.yaml | 4 ++ ...ce.toolkit.fluxcd.io_helmrepositories.yaml | 4 ++ controllers/bucket_controller.go | 7 ++ controllers/gitrepository_controller.go | 7 ++ controllers/helmchart_controller.go | 9 ++- controllers/helmrepository_controller.go | 7 ++ docs/api/source.md | 68 +++++++++++++++++-- docs/spec/v1beta1/buckets.md | 5 ++ docs/spec/v1beta1/gitrepositories.md | 5 ++ docs/spec/v1beta1/helmcharts.md | 5 ++ docs/spec/v1beta1/helmrepositories.md | 5 ++ hack/api-docs/config.json | 8 ++- 19 files changed, 147 insertions(+), 7 deletions(-) diff --git a/api/v1beta1/bucket_types.go b/api/v1beta1/bucket_types.go index 29db6e16..2c10960c 100644 --- a/api/v1beta1/bucket_types.go +++ b/api/v1beta1/bucket_types.go @@ -95,6 +95,8 @@ type BucketStatus struct { // Artifact represents the output of the last successful Bucket sync. // +optional Artifact *Artifact `json:"artifact,omitempty"` + + meta.ReconcileRequestStatus `json:",inline"` } const ( diff --git a/api/v1beta1/gitrepository_types.go b/api/v1beta1/gitrepository_types.go index 1d0831a8..ce2ea8d9 100644 --- a/api/v1beta1/gitrepository_types.go +++ b/api/v1beta1/gitrepository_types.go @@ -116,6 +116,8 @@ type GitRepositoryStatus struct { // Artifact represents the output of the last successful repository sync. // +optional Artifact *Artifact `json:"artifact,omitempty"` + + meta.ReconcileRequestStatus `json:",inline"` } const ( diff --git a/api/v1beta1/helmchart_types.go b/api/v1beta1/helmchart_types.go index 2b3a9f9c..6a7e6af5 100644 --- a/api/v1beta1/helmchart_types.go +++ b/api/v1beta1/helmchart_types.go @@ -86,6 +86,8 @@ type HelmChartStatus struct { // Artifact represents the output of the last successful chart sync. // +optional Artifact *Artifact `json:"artifact,omitempty"` + + meta.ReconcileRequestStatus `json:",inline"` } const ( diff --git a/api/v1beta1/helmrepository_types.go b/api/v1beta1/helmrepository_types.go index de6fbbab..c8f7a76d 100644 --- a/api/v1beta1/helmrepository_types.go +++ b/api/v1beta1/helmrepository_types.go @@ -73,6 +73,8 @@ type HelmRepositoryStatus struct { // Artifact represents the output of the last successful repository sync. // +optional Artifact *Artifact `json:"artifact,omitempty"` + + meta.ReconcileRequestStatus `json:",inline"` } const ( diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index ace990b0..d8e1018b 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -147,6 +147,7 @@ func (in *BucketStatus) DeepCopyInto(out *BucketStatus) { *out = new(Artifact) (*in).DeepCopyInto(*out) } + out.ReconcileRequestStatus = in.ReconcileRequestStatus } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BucketStatus. @@ -289,6 +290,7 @@ func (in *GitRepositoryStatus) DeepCopyInto(out *GitRepositoryStatus) { *out = new(Artifact) (*in).DeepCopyInto(*out) } + out.ReconcileRequestStatus = in.ReconcileRequestStatus } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitRepositoryStatus. @@ -408,6 +410,7 @@ func (in *HelmChartStatus) DeepCopyInto(out *HelmChartStatus) { *out = new(Artifact) (*in).DeepCopyInto(*out) } + out.ReconcileRequestStatus = in.ReconcileRequestStatus } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmChartStatus. @@ -520,6 +523,7 @@ func (in *HelmRepositoryStatus) DeepCopyInto(out *HelmRepositoryStatus) { *out = new(Artifact) (*in).DeepCopyInto(*out) } + out.ReconcileRequestStatus = in.ReconcileRequestStatus } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmRepositoryStatus. diff --git a/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml b/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml index 7539f995..5665a6a5 100644 --- a/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml +++ b/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml @@ -196,6 +196,10 @@ spec: - type type: object type: array + lastHandledReconcileAt: + description: LastHandledReconcileAt holds the value of the most recent + reconcile request value, so a change can be detected. + type: string observedGeneration: description: ObservedGeneration is the last observed generation. format: int64 diff --git a/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml b/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml index 06493bab..48c16056 100644 --- a/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml +++ b/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml @@ -224,6 +224,10 @@ spec: - type type: object type: array + lastHandledReconcileAt: + description: LastHandledReconcileAt holds the value of the most recent + reconcile request value, so a change can be detected. + type: string observedGeneration: description: ObservedGeneration is the last observed generation. format: int64 diff --git a/config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml b/config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml index 52d2ca41..39af34b5 100644 --- a/config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml +++ b/config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml @@ -200,6 +200,10 @@ spec: - type type: object type: array + lastHandledReconcileAt: + description: LastHandledReconcileAt holds the value of the most recent + reconcile request value, so a change can be detected. + type: string observedGeneration: description: ObservedGeneration is the last observed generation. format: int64 diff --git a/config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml b/config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml index 1f9b4bfa..8cae509a 100644 --- a/config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml +++ b/config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml @@ -175,6 +175,10 @@ spec: - type type: object type: array + lastHandledReconcileAt: + description: LastHandledReconcileAt holds the value of the most recent + reconcile request value, so a change can be detected. + type: string observedGeneration: description: ObservedGeneration is the last observed generation. format: int64 diff --git a/controllers/bucket_controller.go b/controllers/bucket_controller.go index 9bc4abfb..4ac120d3 100644 --- a/controllers/bucket_controller.go +++ b/controllers/bucket_controller.go @@ -109,6 +109,13 @@ func (r *BucketReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { r.recordReadiness(bucket) } + // record the value of the reconciliation request, if any + // TODO(hidde): would be better to defer this in combination with + // always patching the status sub-resource after a reconciliation. + if v, ok := meta.ReconcileAnnotationValue(bucket.GetAnnotations()); ok { + bucket.Status.SetLastHandledReconcileRequest(v) + } + // purge old artifacts from storage if err := r.gc(bucket); err != nil { log.Error(err, "unable to purge old artifacts") diff --git a/controllers/gitrepository_controller.go b/controllers/gitrepository_controller.go index faaa879a..88ef0e76 100644 --- a/controllers/gitrepository_controller.go +++ b/controllers/gitrepository_controller.go @@ -108,6 +108,13 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro r.recordReadiness(repository) } + // record the value of the reconciliation request, if any + // TODO(hidde): would be better to defer this in combination with + // always patching the status sub-resource after a reconciliation. + if v, ok := meta.ReconcileAnnotationValue(repository.GetAnnotations()); ok { + repository.Status.SetLastHandledReconcileRequest(v) + } + // purge old artifacts from storage if err := r.gc(repository); err != nil { log.Error(err, "unable to purge old artifacts") diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index 518620ca..995e203f 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -95,7 +95,7 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { return r.reconcileDelete(ctx, chart) } - // record reconciliation duration + // Record reconciliation duration if r.MetricsRecorder != nil { objRef, err := reference.GetReference(r.Scheme, &chart) if err != nil { @@ -115,6 +115,13 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { r.recordReadiness(chart) } + // Record the value of the reconciliation request, if any + // TODO(hidde): would be better to defer this in combination with + // always patching the status sub-resource after a reconciliation. + if v, ok := meta.ReconcileAnnotationValue(chart.GetAnnotations()); ok { + chart.Status.SetLastHandledReconcileRequest(v) + } + // Purge all but current artifact from storage if err := r.gc(chart); err != nil { log.Error(err, "unable to purge old artifacts") diff --git a/controllers/helmrepository_controller.go b/controllers/helmrepository_controller.go index a74d8880..fc889660 100644 --- a/controllers/helmrepository_controller.go +++ b/controllers/helmrepository_controller.go @@ -109,6 +109,13 @@ func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err r.recordReadiness(repository) } + // record the value of the reconciliation request, if any + // TODO(hidde): would be better to defer this in combination with + // always patching the status sub-resource after a reconciliation. + if v, ok := meta.ReconcileAnnotationValue(repository.GetAnnotations()); ok { + repository.Status.SetLastHandledReconcileRequest(v) + } + // purge old artifacts from storage if err := r.gc(repository); err != nil { log.Error(err, "unable to purge old artifacts") diff --git a/docs/api/source.md b/docs/api/source.md index 188c3662..5ac01962 100644 --- a/docs/api/source.md +++ b/docs/api/source.md @@ -908,7 +908,7 @@ int64 conditions
- + []Kubernetes meta/v1.Condition @@ -944,6 +944,21 @@ Artifact

Artifact represents the output of the last successful Bucket sync.

+ + +ReconcileRequestStatus
+ + +github.com/fluxcd/pkg/apis/meta.ReconcileRequestStatus + + + + +

+(Members of ReconcileRequestStatus are embedded into this type.) +

+ + @@ -1170,7 +1185,7 @@ int64 conditions
- + []Kubernetes meta/v1.Condition @@ -1207,6 +1222,21 @@ Artifact

Artifact represents the output of the last successful repository sync.

+ + +ReconcileRequestStatus
+ + +github.com/fluxcd/pkg/apis/meta.ReconcileRequestStatus + + + + +

+(Members of ReconcileRequestStatus are embedded into this type.) +

+ + @@ -1373,7 +1403,7 @@ int64 conditions
- + []Kubernetes meta/v1.Condition @@ -1409,6 +1439,21 @@ Artifact

Artifact represents the output of the last successful chart sync.

+ + +ReconcileRequestStatus
+ + +github.com/fluxcd/pkg/apis/meta.ReconcileRequestStatus + + + + +

+(Members of ReconcileRequestStatus are embedded into this type.) +

+ + @@ -1524,7 +1569,7 @@ int64 conditions
- + []Kubernetes meta/v1.Condition @@ -1560,6 +1605,21 @@ Artifact

Artifact represents the output of the last successful repository sync.

+ + +ReconcileRequestStatus
+ + +github.com/fluxcd/pkg/apis/meta.ReconcileRequestStatus + + + + +

+(Members of ReconcileRequestStatus are embedded into this type.) +

+ + diff --git a/docs/spec/v1beta1/buckets.md b/docs/spec/v1beta1/buckets.md index dda6df21..1d1954f2 100644 --- a/docs/spec/v1beta1/buckets.md +++ b/docs/spec/v1beta1/buckets.md @@ -81,6 +81,11 @@ type BucketStatus struct { // Artifact represents the output of the last successful Bucket sync. // +optional Artifact *Artifact `json:"artifact,omitempty"` + + // LastHandledReconcileAt is the last manual reconciliation request (by + // annotating the Bucket) handled by the reconciler. + // +optional + LastHandledReconcileAt string `json:"lastHandledReconcileAt,omitempty"` } ``` diff --git a/docs/spec/v1beta1/gitrepositories.md b/docs/spec/v1beta1/gitrepositories.md index 5469e233..d106e9e4 100644 --- a/docs/spec/v1beta1/gitrepositories.md +++ b/docs/spec/v1beta1/gitrepositories.md @@ -103,6 +103,11 @@ type GitRepositoryStatus struct { // Artifact represents the output of the last successful repository sync. // +optional Artifact *Artifact `json:"artifact,omitempty"` + + // LastHandledReconcileAt is the last manual reconciliation request (by + // annotating the GitRepository) handled by the reconciler. + // +optional + LastHandledReconcileAt string `json:"lastHandledReconcileAt,omitempty"` } ``` diff --git a/docs/spec/v1beta1/helmcharts.md b/docs/spec/v1beta1/helmcharts.md index fbec0251..cfb31107 100644 --- a/docs/spec/v1beta1/helmcharts.md +++ b/docs/spec/v1beta1/helmcharts.md @@ -77,6 +77,11 @@ type HelmChartStatus struct { // Artifact represents the output of the last successful chart sync. // +optional Artifact *Artifact `json:"artifact,omitempty"` + + // LastHandledReconcileAt is the last manual reconciliation request (by + // annotating the HelmChart) handled by the reconciler. + // +optional + LastHandledReconcileAt string `json:"lastHandledReconcileAt,omitempty"` } ``` diff --git a/docs/spec/v1beta1/helmrepositories.md b/docs/spec/v1beta1/helmrepositories.md index ac68f446..0cc3e22c 100644 --- a/docs/spec/v1beta1/helmrepositories.md +++ b/docs/spec/v1beta1/helmrepositories.md @@ -54,6 +54,11 @@ type HelmRepositoryStatus struct { // Artifact represents the output of the last successful repository sync. // +optional Artifact *Artifact `json:"artifact,omitempty"` + + // LastHandledReconcileAt is the last manual reconciliation request (by + // annotating the HelmRepository) handled by the reconciler. + // +optional + LastHandledReconcileAt string `json:"lastHandledReconcileAt,omitempty"` } ``` diff --git a/hack/api-docs/config.json b/hack/api-docs/config.json index b59432d0..45c96840 100644 --- a/hack/api-docs/config.json +++ b/hack/api-docs/config.json @@ -11,13 +11,17 @@ "typeMatchPrefix": "^k8s\\.io/apimachinery/pkg/apis/meta/v1\\.Duration$", "docsURLTemplate": "https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Duration" }, + { + "typeMatchPrefix": "^k8s\\.io/apimachinery/pkg/apis/meta/v1\\.Condition$", + "docsURLTemplate": "https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Condition" + }, { "typeMatchPrefix": "^k8s\\.io/(api|apimachinery/pkg/apis)/", "docsURLTemplate": "https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#{{lower .TypeIdentifier}}-{{arrIndex .PackageSegments -1}}-{{arrIndex .PackageSegments -2}}" }, { - "typeMatchPrefix": "^k8s\\.io/apimachinery/pkg/apis/meta/v1\\.Condition$", - "docsURLTemplate": "https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Condition" + "typeMatchPrefix": "^github.com/fluxcd/pkg/apis/meta", + "docsURLTemplate": "https://godoc.org/github.com/fluxcd/pkg/apis/meta#{{ .TypeIdentifier }}" } ], "typeDisplayNamePrefixOverrides": {