Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve FieldIndexer setting in yurt-manager #1834

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/yurtmanager/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"context"
"fmt"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/controller-manager/app"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/openyurtio/openyurt/cmd/yurt-manager/app/config"
Expand Down Expand Up @@ -120,5 +122,23 @@ func SetupWithManager(ctx context.Context, c *config.CompletedConfig, m manager.
}
}

if app.IsControllerEnabled(names.NodeLifeCycleController, ControllersDisabledByDefault, c.ComponentConfig.Generic.Controllers) ||
app.IsControllerEnabled(names.PodBindingController, ControllersDisabledByDefault, c.ComponentConfig.Generic.Controllers) {
// Register spec.NodeName field indexers
if err := m.GetFieldIndexer().IndexField(context.TODO(), &v1.Pod{}, "spec.nodeName", func(rawObj client.Object) []string {
pod, ok := rawObj.(*v1.Pod)
if !ok {
return []string{}
}
if len(pod.Spec.NodeName) == 0 {
return []string{}
}
return []string{pod.Spec.NodeName}
}); err != nil {
klog.Errorf("could not register spec.NodeName field indexers %v", err)
return err
}
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,6 @@ func Add(ctx context.Context, cfg *appconfig.CompletedConfig, mgr manager.Manage
},
}
c.Watch(&source.Kind{Type: &v1.Pod{}}, &handler.Funcs{}, podsPredicate)
if err := mgr.GetFieldIndexer().IndexField(context.TODO(), &v1.Pod{}, nodeNameKeyIndex, func(rawObj client.Object) []string {
pod, ok := rawObj.(*v1.Pod)
if !ok {
return []string{}
}
if len(pod.Spec.NodeName) == 0 {
return []string{}
}
return []string{pod.Spec.NodeName}
}); err != nil {
klog.Errorf("could not register spec.NodeName field indexers for nodelifecycle controller, %v", err)
return err
}

nc.taintManager = scheduler.NewNoExecuteTaintManager(nc.recorder, nc.controllerRuntimeClient, nc.getPodsAssignedToNode)
nodesTaintManagerPredicate := predicate.Funcs{
Expand Down
Loading