From 07d09e2c2e469c6fe8b6fd94326f378d077a8592 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Thu, 26 Nov 2020 12:28:40 +0200 Subject: [PATCH 1/2] Add suspend field to Source API Signed-off-by: Stefan Prodan --- api/v1beta1/bucket_types.go | 4 ++++ api/v1beta1/gitrepository_types.go | 4 ++++ api/v1beta1/helmchart_types.go | 4 ++++ api/v1beta1/helmrepository_types.go | 4 ++++ config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml | 4 ++++ .../crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml | 4 ++++ config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml | 4 ++++ .../bases/source.toolkit.fluxcd.io_helmrepositories.yaml | 4 ++++ docs/spec/v1beta1/buckets.md | 4 ++++ docs/spec/v1beta1/common.md | 6 ++++-- docs/spec/v1beta1/gitrepositories.md | 4 ++++ docs/spec/v1beta1/helmcharts.md | 4 ++++ docs/spec/v1beta1/helmrepositories.md | 4 ++++ 13 files changed, 52 insertions(+), 2 deletions(-) diff --git a/api/v1beta1/bucket_types.go b/api/v1beta1/bucket_types.go index 2c10960c4..32d196406 100644 --- a/api/v1beta1/bucket_types.go +++ b/api/v1beta1/bucket_types.go @@ -71,6 +71,10 @@ type BucketSpec struct { // consult the documentation for your version to find out what those are. // +optional Ignore *string `json:"ignore,omitempty"` + + // This flag tells the controller to suspend the reconciliation of this source. + // +optional + Suspend bool `json:"suspend,omitempty"` } const ( diff --git a/api/v1beta1/gitrepository_types.go b/api/v1beta1/gitrepository_types.go index ce2ea8d91..205667d06 100644 --- a/api/v1beta1/gitrepository_types.go +++ b/api/v1beta1/gitrepository_types.go @@ -66,6 +66,10 @@ type GitRepositorySpec struct { // consult the documentation for your version to find out what those are. // +optional Ignore *string `json:"ignore,omitempty"` + + // This flag tells the controller to suspend the reconciliation of this source. + // +optional + Suspend bool `json:"suspend,omitempty"` } // GitRepositoryRef defines the Git ref used for pull and checkout operations. diff --git a/api/v1beta1/helmchart_types.go b/api/v1beta1/helmchart_types.go index 6a7e6af5a..aa19edfee 100644 --- a/api/v1beta1/helmchart_types.go +++ b/api/v1beta1/helmchart_types.go @@ -49,6 +49,10 @@ type HelmChartSpec struct { // relative path in the SourceRef. Ignored when omitted. // +optional ValuesFile string `json:"valuesFile,omitempty"` + + // This flag tells the controller to suspend the reconciliation of this source. + // +optional + Suspend bool `json:"suspend,omitempty"` } // LocalHelmChartSourceReference contains enough information to let you locate diff --git a/api/v1beta1/helmrepository_types.go b/api/v1beta1/helmrepository_types.go index c8f7a76db..655f1e57f 100644 --- a/api/v1beta1/helmrepository_types.go +++ b/api/v1beta1/helmrepository_types.go @@ -54,6 +54,10 @@ type HelmRepositorySpec struct { // +kubebuilder:default:="60s" // +optional Timeout *metav1.Duration `json:"timeout,omitempty"` + + // This flag tells the controller to suspend the reconciliation of this source. + // +optional + Suspend bool `json:"suspend,omitempty"` } // HelmRepositoryStatus defines the observed state of the HelmRepository. diff --git a/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml b/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml index 5665a6a53..6e95950f4 100644 --- a/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml +++ b/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml @@ -87,6 +87,10 @@ spec: TODO: Add other useful fields. apiVersion, kind, uid?' type: string type: object + suspend: + description: This flag tells the controller to suspend the reconciliation + of this source. + type: boolean timeout: default: 20s description: The timeout for download operations, defaults to 20s. diff --git a/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml b/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml index 48c16056b..8478e39fc 100644 --- a/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml +++ b/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml @@ -89,6 +89,10 @@ spec: TODO: Add other useful fields. apiVersion, kind, uid?' type: string type: object + suspend: + description: This flag tells the controller to suspend the reconciliation + of this source. + type: boolean timeout: default: 20s description: The timeout for remote Git operations like cloning, defaults diff --git a/config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml b/config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml index 39af34b5e..c7da4899b 100644 --- a/config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml +++ b/config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml @@ -86,6 +86,10 @@ spec: - kind - name type: object + suspend: + description: This flag tells the controller to suspend the reconciliation + of this source. + type: boolean valuesFile: description: Alternative values file to use as the default chart values, expected to be a relative path in the SourceRef. Ignored when omitted. diff --git a/config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml b/config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml index 8cae509a5..00868c6ad 100644 --- a/config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml +++ b/config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml @@ -63,6 +63,10 @@ spec: TODO: Add other useful fields. apiVersion, kind, uid?' type: string type: object + suspend: + description: This flag tells the controller to suspend the reconciliation + of this source. + type: boolean timeout: default: 60s description: The timeout of index downloading, defaults to 60s. diff --git a/docs/spec/v1beta1/buckets.md b/docs/spec/v1beta1/buckets.md index 1d1954f2d..fc9f566c5 100644 --- a/docs/spec/v1beta1/buckets.md +++ b/docs/spec/v1beta1/buckets.md @@ -49,6 +49,10 @@ type BucketSpec struct { // consult the documentation for your version to find out what those are. // +optional Ignore *string `json:"ignore,omitempty"` + + // This flag tells the controller to suspend the reconciliation of this source. + // +optional + Suspend bool `json:"suspend,omitempty"` } ``` diff --git a/docs/spec/v1beta1/common.md b/docs/spec/v1beta1/common.md index ce05795bf..251046870 100644 --- a/docs/spec/v1beta1/common.md +++ b/docs/spec/v1beta1/common.md @@ -6,7 +6,7 @@ Common defines resources used across all source types. ### Source interface -Source objects should adhere to the `Source` interface. This interface exposes the [interval](#source-synchronization) +Source objects adhere to the `Source` interface. This interface exposes the [interval](#source-reconciliation) and [artifact](#source-status) of the source to clients without the prerequisite of knowing the source kind: ````go @@ -21,7 +21,7 @@ type Source interface { ### Source reconciliation -Source objects should contain a `spec.interval` field that tells the controller at which interval to check for updates: +Source objects contain a `spec.interval` field that tells the controller at which interval to check for updates: ```go type SourceSpec struct { @@ -39,6 +39,8 @@ The controller can be told to check for updates right away by setting an annotat kubectl annotate --overwrite gitrepository/podinfo fluxcd.io/reconcileAt="$(date +%s)" ``` +The source objects reconciliation can be suspended by setting `spec.suspend` to `true`. + ### Source status Source objects should contain a status sub-resource that embeds an artifact object: diff --git a/docs/spec/v1beta1/gitrepositories.md b/docs/spec/v1beta1/gitrepositories.md index d106e9e4f..4dde7b625 100644 --- a/docs/spec/v1beta1/gitrepositories.md +++ b/docs/spec/v1beta1/gitrepositories.md @@ -46,6 +46,10 @@ type GitRepositorySpec struct { // consult the documentation for your version to find out what those are. // +optional Ignore *string `json:"ignore,omitempty"` + + // This flag tells the controller to suspend the reconciliation of this source. + // +optional + Suspend bool `json:"suspend,omitempty"` } ``` diff --git a/docs/spec/v1beta1/helmcharts.md b/docs/spec/v1beta1/helmcharts.md index cfb311078..3a96c08fd 100644 --- a/docs/spec/v1beta1/helmcharts.md +++ b/docs/spec/v1beta1/helmcharts.md @@ -32,6 +32,10 @@ type HelmChartSpec struct { // relative path in the SourceRef. Ignored when omitted. // +optional ValuesFile string `json:"valuesFile,omitempty"` + + // This flag tells the controller to suspend the reconciliation of this source. + // +optional + Suspend bool `json:"suspend,omitempty"` } ``` diff --git a/docs/spec/v1beta1/helmrepositories.md b/docs/spec/v1beta1/helmrepositories.md index 0cc3e22cf..f82f6196e 100644 --- a/docs/spec/v1beta1/helmrepositories.md +++ b/docs/spec/v1beta1/helmrepositories.md @@ -31,6 +31,10 @@ type HelmRepositorySpec struct { // The timeout of index downloading, defaults to 60s. // +optional Timeout *metav1.Duration `json:"timeout,omitempty"` + + // This flag tells the controller to suspend the reconciliation of this source. + // +optional + Suspend bool `json:"suspend,omitempty"` } ``` From 5579dc8c96391ff81c394f5ed73373b9245a2fbb Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Thu, 26 Nov 2020 12:58:00 +0200 Subject: [PATCH 2/2] Implement source suspension Signed-off-by: Stefan Prodan --- controllers/bucket_controller.go | 6 ++ controllers/gitrepository_controller.go | 6 ++ controllers/helmchart_controller.go | 6 ++ controllers/helmrepository_controller.go | 6 ++ docs/api/source.md | 96 ++++++++++++++++++++++++ 5 files changed, 120 insertions(+) diff --git a/controllers/bucket_controller.go b/controllers/bucket_controller.go index 4ac120d39..7000c30ee 100644 --- a/controllers/bucket_controller.go +++ b/controllers/bucket_controller.go @@ -90,6 +90,12 @@ func (r *BucketReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { return r.reconcileDelete(ctx, bucket) } + // Return early if the object is suspended. + if bucket.Spec.Suspend { + log.Info("Reconciliation is suspended for this object") + return ctrl.Result{}, nil + } + // record reconciliation duration if r.MetricsRecorder != nil { objRef, err := reference.GetReference(r.Scheme, &bucket) diff --git a/controllers/gitrepository_controller.go b/controllers/gitrepository_controller.go index 88ef0e766..ae9f621d8 100644 --- a/controllers/gitrepository_controller.go +++ b/controllers/gitrepository_controller.go @@ -89,6 +89,12 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro return r.reconcileDelete(ctx, repository) } + // Return early if the object is suspended. + if repository.Spec.Suspend { + log.Info("Reconciliation is suspended for this object") + return ctrl.Result{}, nil + } + // record reconciliation duration if r.MetricsRecorder != nil { objRef, err := reference.GetReference(r.Scheme, &repository) diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index 995e203f0..2188e0091 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -95,6 +95,12 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { return r.reconcileDelete(ctx, chart) } + // Return early if the object is suspended. + if chart.Spec.Suspend { + log.Info("Reconciliation is suspended for this object") + return ctrl.Result{}, nil + } + // Record reconciliation duration if r.MetricsRecorder != nil { objRef, err := reference.GetReference(r.Scheme, &chart) diff --git a/controllers/helmrepository_controller.go b/controllers/helmrepository_controller.go index fc889660c..06641ec61 100644 --- a/controllers/helmrepository_controller.go +++ b/controllers/helmrepository_controller.go @@ -90,6 +90,12 @@ func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err return r.reconcileDelete(ctx, repository) } + // Return early if the object is suspended. + if repository.Spec.Suspend { + log.Info("Reconciliation is suspended for this object") + return ctrl.Result{}, nil + } + // record reconciliation duration if r.MetricsRecorder != nil { objRef, err := reference.GetReference(r.Scheme, &repository) diff --git a/docs/api/source.md b/docs/api/source.md index 5ac019624..6e098a0fb 100644 --- a/docs/api/source.md +++ b/docs/api/source.md @@ -188,6 +188,18 @@ string consult the documentation for your version to find out what those are.

+ + +suspend
+ +bool + + + +(Optional) +

This flag tells the controller to suspend the reconciliation of this source.

+ + @@ -363,6 +375,18 @@ string consult the documentation for your version to find out what those are.

+ + +suspend
+ +bool + + + +(Optional) +

This flag tells the controller to suspend the reconciliation of this source.

+ + @@ -502,6 +526,18 @@ string relative path in the SourceRef. Ignored when omitted.

+ + +suspend
+ +bool + + + +(Optional) +

This flag tells the controller to suspend the reconciliation of this source.

+ + @@ -635,6 +671,18 @@ Kubernetes meta/v1.Duration

The timeout of index downloading, defaults to 60s.

+ + +suspend
+ +bool + + + +(Optional) +

This flag tells the controller to suspend the reconciliation of this source.

+ + @@ -871,6 +919,18 @@ string consult the documentation for your version to find out what those are.

+ + +suspend
+ +bool + + + +(Optional) +

This flag tells the controller to suspend the reconciliation of this source.

+ + @@ -1148,6 +1208,18 @@ string consult the documentation for your version to find out what those are.

+ + +suspend
+ +bool + + + +(Optional) +

This flag tells the controller to suspend the reconciliation of this source.

+ + @@ -1366,6 +1438,18 @@ string relative path in the SourceRef. Ignored when omitted.

+ + +suspend
+ +bool + + + +(Optional) +

This flag tells the controller to suspend the reconciliation of this source.

+ + @@ -1532,6 +1616,18 @@ Kubernetes meta/v1.Duration

The timeout of index downloading, defaults to 60s.

+ + +suspend
+ +bool + + + +(Optional) +

This flag tells the controller to suspend the reconciliation of this source.

+ +