Skip to content

Commit

Permalink
Remove unused indexer code (#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
johscheuer authored Apr 18, 2024
1 parent 8370709 commit a459198
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 42 deletions.
47 changes: 8 additions & 39 deletions controllers/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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.")
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit a459198

Please sign in to comment.