95 lines
2.9 KiB
Go
95 lines
2.9 KiB
Go
/*
|
|
Copyright 2023 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 app
|
|
|
|
import (
|
|
apiextensionsapiserver "k8s.io/apiextensions-apiserver/pkg/apiserver"
|
|
"k8s.io/apiserver/pkg/util/webhook"
|
|
aggregatorapiserver "k8s.io/kube-aggregator/pkg/apiserver"
|
|
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
|
|
"k8s.io/kubernetes/pkg/controlplane"
|
|
"k8s.io/kubernetes/pkg/controlplane/apiserver"
|
|
)
|
|
|
|
type Config struct {
|
|
Options options.CompletedOptions
|
|
|
|
Aggregator *aggregatorapiserver.Config
|
|
ControlPlane *controlplane.Config
|
|
ApiExtensions *apiextensionsapiserver.Config
|
|
|
|
ExtraConfig
|
|
}
|
|
|
|
type ExtraConfig struct {
|
|
}
|
|
|
|
type completedConfig struct {
|
|
Options options.CompletedOptions
|
|
|
|
Aggregator aggregatorapiserver.CompletedConfig
|
|
ControlPlane controlplane.CompletedConfig
|
|
ApiExtensions apiextensionsapiserver.CompletedConfig
|
|
|
|
ExtraConfig
|
|
}
|
|
|
|
type CompletedConfig struct {
|
|
// Embed a private pointer that cannot be instantiated outside of this package.
|
|
*completedConfig
|
|
}
|
|
|
|
func (c *Config) Complete() (CompletedConfig, error) {
|
|
return CompletedConfig{&completedConfig{
|
|
Options: c.Options,
|
|
|
|
Aggregator: c.Aggregator.Complete(),
|
|
ControlPlane: c.ControlPlane.Complete(),
|
|
ApiExtensions: c.ApiExtensions.Complete(),
|
|
|
|
ExtraConfig: c.ExtraConfig,
|
|
}}, nil
|
|
}
|
|
|
|
// NewConfig creates all the resources for running kube-apiserver, but runs none of them.
|
|
func NewConfig(opts options.CompletedOptions) (*Config, error) {
|
|
c := &Config{
|
|
Options: opts,
|
|
}
|
|
|
|
controlPlane, serviceResolver, pluginInitializer, err := CreateKubeAPIServerConfig(opts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
c.ControlPlane = controlPlane
|
|
|
|
apiExtensions, err := apiserver.CreateAPIExtensionsConfig(*controlPlane.GenericConfig, controlPlane.ExtraConfig.VersionedInformers, pluginInitializer, opts.CompletedOptions, opts.MasterCount,
|
|
serviceResolver, webhook.NewDefaultAuthenticationInfoResolverWrapper(controlPlane.ExtraConfig.ProxyTransport, controlPlane.GenericConfig.EgressSelector, controlPlane.GenericConfig.LoopbackClientConfig, controlPlane.GenericConfig.TracerProvider))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
c.ApiExtensions = apiExtensions
|
|
|
|
aggregator, err := createAggregatorConfig(*controlPlane.GenericConfig, opts.CompletedOptions, controlPlane.ExtraConfig.VersionedInformers, serviceResolver, controlPlane.ExtraConfig.ProxyTransport, controlPlane.ExtraConfig.PeerProxy, pluginInitializer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
c.Aggregator = aggregator
|
|
|
|
return c, nil
|
|
}
|