-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
retrofit the scheduler with the leader election client. #19347
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"net" | ||
|
||
"k8s.io/kubernetes/pkg/api" | ||
"k8s.io/kubernetes/pkg/client/leaderelection" | ||
"k8s.io/kubernetes/pkg/master/ports" | ||
"k8s.io/kubernetes/plugin/pkg/scheduler/factory" | ||
|
||
|
@@ -41,6 +42,7 @@ type SchedulerServer struct { | |
KubeAPIQPS float32 | ||
KubeAPIBurst int | ||
SchedulerName string | ||
LeaderElection leaderelection.LeaderElectionCLIConfig | ||
} | ||
|
||
// NewSchedulerServer creates a new SchedulerServer with default parameters | ||
|
@@ -54,6 +56,7 @@ func NewSchedulerServer() *SchedulerServer { | |
KubeAPIQPS: 50.0, | ||
KubeAPIBurst: 100, | ||
SchedulerName: api.DefaultSchedulerName, | ||
LeaderElection: leaderelection.DefaultLeaderElectionCLIConfig(), | ||
} | ||
return &s | ||
} | ||
|
@@ -72,4 +75,5 @@ func (s *SchedulerServer) AddFlags(fs *pflag.FlagSet) { | |
fs.Float32Var(&s.KubeAPIQPS, "kube-api-qps", s.KubeAPIQPS, "QPS to use while talking with kubernetes apiserver") | ||
fs.IntVar(&s.KubeAPIBurst, "kube-api-burst", s.KubeAPIBurst, "Burst to use while talking with kubernetes apiserver") | ||
fs.StringVar(&s.SchedulerName, "scheduler-name", s.SchedulerName, "Name of the scheduler, used to select which pods will be processed by this scheduler, based on pod's annotation with key 'scheduler.alpha.kubernetes.io/name'") | ||
s.LeaderElection.BindFlags(fs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be doing this everywhere! |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import ( | |
"strconv" | ||
|
||
"k8s.io/kubernetes/pkg/api" | ||
"k8s.io/kubernetes/pkg/client/leaderelection" | ||
"k8s.io/kubernetes/pkg/client/record" | ||
client "k8s.io/kubernetes/pkg/client/unversioned" | ||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd" | ||
|
@@ -110,9 +111,44 @@ func Run(s *options.SchedulerServer) error { | |
eventBroadcaster.StartRecordingToSink(kubeClient.Events("")) | ||
|
||
sched := scheduler.New(config) | ||
sched.Run() | ||
|
||
select {} | ||
run := func(_ <-chan struct{}) { | ||
sched.Run() | ||
select {} | ||
} | ||
|
||
if !s.LeaderElection.LeaderElect { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment re: is there any reason to not have this always enabled? |
||
run(nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must be missing something -- while can't you just make this block say
instead of having a separate run() function? Is run() used from somewhere else that I missed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used again on line 43 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line 43 is an import line AFAICT There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davidopp sorry 143 |
||
glog.Fatal("this statement is unreachable") | ||
panic("unreachable") | ||
} | ||
|
||
id, err := os.Hostname() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
leaderelection.RunOrDie(leaderelection.LeaderElectionConfig{ | ||
EndpointsMeta: api.ObjectMeta{ | ||
Namespace: "kube-system", | ||
Name: "kube-scheduler", | ||
}, | ||
Client: kubeClient, | ||
Identity: id, | ||
EventRecorder: config.Recorder, | ||
LeaseDuration: s.LeaderElection.LeaseDuration, | ||
RenewDeadline: s.LeaderElection.RenewDeadline, | ||
RetryPeriod: s.LeaderElection.RetryPeriod, | ||
Callbacks: leaderelection.LeaderCallbacks{ | ||
OnStartedLeading: run, | ||
OnStoppedLeading: func() { | ||
glog.Fatalf("lost master") | ||
}, | ||
}, | ||
}) | ||
|
||
glog.Fatal("this statement is unreachable") | ||
panic("unreachable") | ||
} | ||
|
||
func createConfig(s *options.SchedulerServer, configFactory *factory.ConfigFactory) (*scheduler.Config, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any issue in O(1) case to not default to on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with that but I'd like to enable it by default only once we have an e2e test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe say "replicated scheduler for high availability" just to make sure people don't confuse this with running multiple schedulers for performance or partitioning diffrent scheduling algorithms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidopp - Good point, defaulting on would be bad in this case.