-
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
scheduler: refactor main entry Run() #38572
Conversation
cc @timothysc @xiang90 |
@@ -36,5 +37,8 @@ func main() { | |||
|
|||
verflag.PrintAndExitIfRequested() | |||
|
|||
app.Run(s) | |||
if err := app.Run(s); err != nil { | |||
glog.Errorf("scheduler app failed to run: %v", err) |
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.
glog.Fatal here? or we can reach line 43.
if err := app.Run(s); err != nil { | ||
glog.Errorf("scheduler app failed to run: %v", err) | ||
} | ||
glog.Fatal("this statement shouldn't be reached") |
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.
we should panic on a unreachable line not fatal. usually fatal on unrecoverable external error, and panic on unrecoverable internal error.
run := func(_ <-chan struct{}) { | ||
sched.Run() | ||
select {} | ||
} | ||
|
||
if !s.LeaderElection.LeaderElect { | ||
run(nil) | ||
glog.Fatal("this statement is unreachable") | ||
panic("unreachable") | ||
return nil |
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.
probably should still panic internally.
|
||
cli, err := clientset.NewForConfig(restclient.AddUserAgent(kubeconfig, "leader-election")) | ||
if err != nil { | ||
return nil, fmt.Errorf("Invalid API configuration: %v", err) |
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.
invalid API configuration: %v
func createClient(s *options.SchedulerServer) (*clientset.Clientset, error) { | ||
kubeconfig, err := clientcmd.BuildConfigFromFlags(s.Master, s.Kubeconfig) | ||
if err != nil { | ||
glog.Errorf("unable to build config from flags: %v", err) |
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.
we should log error in the caller?
Minor issues. LGTM after fixing them. |
Fixed minor issues |
@hongchaodeng Awesome. Thanks! |
@k8s-bot cri e2e test this |
Jenkins CRI GCE e2e failed for commit 7bd580caf9f1e492624af42d0fb3864dcb0cead5. Full PR test history. The magic incantation to run this job again is |
Can you help review? |
goruntime.SetBlockProfileRate(1) | ||
} | ||
} | ||
if c, err := configz.New("componentconfig"); err == nil { |
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.
It's difficult to tell, but did you ensure this was the 1st place configz was used in the shuffling. B4 it was the 1st line before refactoring.
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.
Pretty sure it's fine. Tested and verified.
If you looked at the commit 5ec02bd, it actually wasn't used anywhere else.
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.
Not sure why it needs to be put 1st line.
cc original author @mikedanese
if err := app.Run(s); err != nil { | ||
glog.Fatalf("scheduler app failed to run: %v", err) | ||
} | ||
panic("this statement shouldn't be reached") |
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 don't think this logic makes much sense.. of course we can reach this point via a number of ways. Shouldn't we just exit gracefully?
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 will remove this one.
of course we can reach this point via a number of ways.
IIRC, no way to reach here? Can you clarify?
if err != nil { | ||
glog.Fatalf("Invalid API configuration: %v", err) | ||
return fmt.Errorf("unable to create kube client: %v", err) |
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.
Does it make sense to re-wrap the error or just return them? I just debate the utility if we're refactoring.
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.
The previous code usually Fatalf() right there. Now We Fatalf() outside, and thus it's better to wrap them.
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.
k.
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.
Please answer the minor comments, otherwise lgtm
Jenkins GCI GKE smoke e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history. The magic incantation to run this job again is |
Jenkins GCE etcd3 e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history. The magic incantation to run this job again is |
Jenkins CRI GCE Node e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history. The magic incantation to run this job again is |
Jenkins verification failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history. The magic incantation to run this job again is |
Jenkins GCE e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history. The magic incantation to run this job again is |
Jenkins unit/integration failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history. The magic incantation to run this job again is |
Jenkins GKE smoke e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history. The magic incantation to run this job again is |
Jenkins GCE Node e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history. The magic incantation to run this job again is |
Jenkins Kubemark GCE e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history. The magic incantation to run this job again is |
Jenkins GCI GCE e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history. The magic incantation to run this job again is |
lgtm. |
Automatic merge from submit-queue (batch tested with PRs 38315, 38624, 38572, 38544) |
The kube-scheduler/app.Run() is the main entry of scheduler program.
It's enormous.
This PR tries to clean it up. Should be more modular and readable.