k3s/vendor/k8s.io/kubernetes/cmd/hyperkube/main.go

122 lines
3.6 KiB
Go
Raw Normal View History

2019-01-12 04:58:27 +00:00
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// A binary that can morph into all of the other kubernetes binaries. You can
// also soft-link to it busybox style.
//
package main
import (
goflag "flag"
"math/rand"
"os"
"path/filepath"
"time"
2019-09-27 21:51:53 +00:00
"k8s.io/apiserver/pkg/server"
2019-01-12 04:58:27 +00:00
"github.com/spf13/cobra"
"github.com/spf13/pflag"
2019-04-07 17:07:55 +00:00
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
2019-09-27 21:51:53 +00:00
_ "k8s.io/component-base/metrics/prometheus/restclient" // for client metric registration
2019-01-12 04:58:27 +00:00
kubeapiserver "k8s.io/kubernetes/cmd/kube-apiserver/app"
kubecontrollermanager "k8s.io/kubernetes/cmd/kube-controller-manager/app"
kubeproxy "k8s.io/kubernetes/cmd/kube-proxy/app"
kubescheduler "k8s.io/kubernetes/cmd/kube-scheduler/app"
kubelet "k8s.io/kubernetes/cmd/kubelet/app"
kubectl "k8s.io/kubernetes/pkg/kubectl/cmd"
_ "k8s.io/kubernetes/pkg/version/prometheus" // for version metric registration
)
func main() {
rand.Seed(time.Now().UnixNano())
2019-08-30 18:33:25 +00:00
hyperkubeCommand, allCommandFns := NewHyperKubeCommand()
2019-01-12 04:58:27 +00:00
// TODO: once we switch everything over to Cobra commands, we can go back to calling
2019-04-07 17:07:55 +00:00
// cliflag.InitFlags() (by removing its pflag.Parse() call). For now, we have to set the
2019-01-12 04:58:27 +00:00
// normalize func and add the go flag set by hand.
2019-04-07 17:07:55 +00:00
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
2019-01-12 04:58:27 +00:00
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
2019-04-07 17:07:55 +00:00
// cliflag.InitFlags()
2019-01-12 04:58:27 +00:00
logs.InitLogs()
defer logs.FlushLogs()
basename := filepath.Base(os.Args[0])
if err := commandFor(basename, hyperkubeCommand, allCommandFns).Execute(); err != nil {
os.Exit(1)
}
}
func commandFor(basename string, defaultCommand *cobra.Command, commands []func() *cobra.Command) *cobra.Command {
for _, commandFn := range commands {
command := commandFn()
if command.Name() == basename {
return command
}
for _, alias := range command.Aliases {
if alias == basename {
return command
}
}
}
return defaultCommand
}
// NewHyperKubeCommand is the entry point for hyperkube
2019-08-30 18:33:25 +00:00
func NewHyperKubeCommand() (*cobra.Command, []func() *cobra.Command) {
2019-04-07 17:07:55 +00:00
// these have to be functions since the command is polymorphic. Cobra wants you to be top level
2019-01-12 04:58:27 +00:00
// command to get executed
2019-08-30 18:33:25 +00:00
stopCh := server.SetupSignalHandler()
apiserver := func() *cobra.Command { return kubeapiserver.NewAPIServerCommand(stopCh) }
controller := func() *cobra.Command { return kubecontrollermanager.NewControllerManagerCommand() }
proxy := func() *cobra.Command { return kubeproxy.NewProxyCommand() }
scheduler := func() *cobra.Command { return kubescheduler.NewSchedulerCommand() }
2019-01-12 04:58:27 +00:00
kubectlCmd := func() *cobra.Command { return kubectl.NewDefaultKubectlCommand() }
kubelet := func() *cobra.Command { return kubelet.NewKubeletCommand(stopCh) }
commandFns := []func() *cobra.Command{
apiserver,
controller,
proxy,
scheduler,
kubectlCmd,
kubelet,
}
cmd := &cobra.Command{
Use: "hyperkube",
Short: "Request a new project",
Run: func(cmd *cobra.Command, args []string) {
2019-09-27 21:51:53 +00:00
if len(args) != 0 {
2019-01-12 04:58:27 +00:00
cmd.Help()
os.Exit(1)
}
},
}
for i := range commandFns {
cmd.AddCommand(commandFns[i]())
}
return cmd, commandFns
}