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

Fix rest stop bug #74

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 17 additions & 13 deletions pkg/framework/kubescheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,23 @@ func WithTerminatingPods(with bool) Option {
// for kubeconfig nor for apiserver url
func NewKubeSchedulerFramework(kubeSchedulerConfig *schedconfig.CompletedConfig, restConfig *restclient.Config, options ...Option) (pkg.Framework, error) {
kubeSchedulerConfig.InformerFactory.InformerFor(&corev1.Pod{}, newPodInformer)

dynamicClient := dynamic.NewForConfigOrDie(restConfig)
restMapper, err := apiutil.NewDynamicRESTMapper(restConfig)
if err != nil {
return nil, err
var err error
var restMapper meta.RESTMapper
var dynamicClient *dynamic.DynamicClient
var dynInformerFactory dynamicinformer.DynamicSharedInformerFactory
if restConfig != nil {
if restMapper, err = apiutil.NewDynamicRESTMapper(restConfig); err != nil {
return nil, err
}
dynamicClient = dynamic.NewForConfigOrDie(restConfig)
// only for latest k8s version
dynInformerFactory = dynamicinformer.NewFilteredDynamicSharedInformerFactory(dynamicClient, 0, corev1.NamespaceAll, nil)
}

s := &kubeschedulerFramework{
fakeClient: kubeSchedulerConfig.Client,
dynamicClient: dynamicClient,
dynInformerFactory: dynInformerFactory,
restMapper: restMapper,
stopCh: make(chan struct{}),
fakeInformerFactory: kubeSchedulerConfig.InformerFactory,
Expand All @@ -251,12 +258,6 @@ func NewKubeSchedulerFramework(kubeSchedulerConfig *schedconfig.CompletedConfig,
option(s)
}

// only for latest k8s version
if restConfig != nil {
dynClient := dynamic.NewForConfigOrDie(restConfig)
s.dynInformerFactory = dynamicinformer.NewFilteredDynamicSharedInformerFactory(dynClient, 0, corev1.NamespaceAll, nil)
}

scheduler, err := s.createScheduler(kubeSchedulerConfig)
if err != nil {
return nil, err
Expand Down Expand Up @@ -293,7 +294,7 @@ func (s *kubeschedulerFramework) GetPodsByNode(nodeName string) ([]*corev1.Pod,
// InitTheWorld use objs outside or default init resources to initialize the scheduler
// the objs outside must be typed object.
func (s *kubeschedulerFramework) InitTheWorld(objs ...runtime.Object) error {
if len(objs) == 0 {
if len(objs) == 0 && s.dynamicClient != nil {
// black magic
klog.V(2).InfoS("Init the world form running cluster")
initObjects := getInitObjects(s.restMapper, s.dynamicClient)
Expand Down Expand Up @@ -399,7 +400,10 @@ func (s *kubeschedulerFramework) Run() error {
if s.dynInformerFactory != nil {
s.dynInformerFactory.WaitForCacheSync(s.informerCh)
}
go s.scheduler.Run(context.TODO())

ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
go s.scheduler.Run(ctx)

<-s.stopCh

Expand Down