From 0810e1fa992e055c62f00c05a5aaf01ea142de80 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Feb 2015 14:21:41 -0800 Subject: [PATCH 01/11] build hyperkube --- hack/lib/golang.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index 3438f5042d6..2d3f092f84c 100644 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -24,6 +24,7 @@ readonly KUBE_SERVER_TARGETS=( cmd/kube-apiserver cmd/kube-controller-manager cmd/kubelet + cmd/hyperkube plugin/cmd/kube-scheduler ) readonly KUBE_SERVER_BINARIES=("${KUBE_SERVER_TARGETS[@]##*/}") From 710157ac9e64464f3b9150bfae18e39fce2fcc2a Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Feb 2015 13:20:42 -0800 Subject: [PATCH 02/11] simplify hyperkube prints --- pkg/hyperkube/hyperkube.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/hyperkube/hyperkube.go b/pkg/hyperkube/hyperkube.go index 72e67683fef..f38aec289e2 100644 --- a/pkg/hyperkube/hyperkube.go +++ b/pkg/hyperkube/hyperkube.go @@ -101,14 +101,12 @@ func (hk *HyperKube) Print(i ...interface{}) { // Println is a convenience method to Println to the defined output func (hk *HyperKube) Println(i ...interface{}) { - str := fmt.Sprintln(i...) - hk.Print(str) + fmt.Fprintln(hk.Out(), i...) } // Printf is a convenience method to Printf to the defined output func (hk *HyperKube) Printf(format string, i ...interface{}) { - str := fmt.Sprintf(format, i...) - hk.Print(str) + fmt.Fprintf(hk.Out(), format, i...) } // Run the server. This will pick the appropriate server and run it. From 7fe7f8a542bfeec73c23ac4280cc3ec0cc57cb74 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Feb 2015 13:30:53 -0800 Subject: [PATCH 03/11] move pkg/kubelet/server to cmd/kubelet/app --- cmd/hyperkube/hyperkube.go | 2 +- cmd/integration/integration.go | 6 +++--- {pkg/kubelet/server => cmd/kubelet/app}/plugins.go | 2 +- {pkg/kubelet/server => cmd/kubelet/app}/server.go | 4 ++-- cmd/kubelet/kubelet.go | 4 ++-- cmd/kubernetes/kubernetes.go | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) rename {pkg/kubelet/server => cmd/kubelet/app}/plugins.go (99%) rename {pkg/kubelet/server => cmd/kubelet/app}/server.go (99%) diff --git a/cmd/hyperkube/hyperkube.go b/cmd/hyperkube/hyperkube.go index 877048bad38..9e925de8877 100644 --- a/cmd/hyperkube/hyperkube.go +++ b/cmd/hyperkube/hyperkube.go @@ -21,9 +21,9 @@ package main import ( "os" + kubelet "github.com/GoogleCloudPlatform/kubernetes/cmd/kubelet/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/controllermanager" "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" - kubelet "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/server" apiserver "github.com/GoogleCloudPlatform/kubernetes/pkg/master/server" proxy "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/server" sched "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/server" diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index 0b27821130a..08b6eaecb02 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -32,6 +32,7 @@ import ( "sync" "time" + kubeletapp "github.com/GoogleCloudPlatform/kubernetes/cmd/kubelet/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" @@ -41,7 +42,6 @@ import ( nodeControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller" replicationControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/controller" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools" - kubeletServer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/server" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume/empty_dir" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/master" @@ -211,13 +211,13 @@ func startComponents(manifestURL string) (apiServerURL string) { // Kubelet (localhost) testRootDir := makeTempDirOrDie("kubelet_integ_1.") glog.Infof("Using %s as root dir for kubelet #1", testRootDir) - kubeletServer.SimpleRunKubelet(cl, nil, &fakeDocker1, machineList[0], testRootDir, manifestURL, "127.0.0.1", 10250, api.NamespaceDefault, empty_dir.ProbeVolumePlugins()) + kubeletapp.SimpleRunKubelet(cl, nil, &fakeDocker1, machineList[0], testRootDir, manifestURL, "127.0.0.1", 10250, api.NamespaceDefault, empty_dir.ProbeVolumePlugins()) // Kubelet (machine) // Create a second kubelet so that the guestbook example's two redis slaves both // have a place they can schedule. testRootDir = makeTempDirOrDie("kubelet_integ_2.") glog.Infof("Using %s as root dir for kubelet #2", testRootDir) - kubeletServer.SimpleRunKubelet(cl, nil, &fakeDocker2, machineList[1], testRootDir, "", "127.0.0.1", 10251, api.NamespaceDefault, empty_dir.ProbeVolumePlugins()) + kubeletapp.SimpleRunKubelet(cl, nil, &fakeDocker2, machineList[1], testRootDir, "", "127.0.0.1", 10251, api.NamespaceDefault, empty_dir.ProbeVolumePlugins()) return apiServer.URL } diff --git a/pkg/kubelet/server/plugins.go b/cmd/kubelet/app/plugins.go similarity index 99% rename from pkg/kubelet/server/plugins.go rename to cmd/kubelet/app/plugins.go index ceb573dce64..130e72f153d 100644 --- a/pkg/kubelet/server/plugins.go +++ b/cmd/kubelet/app/plugins.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package server +package app // This file exists to force the desired plugin implementations to be linked. import ( diff --git a/pkg/kubelet/server/server.go b/cmd/kubelet/app/server.go similarity index 99% rename from pkg/kubelet/server/server.go rename to cmd/kubelet/app/server.go index 0d35b789979..d61c424125c 100644 --- a/pkg/kubelet/server/server.go +++ b/cmd/kubelet/app/server.go @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package server makes it easy to create a kubelet server for various contexts. -package server +// Package app makes it easy to create a kubelet server for various contexts. +package app import ( "fmt" diff --git a/cmd/kubelet/kubelet.go b/cmd/kubelet/kubelet.go index a49c36af9f5..78bb915b62c 100644 --- a/cmd/kubelet/kubelet.go +++ b/cmd/kubelet/kubelet.go @@ -25,7 +25,7 @@ import ( "os" "runtime" - "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/server" + "github.com/GoogleCloudPlatform/kubernetes/cmd/kubelet/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" @@ -34,7 +34,7 @@ import ( func main() { runtime.GOMAXPROCS(runtime.NumCPU()) - s := server.NewKubeletServer() + s := app.NewKubeletServer() s.AddFlags(pflag.CommandLine) util.InitFlags() diff --git a/cmd/kubernetes/kubernetes.go b/cmd/kubernetes/kubernetes.go index 3eaac111873..5528ab24330 100644 --- a/cmd/kubernetes/kubernetes.go +++ b/cmd/kubernetes/kubernetes.go @@ -28,6 +28,7 @@ import ( "runtime" "time" + kubeletapp "github.com/GoogleCloudPlatform/kubernetes/cmd/kubelet/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi" @@ -36,7 +37,6 @@ import ( nodeControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller" "github.com/GoogleCloudPlatform/kubernetes/pkg/controller" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools" - kubeletServer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/server" "github.com/GoogleCloudPlatform/kubernetes/pkg/master" "github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports" "github.com/GoogleCloudPlatform/kubernetes/pkg/service" @@ -144,7 +144,7 @@ func startComponents(etcdClient tools.EtcdClient, cl *client.Client, addr net.IP runControllerManager(machineList, cl, *nodeMilliCPU, *nodeMemory) dockerClient := dockertools.ConnectToDockerOrDie(*dockerEndpoint) - kubeletServer.SimpleRunKubelet(cl, nil, dockerClient, machineList[0], "/tmp/kubernetes", "", "127.0.0.1", 10250, *masterServiceNamespace, kubeletServer.ProbeVolumePlugins()) + kubeletapp.SimpleRunKubelet(cl, nil, dockerClient, machineList[0], "/tmp/kubernetes", "", "127.0.0.1", 10250, *masterServiceNamespace, kubeletapp.ProbeVolumePlugins()) } func newApiClient(addr net.IP, port int) *client.Client { From 9f1451121d767d68e045f3bbc44ab3afb0e78c4b Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Feb 2015 13:43:53 -0800 Subject: [PATCH 04/11] keep hyperkube noise in one place --- cmd/hyperkube/hyperkube.go | 3 +-- cmd/hyperkube/kubelet.go | 42 ++++++++++++++++++++++++++++++++++++++ cmd/kubelet/app/server.go | 21 ------------------- 3 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 cmd/hyperkube/kubelet.go diff --git a/cmd/hyperkube/hyperkube.go b/cmd/hyperkube/hyperkube.go index 9e925de8877..c0f50fe8289 100644 --- a/cmd/hyperkube/hyperkube.go +++ b/cmd/hyperkube/hyperkube.go @@ -21,7 +21,6 @@ package main import ( "os" - kubelet "github.com/GoogleCloudPlatform/kubernetes/cmd/kubelet/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/controllermanager" "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" apiserver "github.com/GoogleCloudPlatform/kubernetes/pkg/master/server" @@ -38,7 +37,7 @@ func main() { hk.AddServer(apiserver.NewHyperkubeServer()) hk.AddServer(controllermanager.NewHyperkubeServer()) hk.AddServer(sched.NewHyperkubeServer()) - hk.AddServer(kubelet.NewHyperkubeServer()) + hk.AddServer(NewKubelet()) hk.AddServer(proxy.NewHyperkubeServer()) hk.RunToExit(os.Args) diff --git a/cmd/hyperkube/kubelet.go b/cmd/hyperkube/kubelet.go new file mode 100644 index 00000000000..13c2c062a71 --- /dev/null +++ b/cmd/hyperkube/kubelet.go @@ -0,0 +1,42 @@ +/* +Copyright 2015 Google Inc. All rights reserved. + +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. +*/ + +package main + +import ( + kubelet "github.com/GoogleCloudPlatform/kubernetes/cmd/kubelet/app" + "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" +) + +// NewKubelet creates a new hyperkube Server object that includes the +// description and flags. +func NewKubelet() *hyperkube.Server { + s := kubelet.NewKubeletServer() + hks := hyperkube.Server{ + SimpleUsage: "kubelet", + Long: `The kubelet binary is responsible for maintaining a set of containers on a + particular node. It syncs data from a variety of sources including a + Kubernetes API server, an etcd cluster, HTTP endpoint or local file. It then + queries Docker to see what is currently running. It synchronizes the + configuration data, with the running set of containers by starting or stopping + Docker containers.`, + Run: func(_ *hyperkube.Server, args []string) error { + return s.Run(args) + }, + } + s.AddFlags(hks.Flags()) + return &hks +} diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index d61c424125c..341164e722b 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -28,7 +28,6 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth" "github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider" _ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz" - "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/config" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools" @@ -99,26 +98,6 @@ func NewKubeletServer() *KubeletServer { } } -// NewHyperkubeServer creates a new hyperkube Server object that includes the -// description and flags. -func NewHyperkubeServer() *hyperkube.Server { - s := NewKubeletServer() - hks := hyperkube.Server{ - SimpleUsage: "kubelet", - Long: `The kubelet binary is responsible for maintaining a set of containers on a -particular node. It syncs data from a variety of sources including a -Kubernetes API server, an etcd cluster, HTTP endpoint or local file. It then -queries Docker to see what is currently running. It synchronizes the -configuration data, with the running set of containers by starting or stopping -Docker containers.`, - Run: func(_ *hyperkube.Server, args []string) error { - return s.Run(args) - }, - } - s.AddFlags(hks.Flags()) - return &hks -} - // AddFlags adds flags for a specific KubeletServer to the specified FlagSet func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&s.Config, "config", s.Config, "Path to the config file or directory of files") From 8c2ff81ae0f8d5d2860533990d0240a33003500b Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Feb 2015 13:55:35 -0800 Subject: [PATCH 05/11] move pkg/proxy/server to cmd/kube-proxy/app --- cmd/hyperkube/hyperkube.go | 2 +- {pkg/proxy/server => cmd/kube-proxy/app}/server.go | 6 +++--- cmd/kube-proxy/proxy.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) rename {pkg/proxy/server => cmd/kube-proxy/app}/server.go (98%) diff --git a/cmd/hyperkube/hyperkube.go b/cmd/hyperkube/hyperkube.go index c0f50fe8289..b0f2c1a3d1c 100644 --- a/cmd/hyperkube/hyperkube.go +++ b/cmd/hyperkube/hyperkube.go @@ -21,10 +21,10 @@ package main import ( "os" + proxy "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-proxy/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/controllermanager" "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" apiserver "github.com/GoogleCloudPlatform/kubernetes/pkg/master/server" - proxy "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/server" sched "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/server" ) diff --git a/pkg/proxy/server/server.go b/cmd/kube-proxy/app/server.go similarity index 98% rename from pkg/proxy/server/server.go rename to cmd/kube-proxy/app/server.go index 55c11f69f5e..0ad82534af4 100644 --- a/pkg/proxy/server/server.go +++ b/cmd/kube-proxy/app/server.go @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package server does all of the work necessary to configure and run a -// Kubernetes proxy process. -package server +// Package app does all of the work necessary to configure and run a +// Kubernetes app process. +package app import ( "net" diff --git a/cmd/kube-proxy/proxy.go b/cmd/kube-proxy/proxy.go index 5b1d1d2e626..12d3b49303d 100644 --- a/cmd/kube-proxy/proxy.go +++ b/cmd/kube-proxy/proxy.go @@ -21,7 +21,7 @@ import ( "os" "runtime" - "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/server" + "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-proxy/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" @@ -30,7 +30,7 @@ import ( func main() { runtime.GOMAXPROCS(runtime.NumCPU()) - s := server.NewProxyServer() + s := app.NewProxyServer() s.AddFlags(pflag.CommandLine) util.InitFlags() From 0a7b89cc00b2713a38613d5187fb4e6bb3d157bf Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Feb 2015 14:01:54 -0800 Subject: [PATCH 06/11] keep hyperkube noise in one place --- cmd/hyperkube/hyperkube.go | 3 +-- cmd/hyperkube/kube-proxy.go | 41 ++++++++++++++++++++++++++++++++++++ cmd/kube-proxy/app/server.go | 20 ------------------ 3 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 cmd/hyperkube/kube-proxy.go diff --git a/cmd/hyperkube/hyperkube.go b/cmd/hyperkube/hyperkube.go index b0f2c1a3d1c..8c0d4f46b44 100644 --- a/cmd/hyperkube/hyperkube.go +++ b/cmd/hyperkube/hyperkube.go @@ -21,7 +21,6 @@ package main import ( "os" - proxy "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-proxy/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/controllermanager" "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" apiserver "github.com/GoogleCloudPlatform/kubernetes/pkg/master/server" @@ -38,7 +37,7 @@ func main() { hk.AddServer(controllermanager.NewHyperkubeServer()) hk.AddServer(sched.NewHyperkubeServer()) hk.AddServer(NewKubelet()) - hk.AddServer(proxy.NewHyperkubeServer()) + hk.AddServer(NewKubeProxy()) hk.RunToExit(os.Args) } diff --git a/cmd/hyperkube/kube-proxy.go b/cmd/hyperkube/kube-proxy.go new file mode 100644 index 00000000000..088f25368b8 --- /dev/null +++ b/cmd/hyperkube/kube-proxy.go @@ -0,0 +1,41 @@ +/* +Copyright 2015 Google Inc. All rights reserved. + +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. +*/ + +package main + +import ( + kubeproxy "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-proxy/app" + "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" +) + +// NewKubeProxy creates a new hyperkube Server object that includes the +// description and flags. +func NewKubeProxy() *hyperkube.Server { + s := kubeproxy.NewProxyServer() + + hks := hyperkube.Server{ + SimpleUsage: "proxy", + Long: `The Kubernetes proxy server is responsible for taking traffic directed at + services and forwarding it to the appropriate pods. It generally runs on + nodes next to the Kubelet and proxies traffic from local pods to remote pods. + It is also used when handling incoming external traffic.`, + Run: func(_ *hyperkube.Server, args []string) error { + return s.Run(args) + }, + } + s.AddFlags(hks.Flags()) + return &hks +} diff --git a/cmd/kube-proxy/app/server.go b/cmd/kube-proxy/app/server.go index 0ad82534af4..65cb21487a3 100644 --- a/cmd/kube-proxy/app/server.go +++ b/cmd/kube-proxy/app/server.go @@ -27,7 +27,6 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" _ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz" - "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy" "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/config" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" @@ -58,25 +57,6 @@ func NewProxyServer() *ProxyServer { } } -// NewHyperkubeServer creates a new hyperkube Server object that includes the -// description and flags. -func NewHyperkubeServer() *hyperkube.Server { - s := NewProxyServer() - - hks := hyperkube.Server{ - SimpleUsage: "proxy", - Long: `The Kubernetes proxy server is responsible for taking traffic directed at -services and forwarding it to the appropriate pods. It generally runs on -nodes next to the Kubelet and proxies traffic from local pods to remote pods. -It is also used when handling incoming external traffic.`, - Run: func(_ *hyperkube.Server, args []string) error { - return s.Run(args) - }, - } - s.AddFlags(hks.Flags()) - return &hks -} - // AddFlags adds flags for a specific ProxyServer to the specified FlagSet func (s *ProxyServer) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&s.EtcdConfigFile, "etcd_config", s.EtcdConfigFile, "The config file for the etcd client. Mutually exclusive with -etcd_servers") From 899d30f16a1a06d8bf9eaa417ff9dc86dd752dfc Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Feb 2015 14:13:22 -0800 Subject: [PATCH 07/11] move pkg/master/server to cmd/kube-apiserver/app --- cmd/hyperkube/hyperkube.go | 2 +- cmd/kube-apiserver/apiserver.go | 4 ++-- {pkg/master/server => cmd/kube-apiserver/app}/plugins.go | 2 +- {pkg/master/server => cmd/kube-apiserver/app}/server.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename {pkg/master/server => cmd/kube-apiserver/app}/plugins.go (99%) rename {pkg/master/server => cmd/kube-apiserver/app}/server.go (99%) diff --git a/cmd/hyperkube/hyperkube.go b/cmd/hyperkube/hyperkube.go index 8c0d4f46b44..6d786e0a7bc 100644 --- a/cmd/hyperkube/hyperkube.go +++ b/cmd/hyperkube/hyperkube.go @@ -21,9 +21,9 @@ package main import ( "os" + apiserver "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-apiserver/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/controllermanager" "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" - apiserver "github.com/GoogleCloudPlatform/kubernetes/pkg/master/server" sched "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/server" ) diff --git a/cmd/kube-apiserver/apiserver.go b/cmd/kube-apiserver/apiserver.go index ff0be4a7cae..27154cc6063 100644 --- a/cmd/kube-apiserver/apiserver.go +++ b/cmd/kube-apiserver/apiserver.go @@ -23,7 +23,7 @@ import ( "os" "runtime" - "github.com/GoogleCloudPlatform/kubernetes/pkg/master/server" + "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-apiserver/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" @@ -32,7 +32,7 @@ import ( func main() { runtime.GOMAXPROCS(runtime.NumCPU()) - s := server.NewAPIServer() + s := app.NewAPIServer() s.AddFlags(pflag.CommandLine) util.InitFlags() diff --git a/pkg/master/server/plugins.go b/cmd/kube-apiserver/app/plugins.go similarity index 99% rename from pkg/master/server/plugins.go rename to cmd/kube-apiserver/app/plugins.go index 70671b8c69a..c2dbe05f908 100644 --- a/pkg/master/server/plugins.go +++ b/cmd/kube-apiserver/app/plugins.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package server +package app // This file exists to force the desired plugin implementations to be linked. // This should probably be part of some configuration fed into the build for a diff --git a/pkg/master/server/server.go b/cmd/kube-apiserver/app/server.go similarity index 99% rename from pkg/master/server/server.go rename to cmd/kube-apiserver/app/server.go index a1d4ca3b3b3..377f0477d8d 100644 --- a/pkg/master/server/server.go +++ b/cmd/kube-apiserver/app/server.go @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package server does all of the work necessary to create a Kubernetes +// Package app does all of the work necessary to create a Kubernetes // APIServer by binding together the API, master and APIServer infrastructure. // It can be configured and called directly or via the hyperkube framework. -package server +package app import ( "crypto/tls" From cb09571768bad758b182eae9baaf20879a5d6c3c Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Feb 2015 14:20:00 -0800 Subject: [PATCH 08/11] keep hyperkube noise in one place --- cmd/hyperkube/hyperkube.go | 3 +-- cmd/hyperkube/kube-apiserver.go | 38 ++++++++++++++++++++++++++++++++ cmd/kube-apiserver/app/server.go | 17 -------------- 3 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 cmd/hyperkube/kube-apiserver.go diff --git a/cmd/hyperkube/hyperkube.go b/cmd/hyperkube/hyperkube.go index 6d786e0a7bc..56e3916ac68 100644 --- a/cmd/hyperkube/hyperkube.go +++ b/cmd/hyperkube/hyperkube.go @@ -21,7 +21,6 @@ package main import ( "os" - apiserver "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-apiserver/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/controllermanager" "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" sched "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/server" @@ -33,7 +32,7 @@ func main() { Long: "This is an all-in-one binary that can run any of the various Kubernetes servers.", } - hk.AddServer(apiserver.NewHyperkubeServer()) + hk.AddServer(NewKubeAPIServer()) hk.AddServer(controllermanager.NewHyperkubeServer()) hk.AddServer(sched.NewHyperkubeServer()) hk.AddServer(NewKubelet()) diff --git a/cmd/hyperkube/kube-apiserver.go b/cmd/hyperkube/kube-apiserver.go new file mode 100644 index 00000000000..666db8f8ec4 --- /dev/null +++ b/cmd/hyperkube/kube-apiserver.go @@ -0,0 +1,38 @@ +/* +Copyright 2015 Google Inc. All rights reserved. + +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. +*/ + +package main + +import ( + kubeapiserver "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-apiserver/app" + "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" +) + +// NewKubeAPIServer creates a new hyperkube Server object that includes the +// description and flags. +func NewKubeAPIServer() *hyperkube.Server { + s := kubeapiserver.NewAPIServer() + + hks := hyperkube.Server{ + SimpleUsage: "apiserver", + Long: "The main API entrypoint and interface to the storage system. The API server is also the focal point for all authorization decisions.", + Run: func(_ *hyperkube.Server, args []string) error { + return s.Run(args) + }, + } + s.AddFlags(hks.Flags()) + return &hks +} diff --git a/cmd/kube-apiserver/app/server.go b/cmd/kube-apiserver/app/server.go index 377f0477d8d..7cf3837f35a 100644 --- a/cmd/kube-apiserver/app/server.go +++ b/cmd/kube-apiserver/app/server.go @@ -33,7 +33,6 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider" - "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" "github.com/GoogleCloudPlatform/kubernetes/pkg/master" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" @@ -102,22 +101,6 @@ func NewAPIServer() *APIServer { return &s } -// NewHyperkubeServer creates a new hyperkube Server object that includes the -// description and flags. -func NewHyperkubeServer() *hyperkube.Server { - s := NewAPIServer() - - hks := hyperkube.Server{ - SimpleUsage: "apiserver", - Long: "The main API entrypoint and interface to the storage system. The API server is also the focal point for all authorization decisions.", - Run: func(_ *hyperkube.Server, args []string) error { - return s.Run(args) - }, - } - s.AddFlags(hks.Flags()) - return &hks -} - // AddFlags adds flags for a specific APIServer to the specified FlagSet func (s *APIServer) AddFlags(fs *pflag.FlagSet) { // Note: the weird ""+ in below lines seems to be the only way to get gofmt to From 0b17c0f225dd19300c95e38e0b8110c83514b647 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Feb 2015 20:07:00 -0800 Subject: [PATCH 09/11] move pkg/controllermanager to cmd/kube-controller-manager/app --- cmd/hyperkube/hyperkube.go | 3 +- cmd/hyperkube/kube-controller-manager.go | 38 +++++++++++++++++++ .../app}/controllermanager.go | 21 +--------- .../kube-controller-manager/app}/plugins.go | 2 +- .../controller-manager.go | 4 +- 5 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 cmd/hyperkube/kube-controller-manager.go rename {pkg/controllermanager => cmd/kube-controller-manager/app}/controllermanager.go (91%) rename {pkg/controllermanager => cmd/kube-controller-manager/app}/plugins.go (97%) diff --git a/cmd/hyperkube/hyperkube.go b/cmd/hyperkube/hyperkube.go index 56e3916ac68..36a6fc0879d 100644 --- a/cmd/hyperkube/hyperkube.go +++ b/cmd/hyperkube/hyperkube.go @@ -21,7 +21,6 @@ package main import ( "os" - "github.com/GoogleCloudPlatform/kubernetes/pkg/controllermanager" "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" sched "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/server" ) @@ -33,7 +32,7 @@ func main() { } hk.AddServer(NewKubeAPIServer()) - hk.AddServer(controllermanager.NewHyperkubeServer()) + hk.AddServer(NewKubeControllerManager()) hk.AddServer(sched.NewHyperkubeServer()) hk.AddServer(NewKubelet()) hk.AddServer(NewKubeProxy()) diff --git a/cmd/hyperkube/kube-controller-manager.go b/cmd/hyperkube/kube-controller-manager.go new file mode 100644 index 00000000000..c59928687e9 --- /dev/null +++ b/cmd/hyperkube/kube-controller-manager.go @@ -0,0 +1,38 @@ +/* +Copyright 2015 Google Inc. All rights reserved. + +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. +*/ + +package main + +import ( + controllermgr "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-controller-manager/app" + "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" +) + +// NewKubeControllerManager creates a new hyperkube Server object that includes the +// description and flags. +func NewKubeControllerManager() *hyperkube.Server { + s := controllermgr.NewCMServer() + + hks := hyperkube.Server{ + SimpleUsage: "controller-manager", + Long: "A server that runs a set of active components. This includes replication controllers, service endpoints and nodes.", + Run: func(_ *hyperkube.Server, args []string) error { + return s.Run(args) + }, + } + s.AddFlags(hks.Flags()) + return &hks +} diff --git a/pkg/controllermanager/controllermanager.go b/cmd/kube-controller-manager/app/controllermanager.go similarity index 91% rename from pkg/controllermanager/controllermanager.go rename to cmd/kube-controller-manager/app/controllermanager.go index cc1246e5d95..c9e54ccc5fb 100644 --- a/pkg/controllermanager/controllermanager.go +++ b/cmd/kube-controller-manager/app/controllermanager.go @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package controllermanager implements a server that runs a set of active +// Package app implements a server that runs a set of active // components. This includes replication controllers, service endpoints and // nodes. -package controllermanager +package app import ( "net" @@ -32,7 +32,6 @@ import ( nodeControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller" replicationControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/controller" _ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz" - "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" "github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports" "github.com/GoogleCloudPlatform/kubernetes/pkg/resourcequota" "github.com/GoogleCloudPlatform/kubernetes/pkg/service" @@ -84,22 +83,6 @@ func NewCMServer() *CMServer { return &s } -// NewHyperkubeServer creates a new hyperkube Server object that includes the -// description and flags. -func NewHyperkubeServer() *hyperkube.Server { - s := NewCMServer() - - hks := hyperkube.Server{ - SimpleUsage: "controller-manager", - Long: "A server that runs a set of active components. This includes replication controllers, service endpoints and nodes.", - Run: func(_ *hyperkube.Server, args []string) error { - return s.Run(args) - }, - } - s.AddFlags(hks.Flags()) - return &hks -} - // AddFlags adds flags for a specific CMServer to the specified FlagSet func (s *CMServer) AddFlags(fs *pflag.FlagSet) { fs.IntVar(&s.Port, "port", s.Port, "The port that the controller-manager's http service runs on") diff --git a/pkg/controllermanager/plugins.go b/cmd/kube-controller-manager/app/plugins.go similarity index 97% rename from pkg/controllermanager/plugins.go rename to cmd/kube-controller-manager/app/plugins.go index 391b74c7509..13d311bf365 100644 --- a/pkg/controllermanager/plugins.go +++ b/cmd/kube-controller-manager/app/plugins.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package controllermanager +package app import ( // This file exists to force the desired plugin implementations to be linked. diff --git a/cmd/kube-controller-manager/controller-manager.go b/cmd/kube-controller-manager/controller-manager.go index 007f89c8fd1..d4603ad3360 100644 --- a/cmd/kube-controller-manager/controller-manager.go +++ b/cmd/kube-controller-manager/controller-manager.go @@ -25,7 +25,7 @@ import ( "os" "runtime" - "github.com/GoogleCloudPlatform/kubernetes/pkg/controllermanager" + "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-controller-manager/app" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" @@ -34,7 +34,7 @@ import ( func main() { runtime.GOMAXPROCS(runtime.NumCPU()) - s := controllermanager.NewCMServer() + s := app.NewCMServer() s.AddFlags(pflag.CommandLine) util.InitFlags() From 5f021cfc3e424c73b82064829f650f84d7abbccd Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Feb 2015 20:16:29 -0800 Subject: [PATCH 10/11] move pkg/scheduler/server to cmd/kube-scheduler/app --- cmd/hyperkube/hyperkube.go | 3 +- cmd/hyperkube/kube-scheduler.go | 38 +++++++++++++++++++ .../kube-scheduler/app}/server.go | 21 +--------- plugin/cmd/kube-scheduler/scheduler.go | 4 +- 4 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 cmd/hyperkube/kube-scheduler.go rename plugin/{pkg/scheduler/server => cmd/kube-scheduler/app}/server.go (83%) diff --git a/cmd/hyperkube/hyperkube.go b/cmd/hyperkube/hyperkube.go index 36a6fc0879d..b8ed0ab46fe 100644 --- a/cmd/hyperkube/hyperkube.go +++ b/cmd/hyperkube/hyperkube.go @@ -22,7 +22,6 @@ import ( "os" "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" - sched "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/server" ) func main() { @@ -33,7 +32,7 @@ func main() { hk.AddServer(NewKubeAPIServer()) hk.AddServer(NewKubeControllerManager()) - hk.AddServer(sched.NewHyperkubeServer()) + hk.AddServer(NewScheduler()) hk.AddServer(NewKubelet()) hk.AddServer(NewKubeProxy()) diff --git a/cmd/hyperkube/kube-scheduler.go b/cmd/hyperkube/kube-scheduler.go new file mode 100644 index 00000000000..3bf4f491809 --- /dev/null +++ b/cmd/hyperkube/kube-scheduler.go @@ -0,0 +1,38 @@ +/* +Copyright 2015 Google Inc. All rights reserved. + +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. +*/ + +package main + +import ( + "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" + scheduler "github.com/GoogleCloudPlatform/kubernetes/plugin/cmd/kube-scheduler/app" +) + +// NewScheduler creates a new hyperkube Server object that includes the +// description and flags. +func NewScheduler() *hyperkube.Server { + s := scheduler.NewSchedulerServer() + + hks := hyperkube.Server{ + SimpleUsage: "scheduler", + Long: "Implements a Kubernetes scheduler. This will assign pods to kubelets based on capacity and constraints.", + Run: func(_ *hyperkube.Server, args []string) error { + return s.Run(args) + }, + } + s.AddFlags(hks.Flags()) + return &hks +} diff --git a/plugin/pkg/scheduler/server/server.go b/plugin/cmd/kube-scheduler/app/server.go similarity index 83% rename from plugin/pkg/scheduler/server/server.go rename to plugin/cmd/kube-scheduler/app/server.go index c1a86c88432..f65f7100f3d 100644 --- a/plugin/pkg/scheduler/server/server.go +++ b/plugin/cmd/kube-scheduler/app/server.go @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package server implements a Server object for running the scheduler. -package server +// Package app implements a Server object for running the scheduler. +package app import ( "net" @@ -26,7 +26,6 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client/record" _ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz" - "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" "github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler" @@ -55,22 +54,6 @@ func NewSchedulerServer() *SchedulerServer { return &s } -// NewHyperkubeServer creates a new hyperkube Server object that includes the -// description and flags. -func NewHyperkubeServer() *hyperkube.Server { - s := NewSchedulerServer() - - hks := hyperkube.Server{ - SimpleUsage: "scheduler", - Long: "Implements a Kubernetes scheduler. This will assign pods to kubelets based on capacity and constraints.", - Run: func(_ *hyperkube.Server, args []string) error { - return s.Run(args) - }, - } - s.AddFlags(hks.Flags()) - return &hks -} - // AddFlags adds flags for a specific SchedulerServer to the specified FlagSet func (s *SchedulerServer) AddFlags(fs *pflag.FlagSet) { fs.IntVar(&s.Port, "port", s.Port, "The port that the scheduler's http service runs on") diff --git a/plugin/cmd/kube-scheduler/scheduler.go b/plugin/cmd/kube-scheduler/scheduler.go index 41e90d56940..eb62343a7e6 100644 --- a/plugin/cmd/kube-scheduler/scheduler.go +++ b/plugin/cmd/kube-scheduler/scheduler.go @@ -19,13 +19,13 @@ package main import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" - "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/server" + "github.com/GoogleCloudPlatform/kubernetes/plugin/cmd/kube-scheduler/app" "github.com/spf13/pflag" ) func main() { - s := server.NewSchedulerServer() + s := app.NewSchedulerServer() s.AddFlags(pflag.CommandLine) util.InitFlags() From f2894576c137ab1a1fd898258dc84a16825673a6 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Feb 2015 20:35:02 -0800 Subject: [PATCH 11/11] get rid of pkg/hyperkube --- cmd/hyperkube/hyperkube.go | 185 +++++++++++++++++++-- {pkg => cmd}/hyperkube/hyperkube_test.go | 2 +- cmd/hyperkube/kube-apiserver.go | 7 +- cmd/hyperkube/kube-controller-manager.go | 7 +- cmd/hyperkube/kube-proxy.go | 7 +- cmd/hyperkube/kube-scheduler.go | 7 +- cmd/hyperkube/kubelet.go | 7 +- cmd/hyperkube/main.go | 38 +++++ {pkg => cmd}/hyperkube/server.go | 2 +- pkg/hyperkube/hyperkube.go | 202 ----------------------- 10 files changed, 227 insertions(+), 237 deletions(-) rename {pkg => cmd}/hyperkube/hyperkube_test.go (99%) create mode 100644 cmd/hyperkube/main.go rename {pkg => cmd}/hyperkube/server.go (99%) delete mode 100644 pkg/hyperkube/hyperkube.go diff --git a/cmd/hyperkube/hyperkube.go b/cmd/hyperkube/hyperkube.go index b8ed0ab46fe..d8499e5990b 100644 --- a/cmd/hyperkube/hyperkube.go +++ b/cmd/hyperkube/hyperkube.go @@ -14,27 +14,186 @@ 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 ( + "errors" + "flag" + "fmt" + "io" + "io/ioutil" "os" + "path" - "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" + "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" + + "github.com/spf13/pflag" ) -func main() { - hk := hyperkube.HyperKube{ - Name: "hyperkube", - Long: "This is an all-in-one binary that can run any of the various Kubernetes servers.", +// HyperKube represents a single binary that can morph/manage into multiple +// servers. +type HyperKube struct { + Name string // The executable name, used for help and soft-link invocation + Long string // A long description of the binary. It will be world wrapped before output. + + servers []Server + baseFlags *pflag.FlagSet + out io.Writer + helpFlagVal bool +} + +// AddServer adds a server to the HyperKube object. +func (hk *HyperKube) AddServer(s *Server) { + hk.servers = append(hk.servers, *s) + hk.servers[len(hk.servers)-1].hk = hk +} + +// FindServer will find a specific server named name. +func (hk *HyperKube) FindServer(name string) (*Server, error) { + for _, s := range hk.servers { + if s.Name() == name { + return &s, nil + } + } + return nil, fmt.Errorf("Server not found: %s", name) +} + +// Servers returns a list of all of the registred servers +func (hk *HyperKube) Servers() []Server { + return hk.servers +} + +// Flags returns a flagset for "global" flags. +func (hk *HyperKube) Flags() *pflag.FlagSet { + if hk.baseFlags == nil { + hk.baseFlags = pflag.NewFlagSet(hk.Name, pflag.ContinueOnError) + hk.baseFlags.SetOutput(ioutil.Discard) + hk.baseFlags.BoolVarP(&hk.helpFlagVal, "help", "h", false, "help for "+hk.Name) + + // These will add all of the "global" flags (defined with both the + // flag and pflag packages) to the new flag set we have. + util.AddFlagSetToPFlagSet(flag.CommandLine, hk.baseFlags) + util.AddPFlagSetToPFlagSet(pflag.CommandLine, hk.baseFlags) + + } + return hk.baseFlags +} + +// Out returns the io.Writer that is used for all usage/error information +func (hk *HyperKube) Out() io.Writer { + if hk.out == nil { + hk.out = os.Stderr + } + return hk.out +} + +// SetOut sets the output writer for all usage/error information +func (hk *HyperKube) SetOut(w io.Writer) { + hk.out = w +} + +// Print is a convenience method to Print to the defined output +func (hk *HyperKube) Print(i ...interface{}) { + fmt.Fprint(hk.Out(), i...) +} + +// Println is a convenience method to Println to the defined output +func (hk *HyperKube) Println(i ...interface{}) { + fmt.Fprintln(hk.Out(), i...) +} + +// Printf is a convenience method to Printf to the defined output +func (hk *HyperKube) Printf(format string, i ...interface{}) { + fmt.Fprintf(hk.Out(), format, i...) +} + +// Run the server. This will pick the appropriate server and run it. +func (hk *HyperKube) Run(args []string) error { + // If we are called directly, parse all flags up to the first real + // argument. That should be the server to run. + baseCommand := path.Base(args[0]) + serverName := baseCommand + if serverName == hk.Name { + args = args[1:] + + baseFlags := hk.Flags() + baseFlags.SetInterspersed(false) // Only parse flags up to the next real command + err := baseFlags.Parse(args) + if err != nil || hk.helpFlagVal { + if err != nil { + hk.Println("Error:", err) + } + hk.Usage() + return err + } + + verflag.PrintAndExitIfRequested() + + args = baseFlags.Args() + if len(args) > 0 && len(args[0]) > 0 { + serverName = args[0] + baseCommand = baseCommand + " " + serverName + args = args[1:] + } else { + err = errors.New("No server specified") + hk.Printf("Error: %v\n\n", err) + hk.Usage() + return err + } } - hk.AddServer(NewKubeAPIServer()) - hk.AddServer(NewKubeControllerManager()) - hk.AddServer(NewScheduler()) - hk.AddServer(NewKubelet()) - hk.AddServer(NewKubeProxy()) + s, err := hk.FindServer(serverName) + if err != nil { + hk.Printf("Error: %v\n\n", err) + hk.Usage() + return err + } - hk.RunToExit(os.Args) + util.AddPFlagSetToPFlagSet(hk.Flags(), s.Flags()) + err = s.Flags().Parse(args) + if err != nil || hk.helpFlagVal { + if err != nil { + hk.Printf("Error: %v\n\n", err) + } + s.Usage() + return err + } + + verflag.PrintAndExitIfRequested() + + util.InitLogs() + defer util.FlushLogs() + + err = s.Run(s, s.Flags().Args()) + if err != nil { + hk.Println("Error:", err) + } + + return err +} + +// RunToExit will run the hyperkube and then call os.Exit with an appropriate exit code. +func (hk *HyperKube) RunToExit(args []string) { + err := hk.Run(args) + if err != nil { + os.Exit(1) + } + os.Exit(0) +} + +// Usage will write out a summary for all servers that this binary supports. +func (hk *HyperKube) Usage() { + tt := `{{if .Long}}{{.Long | trim | wrap ""}} +{{end}}Usage + + {{.Name}} [flags] + +Servers +{{range .Servers}} + {{.Name}} +{{.Long | trim | wrap " "}}{{end}} +Call '{{.Name}} --help' for help on a specific server. +` + util.ExecuteTemplate(hk.Out(), tt, hk) } diff --git a/pkg/hyperkube/hyperkube_test.go b/cmd/hyperkube/hyperkube_test.go similarity index 99% rename from pkg/hyperkube/hyperkube_test.go rename to cmd/hyperkube/hyperkube_test.go index c88336c0537..ccd83217c9b 100644 --- a/pkg/hyperkube/hyperkube_test.go +++ b/cmd/hyperkube/hyperkube_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package hyperkube +package main import ( "bytes" diff --git a/cmd/hyperkube/kube-apiserver.go b/cmd/hyperkube/kube-apiserver.go index 666db8f8ec4..0d8ee9ac530 100644 --- a/cmd/hyperkube/kube-apiserver.go +++ b/cmd/hyperkube/kube-apiserver.go @@ -18,18 +18,17 @@ package main import ( kubeapiserver "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-apiserver/app" - "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" ) // NewKubeAPIServer creates a new hyperkube Server object that includes the // description and flags. -func NewKubeAPIServer() *hyperkube.Server { +func NewKubeAPIServer() *Server { s := kubeapiserver.NewAPIServer() - hks := hyperkube.Server{ + hks := Server{ SimpleUsage: "apiserver", Long: "The main API entrypoint and interface to the storage system. The API server is also the focal point for all authorization decisions.", - Run: func(_ *hyperkube.Server, args []string) error { + Run: func(_ *Server, args []string) error { return s.Run(args) }, } diff --git a/cmd/hyperkube/kube-controller-manager.go b/cmd/hyperkube/kube-controller-manager.go index c59928687e9..b501c3d5de2 100644 --- a/cmd/hyperkube/kube-controller-manager.go +++ b/cmd/hyperkube/kube-controller-manager.go @@ -18,18 +18,17 @@ package main import ( controllermgr "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-controller-manager/app" - "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" ) // NewKubeControllerManager creates a new hyperkube Server object that includes the // description and flags. -func NewKubeControllerManager() *hyperkube.Server { +func NewKubeControllerManager() *Server { s := controllermgr.NewCMServer() - hks := hyperkube.Server{ + hks := Server{ SimpleUsage: "controller-manager", Long: "A server that runs a set of active components. This includes replication controllers, service endpoints and nodes.", - Run: func(_ *hyperkube.Server, args []string) error { + Run: func(_ *Server, args []string) error { return s.Run(args) }, } diff --git a/cmd/hyperkube/kube-proxy.go b/cmd/hyperkube/kube-proxy.go index 088f25368b8..4e3daf609d9 100644 --- a/cmd/hyperkube/kube-proxy.go +++ b/cmd/hyperkube/kube-proxy.go @@ -18,21 +18,20 @@ package main import ( kubeproxy "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-proxy/app" - "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" ) // NewKubeProxy creates a new hyperkube Server object that includes the // description and flags. -func NewKubeProxy() *hyperkube.Server { +func NewKubeProxy() *Server { s := kubeproxy.NewProxyServer() - hks := hyperkube.Server{ + hks := Server{ SimpleUsage: "proxy", Long: `The Kubernetes proxy server is responsible for taking traffic directed at services and forwarding it to the appropriate pods. It generally runs on nodes next to the Kubelet and proxies traffic from local pods to remote pods. It is also used when handling incoming external traffic.`, - Run: func(_ *hyperkube.Server, args []string) error { + Run: func(_ *Server, args []string) error { return s.Run(args) }, } diff --git a/cmd/hyperkube/kube-scheduler.go b/cmd/hyperkube/kube-scheduler.go index 3bf4f491809..cff643fc65e 100644 --- a/cmd/hyperkube/kube-scheduler.go +++ b/cmd/hyperkube/kube-scheduler.go @@ -17,19 +17,18 @@ limitations under the License. package main import ( - "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" scheduler "github.com/GoogleCloudPlatform/kubernetes/plugin/cmd/kube-scheduler/app" ) // NewScheduler creates a new hyperkube Server object that includes the // description and flags. -func NewScheduler() *hyperkube.Server { +func NewScheduler() *Server { s := scheduler.NewSchedulerServer() - hks := hyperkube.Server{ + hks := Server{ SimpleUsage: "scheduler", Long: "Implements a Kubernetes scheduler. This will assign pods to kubelets based on capacity and constraints.", - Run: func(_ *hyperkube.Server, args []string) error { + Run: func(_ *Server, args []string) error { return s.Run(args) }, } diff --git a/cmd/hyperkube/kubelet.go b/cmd/hyperkube/kubelet.go index 13c2c062a71..b9c404f1988 100644 --- a/cmd/hyperkube/kubelet.go +++ b/cmd/hyperkube/kubelet.go @@ -18,14 +18,13 @@ package main import ( kubelet "github.com/GoogleCloudPlatform/kubernetes/cmd/kubelet/app" - "github.com/GoogleCloudPlatform/kubernetes/pkg/hyperkube" ) // NewKubelet creates a new hyperkube Server object that includes the // description and flags. -func NewKubelet() *hyperkube.Server { +func NewKubelet() *Server { s := kubelet.NewKubeletServer() - hks := hyperkube.Server{ + hks := Server{ SimpleUsage: "kubelet", Long: `The kubelet binary is responsible for maintaining a set of containers on a particular node. It syncs data from a variety of sources including a @@ -33,7 +32,7 @@ func NewKubelet() *hyperkube.Server { queries Docker to see what is currently running. It synchronizes the configuration data, with the running set of containers by starting or stopping Docker containers.`, - Run: func(_ *hyperkube.Server, args []string) error { + Run: func(_ *Server, args []string) error { return s.Run(args) }, } diff --git a/cmd/hyperkube/main.go b/cmd/hyperkube/main.go new file mode 100644 index 00000000000..36927889896 --- /dev/null +++ b/cmd/hyperkube/main.go @@ -0,0 +1,38 @@ +/* +Copyright 2014 Google Inc. All rights reserved. + +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 ( + "os" +) + +func main() { + hk := HyperKube{ + Name: "hyperkube", + Long: "This is an all-in-one binary that can run any of the various Kubernetes servers.", + } + + hk.AddServer(NewKubeAPIServer()) + hk.AddServer(NewKubeControllerManager()) + hk.AddServer(NewScheduler()) + hk.AddServer(NewKubelet()) + hk.AddServer(NewKubeProxy()) + + hk.RunToExit(os.Args) +} diff --git a/pkg/hyperkube/server.go b/cmd/hyperkube/server.go similarity index 99% rename from pkg/hyperkube/server.go rename to cmd/hyperkube/server.go index 697211b5f19..4c29f1df321 100644 --- a/pkg/hyperkube/server.go +++ b/cmd/hyperkube/server.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package hyperkube +package main import ( "io/ioutil" diff --git a/pkg/hyperkube/hyperkube.go b/pkg/hyperkube/hyperkube.go deleted file mode 100644 index f38aec289e2..00000000000 --- a/pkg/hyperkube/hyperkube.go +++ /dev/null @@ -1,202 +0,0 @@ -/* -Copyright 2014 Google Inc. All rights reserved. - -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. -*/ - -package hyperkube - -import ( - "errors" - "flag" - "fmt" - "io" - "io/ioutil" - "os" - "path" - "runtime" - - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" - "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" - - "github.com/spf13/pflag" -) - -// HyperKube represents a single binary that can morph/manage into multiple -// servers. -type HyperKube struct { - Name string // The executable name, used for help and soft-link invocation - Long string // A long description of the binary. It will be world wrapped before output. - - servers []Server - baseFlags *pflag.FlagSet - out io.Writer - helpFlagVal bool -} - -// AddServer adds a server to the HyperKube object. -func (hk *HyperKube) AddServer(s *Server) { - hk.servers = append(hk.servers, *s) - hk.servers[len(hk.servers)-1].hk = hk -} - -// FindServer will find a specific server named name. -func (hk *HyperKube) FindServer(name string) (*Server, error) { - for _, s := range hk.servers { - if s.Name() == name { - return &s, nil - } - } - return nil, fmt.Errorf("Server not found: %s", name) -} - -// Servers returns a list of all of the registred servers -func (hk *HyperKube) Servers() []Server { - return hk.servers -} - -// Flags returns a flagset for "global" flags. -func (hk *HyperKube) Flags() *pflag.FlagSet { - if hk.baseFlags == nil { - hk.baseFlags = pflag.NewFlagSet(hk.Name, pflag.ContinueOnError) - hk.baseFlags.SetOutput(ioutil.Discard) - hk.baseFlags.BoolVarP(&hk.helpFlagVal, "help", "h", false, "help for "+hk.Name) - - // These will add all of the "global" flags (defined with both the - // flag and pflag packages) to the new flag set we have. - util.AddFlagSetToPFlagSet(flag.CommandLine, hk.baseFlags) - util.AddPFlagSetToPFlagSet(pflag.CommandLine, hk.baseFlags) - - } - return hk.baseFlags -} - -// Out returns the io.Writer that is used for all usage/error information -func (hk *HyperKube) Out() io.Writer { - if hk.out == nil { - hk.out = os.Stderr - } - return hk.out -} - -// SetOut sets the output writer for all usage/error information -func (hk *HyperKube) SetOut(w io.Writer) { - hk.out = w -} - -// Print is a convenience method to Print to the defined output -func (hk *HyperKube) Print(i ...interface{}) { - fmt.Fprint(hk.Out(), i...) -} - -// Println is a convenience method to Println to the defined output -func (hk *HyperKube) Println(i ...interface{}) { - fmt.Fprintln(hk.Out(), i...) -} - -// Printf is a convenience method to Printf to the defined output -func (hk *HyperKube) Printf(format string, i ...interface{}) { - fmt.Fprintf(hk.Out(), format, i...) -} - -// Run the server. This will pick the appropriate server and run it. -func (hk *HyperKube) Run(args []string) error { - // If we are called directly, parse all flags up to the first real - // argument. That should be the server to run. - baseCommand := path.Base(args[0]) - serverName := baseCommand - if serverName == hk.Name { - args = args[1:] - - baseFlags := hk.Flags() - baseFlags.SetInterspersed(false) // Only parse flags up to the next real command - err := baseFlags.Parse(args) - if err != nil || hk.helpFlagVal { - if err != nil { - hk.Println("Error:", err) - } - hk.Usage() - return err - } - - verflag.PrintAndExitIfRequested() - - args = baseFlags.Args() - if len(args) > 0 && len(args[0]) > 0 { - serverName = args[0] - baseCommand = baseCommand + " " + serverName - args = args[1:] - } else { - err = errors.New("No server specified") - hk.Printf("Error: %v\n\n", err) - hk.Usage() - return err - } - } - - s, err := hk.FindServer(serverName) - if err != nil { - hk.Printf("Error: %v\n\n", err) - hk.Usage() - return err - } - - util.AddPFlagSetToPFlagSet(hk.Flags(), s.Flags()) - err = s.Flags().Parse(args) - if err != nil || hk.helpFlagVal { - if err != nil { - hk.Printf("Error: %v\n\n", err) - } - s.Usage() - return err - } - - verflag.PrintAndExitIfRequested() - - util.InitLogs() - defer util.FlushLogs() - - err = s.Run(s, s.Flags().Args()) - if err != nil { - hk.Println("Error:", err) - } - - return err -} - -// RunToExit will run the hyperkube and then call os.Exit with an appropriate exit code. -func (hk *HyperKube) RunToExit(args []string) { - runtime.GOMAXPROCS(runtime.NumCPU()) - err := hk.Run(args) - if err != nil { - fmt.Fprint(os.Stderr, err.Error()) - os.Exit(1) - } - os.Exit(0) -} - -// Usage will write out a summary for all servers that this binary supports. -func (hk *HyperKube) Usage() { - tt := `{{if .Long}}{{.Long | trim | wrap ""}} -{{end}}Usage - - {{.Name}} [flags] - -Servers -{{range .Servers}} - {{.Name}} -{{.Long | trim | wrap " "}}{{end}} -Call '{{.Name}} --help' for help on a specific server. -` - util.ExecuteTemplate(hk.Out(), tt, hk) -}