|
|
|
@@ -23,6 +23,7 @@ import (
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
|
openapinamer "k8s.io/apiserver/pkg/endpoints/openapi"
|
|
|
|
|
|
|
|
|
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
|
|
|
|
"k8s.io/apimachinery/pkg/util/sets"
|
|
|
|
@@ -32,12 +33,14 @@ import (
|
|
|
|
|
"k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1"
|
|
|
|
|
"k8s.io/kube-aggregator/pkg/apiserver"
|
|
|
|
|
aggregatorscheme "k8s.io/kube-aggregator/pkg/apiserver/scheme"
|
|
|
|
|
"k8s.io/kube-aggregator/pkg/generated/openapi"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const defaultEtcdPathPrefix = "/registry/kube-aggregator.kubernetes.io/"
|
|
|
|
|
|
|
|
|
|
// AggregatorOptions contains everything necessary to create and run an API Aggregator.
|
|
|
|
|
type AggregatorOptions struct {
|
|
|
|
|
ServerRunOptions *genericoptions.ServerRunOptions
|
|
|
|
|
RecommendedOptions *genericoptions.RecommendedOptions
|
|
|
|
|
APIEnablement *genericoptions.APIEnablementOptions
|
|
|
|
|
|
|
|
|
@@ -77,6 +80,7 @@ func NewCommandStartAggregator(defaults *AggregatorOptions, stopCh <-chan struct
|
|
|
|
|
|
|
|
|
|
// 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.ServerRunOptions.AddUniversalFlags(fs)
|
|
|
|
|
o.RecommendedOptions.AddFlags(fs)
|
|
|
|
|
o.APIEnablement.AddFlags(fs)
|
|
|
|
|
fs.StringVar(&o.ProxyClientCertFile, "proxy-client-cert-file", o.ProxyClientCertFile, "client certificate used identify the proxy to the API server")
|
|
|
|
@@ -86,6 +90,7 @@ func (o *AggregatorOptions) AddFlags(fs *pflag.FlagSet) {
|
|
|
|
|
// 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{
|
|
|
|
|
ServerRunOptions: genericoptions.NewServerRunOptions(),
|
|
|
|
|
RecommendedOptions: genericoptions.NewRecommendedOptions(
|
|
|
|
|
defaultEtcdPathPrefix,
|
|
|
|
|
aggregatorscheme.Codecs.LegacyCodec(v1beta1.SchemeGroupVersion),
|
|
|
|
@@ -102,6 +107,7 @@ func NewDefaultOptions(out, err io.Writer) *AggregatorOptions {
|
|
|
|
|
// Validate validates all the required options.
|
|
|
|
|
func (o AggregatorOptions) Validate(args []string) error {
|
|
|
|
|
errors := []error{}
|
|
|
|
|
errors = append(errors, o.ServerRunOptions.Validate()...)
|
|
|
|
|
errors = append(errors, o.RecommendedOptions.Validate()...)
|
|
|
|
|
errors = append(errors, o.APIEnablement.Validate(aggregatorscheme.Scheme)...)
|
|
|
|
|
return utilerrors.NewAggregate(errors)
|
|
|
|
@@ -121,6 +127,9 @@ func (o AggregatorOptions) RunAggregator(stopCh <-chan struct{}) error {
|
|
|
|
|
|
|
|
|
|
serverConfig := genericapiserver.NewRecommendedConfig(aggregatorscheme.Codecs)
|
|
|
|
|
|
|
|
|
|
if err := o.ServerRunOptions.ApplyTo(&serverConfig.Config); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if err := o.RecommendedOptions.ApplyTo(serverConfig); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@@ -131,6 +140,8 @@ func (o AggregatorOptions) RunAggregator(stopCh <-chan struct{}) error {
|
|
|
|
|
sets.NewString("watch", "proxy"),
|
|
|
|
|
sets.NewString("attach", "exec", "proxy", "log", "portforward"),
|
|
|
|
|
)
|
|
|
|
|
serverConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(openapi.GetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(aggregatorscheme.Scheme))
|
|
|
|
|
serverConfig.OpenAPIConfig.Info.Title = "kube-aggregator"
|
|
|
|
|
|
|
|
|
|
serviceResolver := apiserver.NewClusterIPServiceResolver(serverConfig.SharedInformerFactory.Core().V1().Services().Lister())
|
|
|
|
|
|
|
|
|
@@ -155,5 +166,10 @@ func (o AggregatorOptions) RunAggregator(stopCh <-chan struct{}) error {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return server.GenericAPIServer.PrepareRun().Run(stopCh)
|
|
|
|
|
|
|
|
|
|
prepared, err := server.PrepareRun()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return prepared.Run(stopCh)
|
|
|
|
|
}
|
|
|
|
|