From a459198bfb96fd1ae966a1ad7f274eafc5efa0f0 Mon Sep 17 00:00:00 2001 From: Johannes Scheuermann Date: Thu, 18 Apr 2024 19:03:51 +0200 Subject: [PATCH] Remove unused indexer code (#1997) --- controllers/cluster_controller.go | 47 ++++++------------------------- setup/setup.go | 6 ++-- 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/controllers/cluster_controller.go b/controllers/cluster_controller.go index 06e3d7e3..6cefb27c 100644 --- a/controllers/cluster_controller.go +++ b/controllers/cluster_controller.go @@ -246,50 +246,19 @@ func runClusterSubReconciler(ctx context.Context, logger logr.Logger, subReconci } // updateIndexerForManager will set all the required field indexer for the FoundationDBClusterReconciler. -func (r *FoundationDBClusterReconciler) updateIndexerForManager(mgr ctrl.Manager, enableNodeIndex bool) error { - // TODO (johscheuer): Validate if all those indexers are still needed as we changed the way how the operator - // fetches the information. - // See: https://github.com/FoundationDB/fdb-kubernetes-operator/issues/1996 - err := mgr.GetFieldIndexer().IndexField(context.Background(), &corev1.Pod{}, "metadata.name", func(o client.Object) []string { - return []string{o.(*corev1.Pod).Name} - }) - if err != nil { - return err - } - - if enableNodeIndex { - err = mgr.GetFieldIndexer().IndexField(context.Background(), &corev1.Node{}, "metadata.name", func(o client.Object) []string { - return []string{o.(*corev1.Node).Name} - }) - if err != nil { - return err - } - - if r.ClusterLabelKeyForNodeTrigger != "" { - err = mgr.GetFieldIndexer().IndexField(context.Background(), &corev1.Pod{}, "spec.nodeName", func(o client.Object) []string { - return []string{o.(*corev1.Pod).Spec.NodeName} - }) - if err != nil { - return err - } - } - } - - err = mgr.GetFieldIndexer().IndexField(context.Background(), &corev1.Service{}, "metadata.name", func(o client.Object) []string { - return []string{o.(*corev1.Service).Name} - }) - if err != nil { - return err +func (r *FoundationDBClusterReconciler) updateIndexerForManager(mgr ctrl.Manager) error { + if r.ClusterLabelKeyForNodeTrigger == "" { + return nil } - return mgr.GetFieldIndexer().IndexField(context.Background(), &corev1.PersistentVolumeClaim{}, "metadata.name", func(o client.Object) []string { - return []string{o.(*corev1.PersistentVolumeClaim).Name} + return mgr.GetFieldIndexer().IndexField(context.Background(), &corev1.Pod{}, "spec.nodeName", func(o client.Object) []string { + return []string{o.(*corev1.Pod).Spec.NodeName} }) } // SetupWithManager prepares the FoundationDBClusterReconciler for use. -func (r *FoundationDBClusterReconciler) SetupWithManager(mgr ctrl.Manager, maxConcurrentReconciles int, enableNodeIndex bool, selector metav1.LabelSelector, watchedObjects ...client.Object) error { - err := r.updateIndexerForManager(mgr, enableNodeIndex) +func (r *FoundationDBClusterReconciler) SetupWithManager(mgr ctrl.Manager, maxConcurrentReconciles int, selector metav1.LabelSelector, watchedObjects ...client.Object) error { + err := r.updateIndexerForManager(mgr) if err != nil { return err } @@ -322,7 +291,7 @@ func (r *FoundationDBClusterReconciler) SetupWithManager(mgr ctrl.Manager, maxCo Owns(&corev1.ConfigMap{}, globalPredicate). Owns(&corev1.Service{}, globalPredicate) - if r.ClusterLabelKeyForNodeTrigger != "" && enableNodeIndex { + if r.ClusterLabelKeyForNodeTrigger != "" { managerBuilder.Watches( &source.Kind{Type: &corev1.Node{}}, handler.EnqueueRequestsFromMapFunc(r.findFoundationDBClusterForNode), diff --git a/setup/setup.go b/setup/setup.go index ff1336f4..29707f85 100644 --- a/setup/setup.go +++ b/setup/setup.go @@ -120,7 +120,7 @@ func (o *Options) BindFlags(fs *flag.FlagSet) { fs.StringVar(&o.LogFilePermission, "log-file-permission", "0644", "The file permission for the log file. Only used if log-file is set. Only the octal representation is supported.") fs.StringVar(&o.ClusterLabelKeyForNodeTrigger, "cluster-label-key-for-node-trigger", "", - "The label key to use to trigger a reconciliation if a node resources changes. Requires that --enable-node-index is set to true.") + "The label key to use to trigger a reconciliation if a node resources changes.") fs.IntVar(&o.MaxNumberOfOldLogFiles, "max-old-log-files", 3, "Defines the maximum number of old operator log files to retain.") fs.BoolVar(&o.CompressOldFiles, "compress", false, "Defines whether the rotated log files should be compressed using gzip or not.") fs.BoolVar(&o.PrintVersion, "version", false, "Prints the version of the operator and exits.") @@ -138,7 +138,7 @@ func (o *Options) BindFlags(fs *flag.FlagSet) { fs.BoolVar(&o.ServerSideApply, "server-side-apply", false, "This flag enables server side apply.") fs.BoolVar(&o.EnableRecoveryState, "enable-recovery-state", true, "This flag enables the use of the recovery state for the minimum uptime between bounced if the FDB version supports it.") fs.BoolVar(&o.CacheDatabaseStatus, "cache-database-status", true, "Defines the default value for caching the database status.") - fs.BoolVar(&o.EnableNodeIndex, "enable-node-index", false, "Defines if the operator should add an index for accessing node objects. This requires a ClusterRoleBinding with node access. If the taint feature should be used, this setting should be set to true.") + fs.BoolVar(&o.EnableNodeIndex, "enable-node-index", false, "Deprecated, not used anymore. Defines if the operator should add an index for accessing node objects. This requires a ClusterRoleBinding with node access. If the taint feature should be used, this setting should be set to true.") fs.Float64Var(&o.MinimumRecoveryTimeForInclusion, "minimum-recovery-time-for-inclusion", 600.0, "Defines the minimum uptime of the cluster before inclusions are allowed. For clusters after 7.1 this will use the recovery state. This should reduce the risk of frequent recoveries because of inclusions.") fs.Float64Var(&o.MinimumRecoveryTimeForExclusion, "minimum-recovery-time-for-exclusion", 120.0, "Defines the minimum uptime of the cluster before exclusions are allowed. For clusters after 7.1 this will use the recovery state. This should reduce the risk of frequent recoveries because of exclusions.") } @@ -270,7 +270,7 @@ func StartManager( clusterReconciler.ClusterLabelKeyForNodeTrigger = strings.Trim(operatorOpts.ClusterLabelKeyForNodeTrigger, "\"") clusterReconciler.Namespace = operatorOpts.WatchNamespace - if err := clusterReconciler.SetupWithManager(mgr, operatorOpts.MaxConcurrentReconciles, operatorOpts.EnableNodeIndex, *labelSelector, watchedObjects...); err != nil { + if err := clusterReconciler.SetupWithManager(mgr, operatorOpts.MaxConcurrentReconciles, *labelSelector, watchedObjects...); err != nil { setupLog.Error(err, "unable to create controller", "controller", "FoundationDBCluster") os.Exit(1) }