Skip to content

Commit

Permalink
controllers: skip reconciling when the status has changed. (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
datdao authored Jun 29, 2023
1 parent 08358a8 commit d783bf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion controllers/atlasmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"

dbv1alpha1 "github.com/ariga/atlas-operator/api/v1alpha1"
Expand Down Expand Up @@ -354,7 +356,7 @@ func (r *AtlasMigrationReconciler) watch(am dbv1alpha1.AtlasMigration) {
// SetupWithManager sets up the controller with the Manager.
func (r *AtlasMigrationReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&dbv1alpha1.AtlasMigration{}).
For(&dbv1alpha1.AtlasMigration{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&dbv1alpha1.AtlasMigration{}).
Watches(&source.Kind{Type: &corev1.Secret{}}, r.secretWatcher).
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, r.configMapWatcher).
Expand Down
4 changes: 3 additions & 1 deletion controllers/atlasschema_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/yaml"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"

dbv1alpha1 "github.com/ariga/atlas-operator/api/v1alpha1"
Expand Down Expand Up @@ -229,7 +231,7 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// SetupWithManager sets up the controller with the Manager.
func (r *AtlasSchemaReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&dbv1alpha1.AtlasSchema{}).
For(&dbv1alpha1.AtlasSchema{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&dbv1alpha1.AtlasSchema{}).
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, r.configMapWatcher).
Watches(&source.Kind{Type: &corev1.Secret{}}, r.secretWatcher).
Expand Down

0 comments on commit d783bf4

Please sign in to comment.