From babc83bf39e9804ef9340f0c52f5810a3acfd85f Mon Sep 17 00:00:00 2001 From: rabi Date: Tue, 23 Jul 2024 13:56:15 +0530 Subject: [PATCH] WIP Don't reconcile for status updates This sometimes leads to infinite loops and also results in very verbose controller logs. Also removes the changes to duplicate multating webhook logic when calling CreateOrPatch. --- .../dataplane/openstackdataplanedeployment_controller.go | 8 +++++++- .../dataplane/openstackdataplanenodeset_controller.go | 8 +++++--- pkg/dataplane/service.go | 4 ---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/controllers/dataplane/openstackdataplanedeployment_controller.go b/controllers/dataplane/openstackdataplanedeployment_controller.go index 0f8234e2a..1a2f2edae 100644 --- a/controllers/dataplane/openstackdataplanedeployment_controller.go +++ b/controllers/dataplane/openstackdataplanedeployment_controller.go @@ -28,8 +28,10 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes" 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/predicate" "github.com/go-logr/logr" condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" @@ -426,7 +428,11 @@ func (r *OpenStackDataPlaneDeploymentReconciler) setHashes( // SetupWithManager sets up the controller with the Manager. func (r *OpenStackDataPlaneDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&dataplanev1.OpenStackDataPlaneDeployment{}). + For(&dataplanev1.OpenStackDataPlaneDeployment{}, + builder.WithPredicates(predicate.Or( + predicate.GenerationChangedPredicate{}, + predicate.AnnotationChangedPredicate{}, + predicate.LabelChangedPredicate{}))). Owns(&ansibleeev1.OpenStackAnsibleEE{}). Complete(r) } diff --git a/controllers/dataplane/openstackdataplanenodeset_controller.go b/controllers/dataplane/openstackdataplanenodeset_controller.go index 8f5cf2bab..9adc3d6e8 100644 --- a/controllers/dataplane/openstackdataplanenodeset_controller.go +++ b/controllers/dataplane/openstackdataplanenodeset_controller.go @@ -628,7 +628,11 @@ func (r *OpenStackDataPlaneNodeSetReconciler) SetupWithManager( return err } return ctrl.NewControllerManagedBy(mgr). - For(&dataplanev1.OpenStackDataPlaneNodeSet{}). + For(&dataplanev1.OpenStackDataPlaneNodeSet{}, + builder.WithPredicates(predicate.Or( + predicate.GenerationChangedPredicate{}, + predicate.AnnotationChangedPredicate{}, + predicate.LabelChangedPredicate{}))). Owns(&ansibleeev1.OpenStackAnsibleEE{}). Owns(&baremetalv1.OpenStackBaremetalSet{}). Owns(&infranetworkv1.IPSet{}). @@ -655,7 +659,6 @@ func (r *OpenStackDataPlaneNodeSetReconciler) secretWatcherFn( Log := r.GetLogger(ctx) nodeSets := &dataplanev1.OpenStackDataPlaneNodeSetList{} kind := strings.ToLower(obj.GetObjectKind().GroupVersionKind().Kind) - selector := "spec.ansibleVarsFrom.ansible.configMaps" if kind == "secret" { selector = "spec.ansibleVarsFrom.ansible.secrets" @@ -690,7 +693,6 @@ func (r *OpenStackDataPlaneNodeSetReconciler) genericWatcherFn( ) []reconcile.Request { Log := r.GetLogger(ctx) nodeSets := &dataplanev1.OpenStackDataPlaneNodeSetList{} - listOpts := []client.ListOption{ client.InNamespace(obj.GetNamespace()), } diff --git a/pkg/dataplane/service.go b/pkg/dataplane/service.go index f44bb2c95..2b22bfc0e 100644 --- a/pkg/dataplane/service.go +++ b/pkg/dataplane/service.go @@ -140,10 +140,6 @@ func EnsureServices(ctx context.Context, helper *helper.Helper, instance *datapl } _, err = controllerutil.CreateOrPatch(ctx, helper.GetClient(), ensureService, func() error { serviceObjSpec.DeepCopyInto(&ensureService.Spec) - ensureService.DefaultLabels() - if ensureService.Spec.EDPMServiceType == "" { - ensureService.Spec.EDPMServiceType = serviceObjMeta.Name - } return nil }) if err != nil {