From 50186b13910a45f852d197d5fe65623e7eda042d Mon Sep 17 00:00:00 2001 From: zzjin Date: Thu, 24 Oct 2024 11:04:37 +0800 Subject: [PATCH] Do not reconcile when terminal CR spec not changed. Signed-off-by: zzjin --- controllers/terminal/controllers/terminal_controller.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/controllers/terminal/controllers/terminal_controller.go b/controllers/terminal/controllers/terminal_controller.go index 693b36a2ac8..8035da62a65 100644 --- a/controllers/terminal/controllers/terminal_controller.go +++ b/controllers/terminal/controllers/terminal_controller.go @@ -33,9 +33,11 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/record" 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/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/predicate" "github.com/labring/sealos/controllers/pkg/utils/label" terminalv1 "github.com/labring/sealos/controllers/terminal/api/v1" @@ -400,7 +402,9 @@ func (r *TerminalReconciler) SetupWithManager(mgr ctrl.Manager) error { r.recorder = mgr.GetEventRecorderFor("sealos-terminal-controller") r.Config = mgr.GetConfig() return ctrl.NewControllerManagedBy(mgr). - For(&terminalv1.Terminal{}). - Owns(&appsv1.Deployment{}).Owns(&corev1.Service{}).Owns(&networkingv1.Ingress{}). + For(&terminalv1.Terminal{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})). + Owns(&appsv1.Deployment{}, builder.WithPredicates(predicate.ResourceVersionChangedPredicate{})). + Owns(&corev1.Service{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})). + Owns(&networkingv1.Ingress{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})). Complete(r) }