mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
Turn embedding into composition: master.Config.{Config -> GenericConfig}
This commit is contained in:
@@ -116,7 +116,7 @@ const (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
*genericapiserver.Config
|
||||
GenericConfig *genericapiserver.Config
|
||||
|
||||
StorageFactory genericapiserver.StorageFactory
|
||||
EnableWatchCache bool
|
||||
@@ -231,7 +231,7 @@ func (c *Config) New() (*Master, error) {
|
||||
|
||||
restOptionsFactory: restOptionsFactory{
|
||||
deleteCollectionWorkers: c.DeleteCollectionWorkers,
|
||||
enableGarbageCollection: c.EnableGarbageCollection,
|
||||
enableGarbageCollection: c.GenericConfig.EnableGarbageCollection,
|
||||
storageFactory: c.StorageFactory,
|
||||
},
|
||||
}
|
||||
@@ -247,8 +247,8 @@ func (c *Config) New() (*Master, error) {
|
||||
c.RESTStorageProviders = map[string]genericapiserver.RESTStorageProvider{}
|
||||
}
|
||||
c.RESTStorageProviders[appsapi.GroupName] = appsrest.RESTStorageProvider{}
|
||||
c.RESTStorageProviders[authenticationv1beta1.GroupName] = authenticationrest.RESTStorageProvider{Authenticator: c.Authenticator}
|
||||
c.RESTStorageProviders[authorization.GroupName] = authorizationrest.RESTStorageProvider{Authorizer: c.Authorizer}
|
||||
c.RESTStorageProviders[authenticationv1beta1.GroupName] = authenticationrest.RESTStorageProvider{Authenticator: c.GenericConfig.Authenticator}
|
||||
c.RESTStorageProviders[authorization.GroupName] = authorizationrest.RESTStorageProvider{Authorizer: c.GenericConfig.Authorizer}
|
||||
c.RESTStorageProviders[autoscaling.GroupName] = autoscalingrest.RESTStorageProvider{}
|
||||
c.RESTStorageProviders[batch.GroupName] = batchrest.RESTStorageProvider{}
|
||||
c.RESTStorageProviders[certificates.GroupName] = certificatesrest.RESTStorageProvider{}
|
||||
@@ -257,7 +257,7 @@ func (c *Config) New() (*Master, error) {
|
||||
DisableThirdPartyControllerForTesting: m.disableThirdPartyControllerForTesting,
|
||||
}
|
||||
c.RESTStorageProviders[policy.GroupName] = policyrest.RESTStorageProvider{}
|
||||
c.RESTStorageProviders[rbac.GroupName] = &rbacrest.RESTStorageProvider{AuthorizerRBACSuperUser: c.AuthorizerRBACSuperUser}
|
||||
c.RESTStorageProviders[rbac.GroupName] = &rbacrest.RESTStorageProvider{AuthorizerRBACSuperUser: c.GenericConfig.AuthorizerRBACSuperUser}
|
||||
c.RESTStorageProviders[storage.GroupName] = storagerest.RESTStorageProvider{}
|
||||
m.InstallAPIs(c)
|
||||
|
||||
@@ -273,7 +273,7 @@ func (m *Master) InstallAPIs(c *Config) {
|
||||
apiGroupsInfo := []genericapiserver.APIGroupInfo{}
|
||||
|
||||
// Install v1 unless disabled.
|
||||
if c.APIResourceConfigSource.AnyResourcesForVersionEnabled(apiv1.SchemeGroupVersion) {
|
||||
if c.GenericConfig.APIResourceConfigSource.AnyResourcesForVersionEnabled(apiv1.SchemeGroupVersion) {
|
||||
// Install v1 API.
|
||||
m.initV1ResourcesStorage(c)
|
||||
apiGroupInfo := genericapiserver.APIGroupInfo{
|
||||
@@ -308,7 +308,7 @@ func (m *Master) InstallAPIs(c *Config) {
|
||||
}
|
||||
healthz.InstallHandler(m.Mux, healthzChecks...)
|
||||
|
||||
if c.EnableProfiling {
|
||||
if c.GenericConfig.EnableProfiling {
|
||||
routes.MetricsWithReset{}.Install(m.Mux, m.HandlerContainer)
|
||||
} else {
|
||||
routes.DefaultMetrics{}.Install(m.Mux, m.HandlerContainer)
|
||||
@@ -316,7 +316,7 @@ func (m *Master) InstallAPIs(c *Config) {
|
||||
|
||||
// Install third party resource support if requested
|
||||
// TODO seems like this bit ought to be unconditional and the REST API is controlled by the config
|
||||
if c.APIResourceConfigSource.ResourceEnabled(extensionsapiv1beta1.SchemeGroupVersion.WithResource("thirdpartyresources")) {
|
||||
if c.GenericConfig.APIResourceConfigSource.ResourceEnabled(extensionsapiv1beta1.SchemeGroupVersion.WithResource("thirdpartyresources")) {
|
||||
var err error
|
||||
m.thirdPartyStorageConfig, err = c.StorageFactory.NewConfig(extensions.Resource("thirdpartyresources"))
|
||||
if err != nil {
|
||||
@@ -332,12 +332,12 @@ func (m *Master) InstallAPIs(c *Config) {
|
||||
// stabilize order.
|
||||
// TODO find a better way to configure priority of groups
|
||||
for _, group := range sets.StringKeySet(c.RESTStorageProviders).List() {
|
||||
if !c.APIResourceConfigSource.AnyResourcesForGroupEnabled(group) {
|
||||
if !c.GenericConfig.APIResourceConfigSource.AnyResourcesForGroupEnabled(group) {
|
||||
glog.V(1).Infof("Skipping disabled API group %q.", group)
|
||||
continue
|
||||
}
|
||||
restStorageBuilder := c.RESTStorageProviders[group]
|
||||
apiGroupInfo, enabled := restStorageBuilder.NewRESTStorage(c.APIResourceConfigSource, restOptionsGetter)
|
||||
apiGroupInfo, enabled := restStorageBuilder.NewRESTStorage(c.GenericConfig.APIResourceConfigSource, restOptionsGetter)
|
||||
if !enabled {
|
||||
glog.Warningf("Problem initializing API group %q, skipping.", group)
|
||||
continue
|
||||
|
||||
@@ -83,7 +83,7 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
|
||||
GenericAPIServer: &genericapiserver.GenericAPIServer{},
|
||||
}
|
||||
config := Config{
|
||||
Config: &genericapiserver.Config{},
|
||||
GenericConfig: &genericapiserver.Config{},
|
||||
}
|
||||
|
||||
resourceEncoding := genericapiserver.NewDefaultResourceEncodingConfig()
|
||||
@@ -97,17 +97,17 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
|
||||
storageFactory := genericapiserver.NewDefaultStorageFactory(*storageConfig, testapi.StorageMediaType(), api.Codecs, resourceEncoding, DefaultAPIResourceConfigSource())
|
||||
|
||||
config.StorageFactory = storageFactory
|
||||
config.APIResourceConfigSource = DefaultAPIResourceConfigSource()
|
||||
config.PublicAddress = net.ParseIP("192.168.10.4")
|
||||
config.Serializer = api.Codecs
|
||||
config.GenericConfig.APIResourceConfigSource = DefaultAPIResourceConfigSource()
|
||||
config.GenericConfig.PublicAddress = net.ParseIP("192.168.10.4")
|
||||
config.GenericConfig.Serializer = api.Codecs
|
||||
config.KubeletClient = client.FakeKubeletClient{}
|
||||
config.APIPrefix = "/api"
|
||||
config.APIGroupPrefix = "/apis"
|
||||
config.APIResourceConfigSource = DefaultAPIResourceConfigSource()
|
||||
config.ProxyDialer = func(network, addr string) (net.Conn, error) { return nil, nil }
|
||||
config.ProxyTLSClientConfig = &tls.Config{}
|
||||
config.RequestContextMapper = api.NewRequestContextMapper()
|
||||
config.Config.EnableVersion = true
|
||||
config.GenericConfig.APIPrefix = "/api"
|
||||
config.GenericConfig.APIGroupPrefix = "/apis"
|
||||
config.GenericConfig.APIResourceConfigSource = DefaultAPIResourceConfigSource()
|
||||
config.GenericConfig.ProxyDialer = func(network, addr string) (net.Conn, error) { return nil, nil }
|
||||
config.GenericConfig.ProxyTLSClientConfig = &tls.Config{}
|
||||
config.GenericConfig.RequestContextMapper = api.NewRequestContextMapper()
|
||||
config.GenericConfig.EnableVersion = true
|
||||
|
||||
// TODO: this is kind of hacky. The trouble is that the sync loop
|
||||
// runs in a go-routine and there is no way to validate in the test
|
||||
@@ -150,7 +150,7 @@ func limitedAPIResourceConfigSource() *genericapiserver.ResourceConfig {
|
||||
// newLimitedMaster only enables the core group, the extensions group, the batch group, and the autoscaling group.
|
||||
func newLimitedMaster(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.Assertions) {
|
||||
_, etcdserver, config, assert := setUp(t)
|
||||
config.APIResourceConfigSource = limitedAPIResourceConfigSource()
|
||||
config.GenericConfig.APIResourceConfigSource = limitedAPIResourceConfigSource()
|
||||
master, err := config.Complete().New()
|
||||
if err != nil {
|
||||
t.Fatalf("Error in bringing up the master: %v", err)
|
||||
@@ -168,8 +168,8 @@ func TestNew(t *testing.T) {
|
||||
// Verify many of the variables match their config counterparts
|
||||
assert.Equal(master.enableCoreControllers, config.EnableCoreControllers)
|
||||
assert.Equal(master.tunneler, config.Tunneler)
|
||||
assert.Equal(master.RequestContextMapper(), config.RequestContextMapper)
|
||||
assert.Equal(master.ClusterIP, config.PublicAddress)
|
||||
assert.Equal(master.RequestContextMapper(), config.GenericConfig.RequestContextMapper)
|
||||
assert.Equal(master.ClusterIP, config.GenericConfig.PublicAddress)
|
||||
|
||||
// these values get defaulted
|
||||
_, serviceClusterIPRange, _ := net.ParseCIDR("10.0.0.0/24")
|
||||
@@ -181,10 +181,10 @@ func TestNew(t *testing.T) {
|
||||
// These functions should point to the same memory location
|
||||
masterDialer, _ := utilnet.Dialer(master.ProxyTransport)
|
||||
masterDialerFunc := fmt.Sprintf("%p", masterDialer)
|
||||
configDialerFunc := fmt.Sprintf("%p", config.ProxyDialer)
|
||||
configDialerFunc := fmt.Sprintf("%p", config.GenericConfig.ProxyDialer)
|
||||
assert.Equal(masterDialerFunc, configDialerFunc)
|
||||
|
||||
assert.Equal(master.ProxyTransport.(*http.Transport).TLSClientConfig, config.ProxyTLSClientConfig)
|
||||
assert.Equal(master.ProxyTransport.(*http.Transport).TLSClientConfig, config.GenericConfig.ProxyTLSClientConfig)
|
||||
}
|
||||
|
||||
// TestNamespaceSubresources ensures the namespace subresource parsing in apiserver/handlers.go doesn't drift
|
||||
@@ -1253,10 +1253,10 @@ func TestValidOpenAPISpec(t *testing.T) {
|
||||
_, etcdserver, config, assert := setUp(t)
|
||||
defer etcdserver.Terminate(t)
|
||||
|
||||
config.OpenAPIDefinitions = openapi.OpenAPIDefinitions
|
||||
config.EnableOpenAPISupport = true
|
||||
config.EnableIndex = true
|
||||
config.OpenAPIInfo = spec.Info{
|
||||
config.GenericConfig.OpenAPIDefinitions = openapi.OpenAPIDefinitions
|
||||
config.GenericConfig.EnableOpenAPISupport = true
|
||||
config.GenericConfig.EnableIndex = true
|
||||
config.GenericConfig.OpenAPIInfo = spec.Info{
|
||||
InfoProps: spec.InfoProps{
|
||||
Title: "Kubernetes",
|
||||
Version: "unversioned",
|
||||
|
||||
Reference in New Issue
Block a user