diff --git a/api/v1alpha1/source.go b/api/v1alpha1/source.go index 4c918416..6215f677 100644 --- a/api/v1alpha1/source.go +++ b/api/v1alpha1/source.go @@ -14,12 +14,6 @@ type Source interface { GetInterval() metav1.Duration } -const ( - // ReconcileAtAnnotation is the annotation used for triggering a - // reconciliation outside of the defined schedule. - ReconcileAtAnnotation string = "fluxcd.io/reconcileAt" -) - // filterOutSourceCondition returns a new SourceCondition slice without the // SourceCondition of the given type. func filterOutSourceCondition(conditions []SourceCondition, condition string) []SourceCondition { diff --git a/controllers/gitrepository_controller.go b/controllers/gitrepository_controller.go index 4ce52033..d88f02b1 100644 --- a/controllers/gitrepository_controller.go +++ b/controllers/gitrepository_controller.go @@ -38,6 +38,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "github.com/fluxcd/pkg/recorder" + "github.com/fluxcd/pkg/runtime/predicates" sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1" "github.com/fluxcd/source-controller/pkg/git" @@ -158,7 +159,7 @@ func (r *GitRepositoryReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *GitRepositoryReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, opts GitRepositoryReconcilerOptions) error { return ctrl.NewControllerManagedBy(mgr). For(&sourcev1.GitRepository{}). - WithEventFilter(SourceChangePredicate{}). + WithEventFilter(predicates.ChangePredicate{}). WithOptions(controller.Options{MaxConcurrentReconciles: opts.MaxConcurrentReconciles}). Complete(r) } diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index e1eb1291..c6e7b720 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -41,6 +41,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "github.com/fluxcd/pkg/recorder" + "github.com/fluxcd/pkg/runtime/predicates" "github.com/fluxcd/pkg/untar" sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1" @@ -181,7 +182,7 @@ func (r *HelmChartReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *HelmChartReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, opts HelmChartReconcilerOptions) error { return ctrl.NewControllerManagedBy(mgr). For(&sourcev1.HelmChart{}). - WithEventFilter(SourceChangePredicate{}). + WithEventFilter(predicates.ChangePredicate{}). WithOptions(controller.Options{MaxConcurrentReconciles: opts.MaxConcurrentReconciles}). Complete(r) } diff --git a/controllers/helmrepository_controller.go b/controllers/helmrepository_controller.go index 0ea38533..5e082381 100644 --- a/controllers/helmrepository_controller.go +++ b/controllers/helmrepository_controller.go @@ -40,6 +40,7 @@ import ( "sigs.k8s.io/yaml" "github.com/fluxcd/pkg/recorder" + "github.com/fluxcd/pkg/runtime/predicates" sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1" "github.com/fluxcd/source-controller/internal/helm" ) @@ -160,7 +161,7 @@ func (r *HelmRepositoryReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *HelmRepositoryReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, opts HelmRepositoryReconcilerOptions) error { return ctrl.NewControllerManagedBy(mgr). For(&sourcev1.HelmRepository{}). - WithEventFilter(SourceChangePredicate{}). + WithEventFilter(predicates.ChangePredicate{}). WithOptions(controller.Options{MaxConcurrentReconciles: opts.MaxConcurrentReconciles}). Complete(r) } diff --git a/controllers/predicate.go b/controllers/predicate.go deleted file mode 100644 index 79dcd3a7..00000000 --- a/controllers/predicate.go +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright 2020 The Flux CD contributors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controllers - -import ( - "sigs.k8s.io/controller-runtime/pkg/event" - "sigs.k8s.io/controller-runtime/pkg/predicate" - - sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1" -) - -type SourceChangePredicate struct { - predicate.Funcs -} - -// Update implements the default UpdateEvent filter for validating -// source changes. -func (SourceChangePredicate) Update(e event.UpdateEvent) bool { - if e.MetaOld == nil || e.MetaNew == nil { - // ignore objects without metadata - return false - } - if e.MetaNew.GetGeneration() != e.MetaOld.GetGeneration() { - // reconcile on spec changes - return true - } - - // handle force sync - if val, ok := e.MetaNew.GetAnnotations()[sourcev1.ReconcileAtAnnotation]; ok { - if valOld, okOld := e.MetaOld.GetAnnotations()[sourcev1.ReconcileAtAnnotation]; okOld { - if val != valOld { - return true - } - } else { - return true - } - } - - return false -} diff --git a/go.mod b/go.mod index bd4d8296..171657c2 100644 --- a/go.mod +++ b/go.mod @@ -9,8 +9,8 @@ require ( github.com/fluxcd/pkg/gittestserver v0.0.2 github.com/fluxcd/pkg/helmtestserver v0.0.1 github.com/fluxcd/pkg/lockedfile v0.0.5 - github.com/fluxcd/pkg/logger v0.0.1 github.com/fluxcd/pkg/recorder v0.0.6 + github.com/fluxcd/pkg/runtime v0.0.0-20200909163337-e7e634246495 github.com/fluxcd/pkg/ssh v0.0.5 github.com/fluxcd/pkg/untar v0.0.5 github.com/fluxcd/source-controller/api v0.0.14 diff --git a/go.sum b/go.sum index f9befe47..87881d05 100644 --- a/go.sum +++ b/go.sum @@ -208,10 +208,10 @@ github.com/fluxcd/pkg/helmtestserver v0.0.1 h1:8RcLZdg7Zr9ZqyijsIIASjjMXQtF4UWP4 github.com/fluxcd/pkg/helmtestserver v0.0.1/go.mod h1:GR8LriiU7PqZSTH4Xe6Cimpig2VVPB29PeUXJjNJYfA= github.com/fluxcd/pkg/lockedfile v0.0.5 h1:C3T8wfdff1UY1bvplmCkGOLrdMWJHO8Q8+tdlEXJYzQ= github.com/fluxcd/pkg/lockedfile v0.0.5/go.mod h1:uAtPUBId6a2RqO84MTH5HKGX0SbM1kNW3Wr/FhYyDVA= -github.com/fluxcd/pkg/logger v0.0.1 h1:YInMzE4w+crIHQcUI4uLgFI0J+D0IVb8+pgYrseAYNY= -github.com/fluxcd/pkg/logger v0.0.1/go.mod h1:Qg+nqSAmY6OyO9JAIfQr0J2LjNu++M1Sm7KcZVLnjDM= github.com/fluxcd/pkg/recorder v0.0.6 h1:me/n8syeeGXz50OXoPX3jgIj9AtinvhHdKT9Dy+MbHs= github.com/fluxcd/pkg/recorder v0.0.6/go.mod h1:IfQxfVRSNsWs3B0Yp5B6ObEWwKHILlAx8N7XkoDdhFg= +github.com/fluxcd/pkg/runtime v0.0.0-20200909163337-e7e634246495 h1:zhtLz8iRtJWK+jKq9vi9Si4QbcAC2KvQZpQ55DRzLsU= +github.com/fluxcd/pkg/runtime v0.0.0-20200909163337-e7e634246495/go.mod h1:cU1t0+Ld39pZjMyrrHukw1E++OZFNHxG2qAExfDWQ34= github.com/fluxcd/pkg/ssh v0.0.5 h1:rnbFZ7voy2JBlUfMbfyqArX2FYaLNpDhccGFC3qW83A= github.com/fluxcd/pkg/ssh v0.0.5/go.mod h1:7jXPdXZpc0ttMNz2kD9QuMi3RNn/e0DOFbj0Tij/+Hs= github.com/fluxcd/pkg/testserver v0.0.2 h1:SoaMtO9cE5p/wl2zkGudzflnEHd9mk68CGjZOo7w0Uk= diff --git a/main.go b/main.go index 74c56f50..047dfccb 100644 --- a/main.go +++ b/main.go @@ -33,8 +33,8 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" ctrl "sigs.k8s.io/controller-runtime" - "github.com/fluxcd/pkg/logger" "github.com/fluxcd/pkg/recorder" + "github.com/fluxcd/pkg/runtime/logger" sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1" "github.com/fluxcd/source-controller/controllers" // +kubebuilder:scaffold:imports