mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #91525 from bjrara/standalone-aggregator
Improve the standalone kube-aggregator
This commit is contained in:
commit
416e0576d6
@ -76,6 +76,7 @@ kube::golang::server_targets() {
|
||||
cmd/kubelet
|
||||
cmd/kubeadm
|
||||
cmd/kube-scheduler
|
||||
vendor/k8s.io/kube-aggregator
|
||||
vendor/k8s.io/apiextensions-apiserver
|
||||
cluster/gce/gci/mounter
|
||||
)
|
||||
|
@ -13,12 +13,14 @@ go_library(
|
||||
deps = [
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/endpoints/openapi:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/server:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/server/filters:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/server/options:go_default_library",
|
||||
"//staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1:go_default_library",
|
||||
"//staging/src/k8s.io/kube-aggregator/pkg/apiserver:go_default_library",
|
||||
"//staging/src/k8s.io/kube-aggregator/pkg/apiserver/scheme:go_default_library",
|
||||
"//staging/src/k8s.io/kube-aggregator/pkg/generated/openapi:go_default_library",
|
||||
"//vendor/github.com/spf13/cobra:go_default_library",
|
||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
||||
],
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -285,7 +285,12 @@ func (c *AvailableConditionController) sync(key string) error {
|
||||
results <- err
|
||||
return
|
||||
}
|
||||
discoveryURL.Path = "/apis/" + apiService.Spec.Group + "/" + apiService.Spec.Version
|
||||
// render legacyAPIService health check path when it is delegated to a service
|
||||
if apiService.Name == "v1." {
|
||||
discoveryURL.Path = "/api/" + apiService.Spec.Version
|
||||
} else {
|
||||
discoveryURL.Path = "/apis/" + apiService.Spec.Group + "/" + apiService.Spec.Version
|
||||
}
|
||||
|
||||
errCh := make(chan error)
|
||||
go func() {
|
||||
|
Loading…
Reference in New Issue
Block a user