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

cleanly execute scheduler and kubecontrollermanager via cobra command #18139

Merged
merged 5 commits into from
Jan 20, 2018
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
250 changes: 250 additions & 0 deletions contrib/completions/bash/oc

Large diffs are not rendered by default.

250 changes: 250 additions & 0 deletions contrib/completions/zsh/oc

Large diffs are not rendered by default.

38 changes: 14 additions & 24 deletions pkg/cmd/server/start/start_kube_controller_manager.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
package start

import (
"fmt"
"strconv"

"github.com/golang/glog"
"github.com/spf13/pflag"

kerrors "k8s.io/apimachinery/pkg/util/errors"
controllerapp "k8s.io/kubernetes/cmd/kube-controller-manager/app"
controlleroptions "k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
_ "k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider"

cmdflags "github.com/openshift/origin/pkg/cmd/util/flags"
)

func kubeControllerManagerAddFlags(cmserver *controlleroptions.CMServer) func(flags *pflag.FlagSet) {
return func(flags *pflag.FlagSet) {
cmserver.AddFlags(flags, controllerapp.KnownControllers(), controllerapp.ControllersDisabledByDefault.List())
}
}

func newKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCAFile, podEvictionTimeout, openshiftConfigFile string, dynamicProvisioningEnabled bool) (*controlleroptions.CMServer, error) {
func computeKubeControllerManagerArgs(kubeconfigFile, saPrivateKeyFile, saRootCAFile, podEvictionTimeout, openshiftConfigFile string, dynamicProvisioningEnabled bool) []string {
cmdLineArgs := map[string][]string{}
if _, ok := cmdLineArgs["controllers"]; !ok {
cmdLineArgs["controllers"] = []string{
Expand Down Expand Up @@ -77,22 +67,22 @@ func newKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCAFile, po
}
cmdLineArgs["openshift-config"] = []string{openshiftConfigFile}

// resolve arguments
controllerManager := controlleroptions.NewCMServer()
if err := cmdflags.Resolve(cmdLineArgs, kubeControllerManagerAddFlags(controllerManager)); len(err) > 0 {
return nil, kerrors.NewAggregate(err)
args := []string{}
for key, value := range cmdLineArgs {
for _, token := range value {
args = append(args, fmt.Sprintf("--%s=%v", key, token))
}
}

return controllerManager, nil
return args
}

func runEmbeddedKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCAFile, podEvictionTimeout, openshiftConfigFile string, dynamicProvisioningEnabled bool) {
// TODO we need a real identity for this. Right now it's just using the loopback connection like it used to.
controllerManager, err := newKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCAFile, podEvictionTimeout, openshiftConfigFile, dynamicProvisioningEnabled)
if err != nil {
glog.Fatal(err)
}
if err := controllerapp.Run(controllerManager); err != nil {
cmd := controllerapp.NewControllerManagerCommand()
args := computeKubeControllerManagerArgs(kubeconfigFile, saPrivateKeyFile, saRootCAFile, podEvictionTimeout, openshiftConfigFile, dynamicProvisioningEnabled)
if err := cmd.ParseFlags(args); err != nil {
glog.Fatal(err)
}
glog.Infof("`kube-controller-manager %v`", args)
cmd.Run(nil, nil)
panic(fmt.Sprintf("`kube-controller-manager %v` exited", args))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intentional here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this intentional here?

Yes. Because we can't re-init, we need to die. And if we loop, we'll want to know why

}
47 changes: 17 additions & 30 deletions pkg/cmd/server/start/start_kube_scheduler.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package start

import (
"fmt"
"time"

"github.com/golang/glog"
"github.com/spf13/pflag"

kerrors "k8s.io/apimachinery/pkg/util/errors"
schedulerapp "k8s.io/kubernetes/plugin/cmd/kube-scheduler/app"
_ "k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider"

cmdflags "github.com/openshift/origin/pkg/cmd/util/flags"
)

func newScheduler(kubeconfigFile, schedulerConfigFile string, schedulerArgs map[string][]string) (*schedulerapp.Options, error) {
func computeSchedulerArgs(kubeconfigFile, schedulerConfigFile string, schedulerArgs map[string][]string) []string {
cmdLineArgs := map[string][]string{}
// deep-copy the input args to avoid mutation conflict.
for k, v := range schedulerArgs {
Expand All @@ -35,35 +34,23 @@ func newScheduler(kubeconfigFile, schedulerConfigFile string, schedulerArgs map[
cmdLineArgs["port"] = []string{"-1"}
}

// resolve arguments
schedulerOptions, err := schedulerapp.NewOptions()
if err != nil {
return nil, err
}
if err := schedulerOptions.ReallyApplyDefaults(); err != nil {
return nil, err
}
if err := cmdflags.Resolve(cmdLineArgs, func(fs *pflag.FlagSet) {
schedulerapp.AddFlags(schedulerOptions, fs)
}); len(err) > 0 {
return nil, kerrors.NewAggregate(err)
args := []string{}
for key, value := range cmdLineArgs {
for _, token := range value {
args = append(args, fmt.Sprintf("--%s=%v", key, token))
}
}
if err := schedulerOptions.Complete(); err != nil {
return nil, err
}

return schedulerOptions, nil
return args
}

func runEmbeddedScheduler(kubeconfigFile, schedulerConfigFile string, cmdLineArgs map[string][]string) {
// TODO we need a real identity for this. Right now it's just using the loopback connection like it used to.
schedulerOptions, err := newScheduler(kubeconfigFile, schedulerConfigFile, cmdLineArgs)
if err != nil {
glog.Fatal(err)
}
// this does a second leader election, but doing the second leader election will allow us to move out process in
// 3.8 if we so choose.
if err := schedulerOptions.Run(); err != nil {
cmd := schedulerapp.NewSchedulerCommand()
args := computeSchedulerArgs(kubeconfigFile, schedulerConfigFile, cmdLineArgs)
if err := cmd.ParseFlags(args); err != nil {
glog.Fatal(err)
}
glog.Infof("`kube-scheduler %v`", args)
cmd.Run(nil, nil)
glog.Fatalf("`kube-scheduler %v` exited", args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as above.

time.Sleep(10 * time.Second)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 0 additions & 52 deletions vendor/k8s.io/kubernetes/cmd/hyperkube/kube-aggregator.go

This file was deleted.

1 change: 0 additions & 1 deletion vendor/k8s.io/kubernetes/cmd/hyperkube/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions vendor/k8s.io/kubernetes/cmd/kube-apiserver/apiserver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions vendor/k8s.io/kubernetes/cmd/kube-apiserver/app/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading