From 612a8fafb822a92b5023a8169ac97e073f760036 Mon Sep 17 00:00:00 2001 From: deads2k Date: Thu, 16 Feb 2017 14:44:04 -0500 Subject: [PATCH] add kube-aggregator to hyperkube --- cmd/hyperkube/BUILD | 2 + cmd/hyperkube/kube-aggregator.go | 51 +++++++++++++++++++ cmd/hyperkube/main.go | 1 + .../kube-aggregator/pkg/cmd/server/start.go | 42 +++++++++------ vendor/BUILD | 1 + 5 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 cmd/hyperkube/kube-aggregator.go diff --git a/cmd/hyperkube/BUILD b/cmd/hyperkube/BUILD index 03ca96e849..a73441c336 100644 --- a/cmd/hyperkube/BUILD +++ b/cmd/hyperkube/BUILD @@ -32,6 +32,7 @@ go_library( "federation-apiserver.go", "federation-controller-manager.go", "hyperkube.go", + "kube-aggregator.go", "kube-apiserver.go", "kube-controller-manager.go", "kube-proxy.go", @@ -67,6 +68,7 @@ go_library( "//vendor:k8s.io/apiserver/pkg/server/healthz", "//vendor:k8s.io/apiserver/pkg/util/flag", "//vendor:k8s.io/apiserver/pkg/util/logs", + "//vendor:k8s.io/kube-aggregator/pkg/cmd/server", ], ) diff --git a/cmd/hyperkube/kube-aggregator.go b/cmd/hyperkube/kube-aggregator.go new file mode 100644 index 0000000000..ca948792ee --- /dev/null +++ b/cmd/hyperkube/kube-aggregator.go @@ -0,0 +1,51 @@ +/* +Copyright 2017 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. +*/ + +package main + +import ( + "os" + + "k8s.io/kube-aggregator/pkg/cmd/server" +) + +// NewKubeAggregator creates a new hyperkube Server object that includes the +// description and flags. +func NewKubeAggregator() *Server { + o := server.NewDefaultOptions(os.Stdout, os.Stderr) + + hks := Server{ + name: "aggregator", + AlternativeName: "kube-aggregator", + SimpleUsage: "aggregator", + Long: "Aggregator for Kubernetes-style API servers: dynamic registration, discovery summarization, secure proxy.", + Run: func(_ *Server, args []string) error { + if err := o.Complete(); err != nil { + return err + } + if err := o.Validate(args); err != nil { + return err + } + if err := o.RunAggregator(); err != nil { + return err + } + return nil + }, + } + + o.AddFlags(hks.Flags()) + return &hks +} diff --git a/cmd/hyperkube/main.go b/cmd/hyperkube/main.go index a1f6c14cb7..e1e07b7d16 100644 --- a/cmd/hyperkube/main.go +++ b/cmd/hyperkube/main.go @@ -38,6 +38,7 @@ func main() { hk.AddServer(NewScheduler()) hk.AddServer(NewKubelet()) hk.AddServer(NewKubeProxy()) + hk.AddServer(NewKubeAggregator()) //Federation servers hk.AddServer(NewFederationAPIServer()) diff --git a/staging/src/k8s.io/kube-aggregator/pkg/cmd/server/start.go b/staging/src/k8s.io/kube-aggregator/pkg/cmd/server/start.go index a0a2ded4fc..2afc02be84 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/cmd/server/start.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/cmd/server/start.go @@ -22,6 +22,7 @@ import ( "io/ioutil" "github.com/spf13/cobra" + "github.com/spf13/pflag" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" @@ -32,9 +33,8 @@ import ( "k8s.io/client-go/pkg/api" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" - "k8s.io/kube-aggregator/pkg/apiserver" - "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1alpha1" + "k8s.io/kube-aggregator/pkg/apiserver" ) const defaultEtcdPathPrefix = "/registry/kube-aggregator.kubernetes.io/" @@ -55,15 +55,9 @@ type AggregatorOptions struct { StdErr io.Writer } -// NewCommandStartMaster provides a CLI handler for 'start master' command +// NewCommandStartAggregator provides a CLI handler for 'start master' command func NewCommandStartAggregator(out, err io.Writer) *cobra.Command { - o := &AggregatorOptions{ - RecommendedOptions: genericoptions.NewRecommendedOptions(defaultEtcdPathPrefix, api.Scheme, api.Codecs.LegacyCodec(v1alpha1.SchemeGroupVersion)), - - StdOut: out, - StdErr: err, - } - o.RecommendedOptions.SecureServing.ServingOptions.BindPort = 443 + o := NewDefaultOptions(out, err) cmd := &cobra.Command{ Short: "Launch a API aggregator and proxy server", @@ -82,14 +76,30 @@ func NewCommandStartAggregator(out, err io.Writer) *cobra.Command { }, } - flags := cmd.Flags() - o.RecommendedOptions.AddFlags(flags) - flags.StringVar(&o.ProxyClientCertFile, "proxy-client-cert-file", o.ProxyClientCertFile, "client certificate used identify the proxy to the API server") - flags.StringVar(&o.ProxyClientKeyFile, "proxy-client-key-file", o.ProxyClientKeyFile, "client certificate key used identify the proxy to the API server") - flags.StringVar(&o.CoreAPIKubeconfig, "core-kubeconfig", o.CoreAPIKubeconfig, ""+ + o.AddFlags(cmd.Flags()) + return cmd +} + +// AddFlags is necessary because hyperkube doesn't work using cobra, so we have to have different registration and execution paths +func (o *AggregatorOptions) AddFlags(fs *pflag.FlagSet) { + o.RecommendedOptions.AddFlags(fs) + fs.StringVar(&o.ProxyClientCertFile, "proxy-client-cert-file", o.ProxyClientCertFile, "client certificate used identify the proxy to the API server") + fs.StringVar(&o.ProxyClientKeyFile, "proxy-client-key-file", o.ProxyClientKeyFile, "client certificate key used identify the proxy to the API server") + fs.StringVar(&o.CoreAPIKubeconfig, "core-kubeconfig", o.CoreAPIKubeconfig, ""+ "kubeconfig file pointing at the 'core' kubernetes server with enough rights to get,list,watch "+ " services,endpoints. If not set, the in-cluster config is used") - return cmd +} + +// NewDefaultOptions builds a "normal" set of options. You wouldn't normally expose this, but hyperkube isn't cobra compatible +func NewDefaultOptions(out, err io.Writer) *AggregatorOptions { + o := &AggregatorOptions{ + RecommendedOptions: genericoptions.NewRecommendedOptions(defaultEtcdPathPrefix, api.Scheme, api.Codecs.LegacyCodec(v1alpha1.SchemeGroupVersion)), + + StdOut: out, + StdErr: err, + } + o.RecommendedOptions.SecureServing.ServingOptions.BindPort = 443 + return o } func (o AggregatorOptions) Validate(args []string) error { diff --git a/vendor/BUILD b/vendor/BUILD index 2209d07452..c2d29bc93d 100644 --- a/vendor/BUILD +++ b/vendor/BUILD @@ -16793,6 +16793,7 @@ go_library( tags = ["automanaged"], deps = [ "//vendor:github.com/spf13/cobra", + "//vendor:github.com/spf13/pflag", "//vendor:k8s.io/apimachinery/pkg/util/sets", "//vendor:k8s.io/apimachinery/pkg/util/wait", "//vendor:k8s.io/apiserver/pkg/server",