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

scheduler: refactor main entry Run() #38572

Merged
merged 2 commits into from
Dec 13, 2016

Conversation

hongchaodeng
Copy link
Contributor

@hongchaodeng hongchaodeng commented Dec 11, 2016

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 11, 2016
@k8s-reviewable
Copy link

This change is Reviewable

@hongchaodeng
Copy link
Contributor Author

cc @timothysc @xiang90
Can you help review this?

@davidopp davidopp assigned wojtek-t and unassigned davidopp Dec 11, 2016
@@ -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)
Copy link
Contributor

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")
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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?

@xiang90
Copy link
Contributor

xiang90 commented Dec 11, 2016

Minor issues. LGTM after fixing them.

@hongchaodeng
Copy link
Contributor Author

Fixed minor issues

@xiang90
Copy link
Contributor

xiang90 commented Dec 12, 2016

@hongchaodeng Awesome. Thanks!

@hongchaodeng
Copy link
Contributor Author

@k8s-bot unit test this #38594

@hongchaodeng
Copy link
Contributor Author

@k8s-bot cri e2e test this #38556

@hongchaodeng
Copy link
Contributor Author

@k8s-bot cri e2e test this

@k8s-ci-robot
Copy link
Contributor

Jenkins CRI GCE e2e failed for commit 7bd580caf9f1e492624af42d0fb3864dcb0cead5. Full PR test history.

The magic incantation to run this job again is @k8s-bot cri e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@hongchaodeng
Copy link
Contributor Author

@wojtek

Can you help review?

goruntime.SetBlockProfileRate(1)
}
}
if c, err := configz.New("componentconfig"); err == nil {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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")
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k.

Copy link
Member

@timothysc timothysc left a 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

@k8s-ci-robot
Copy link
Contributor

Jenkins GCI GKE smoke e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history.

The magic incantation to run this job again is @k8s-bot gci gke e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins GCE etcd3 e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history.

The magic incantation to run this job again is @k8s-bot gce etcd3 e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins CRI GCE Node e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history.

The magic incantation to run this job again is @k8s-bot cri node e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins verification failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history.

The magic incantation to run this job again is @k8s-bot verify test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins GCE e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history.

The magic incantation to run this job again is @k8s-bot cvm gce e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins unit/integration failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history.

The magic incantation to run this job again is @k8s-bot unit test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins GKE smoke e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history.

The magic incantation to run this job again is @k8s-bot cvm gke e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins GCE Node e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history.

The magic incantation to run this job again is @k8s-bot node e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins Kubemark GCE e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history.

The magic incantation to run this job again is @k8s-bot kubemark e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins GCI GCE e2e failed for commit a6bfeae99555a59b6c201bd13dab5c3ce70f2712. Full PR test history.

The magic incantation to run this job again is @k8s-bot gci gce e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@timothysc timothysc added release-note-none Denotes a PR that doesn't merit a release note. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. and removed release-note-label-needed labels Dec 12, 2016
@timothysc timothysc added this to the v1.6 milestone Dec 12, 2016
@timothysc
Copy link
Member

lgtm.

@timothysc timothysc self-assigned this Dec 12, 2016
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 38315, 38624, 38572, 38544)

@k8s-github-robot k8s-github-robot merged commit 65238bc into kubernetes:master Dec 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants