mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
kube-apiserver/corerest: structure Config
This commit is contained in:
parent
75e3576523
commit
a34e06e74c
@ -414,12 +414,16 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
|
|||||||
APIAudiences: c.GenericConfig.Authentication.APIAudiences,
|
APIAudiences: c.GenericConfig.Authentication.APIAudiences,
|
||||||
Informers: c.ExtraConfig.VersionedInformers,
|
Informers: c.ExtraConfig.VersionedInformers,
|
||||||
},
|
},
|
||||||
ProxyTransport: c.ExtraConfig.ProxyTransport,
|
Proxy: corerest.ProxyConfig{
|
||||||
KubeletClientConfig: c.ExtraConfig.KubeletClientConfig,
|
Transport: c.ExtraConfig.ProxyTransport,
|
||||||
ServiceIPRange: c.ExtraConfig.ServiceIPRange,
|
KubeletClientConfig: c.ExtraConfig.KubeletClientConfig,
|
||||||
ServiceSecondaryIPRange: c.ExtraConfig.SecondaryServiceIPRange,
|
},
|
||||||
ServiceNodePortRange: c.ExtraConfig.ServiceNodePortRange,
|
Services: corerest.ServicesConfig{
|
||||||
ServiceIPRepairInterval: c.ExtraConfig.RepairServicesInterval,
|
ClusterIPRange: c.ExtraConfig.ServiceIPRange,
|
||||||
|
SecondaryClusterIPRange: c.ExtraConfig.SecondaryServiceIPRange,
|
||||||
|
NodePortRange: c.ExtraConfig.ServiceNodePortRange,
|
||||||
|
IPRepairInterval: c.ExtraConfig.RepairServicesInterval,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -159,10 +159,14 @@ func TestLegacyRestStorageStrategies(t *testing.T) {
|
|||||||
LoopbackClientConfig: apiserverCfg.GenericConfig.LoopbackClientConfig,
|
LoopbackClientConfig: apiserverCfg.GenericConfig.LoopbackClientConfig,
|
||||||
Informers: apiserverCfg.ExtraConfig.VersionedInformers,
|
Informers: apiserverCfg.ExtraConfig.VersionedInformers,
|
||||||
},
|
},
|
||||||
ProxyTransport: apiserverCfg.ExtraConfig.ProxyTransport,
|
Proxy: corerest.ProxyConfig{
|
||||||
KubeletClientConfig: apiserverCfg.ExtraConfig.KubeletClientConfig,
|
Transport: apiserverCfg.ExtraConfig.ProxyTransport,
|
||||||
ServiceIPRange: apiserverCfg.ExtraConfig.ServiceIPRange,
|
KubeletClientConfig: apiserverCfg.ExtraConfig.KubeletClientConfig,
|
||||||
ServiceNodePortRange: apiserverCfg.ExtraConfig.ServiceNodePortRange,
|
},
|
||||||
|
Services: corerest.ServicesConfig{
|
||||||
|
ClusterIPRange: apiserverCfg.ExtraConfig.ServiceIPRange,
|
||||||
|
NodePortRange: apiserverCfg.ExtraConfig.ServiceNodePortRange,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error from REST storage: %v", err)
|
t.Fatalf("unexpected error from REST storage: %v", err)
|
||||||
|
@ -93,16 +93,22 @@ type GenericConfig struct {
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
GenericConfig
|
GenericConfig
|
||||||
|
|
||||||
// Used for custom proxy dialing, and proxy TLS options
|
Proxy ProxyConfig
|
||||||
ProxyTransport http.RoundTripper
|
Services ServicesConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProxyConfig struct {
|
||||||
|
Transport http.RoundTripper
|
||||||
KubeletClientConfig kubeletclient.KubeletClientConfig
|
KubeletClientConfig kubeletclient.KubeletClientConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServicesConfig struct {
|
||||||
// Service IP ranges
|
// Service IP ranges
|
||||||
ServiceIPRange net.IPNet
|
ClusterIPRange net.IPNet
|
||||||
ServiceSecondaryIPRange net.IPNet
|
SecondaryClusterIPRange net.IPNet
|
||||||
ServiceNodePortRange utilnet.PortRange
|
NodePortRange utilnet.PortRange
|
||||||
|
|
||||||
ServiceIPRepairInterval time.Duration
|
IPRepairInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type rangeRegistries struct {
|
type rangeRegistries struct {
|
||||||
@ -140,25 +146,25 @@ func New(c Config) (*legacyProvider, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p.startServiceNodePortsRepair = portallocatorcontroller.NewRepair(c.ServiceIPRepairInterval, client.CoreV1(), client.EventsV1(), c.ServiceNodePortRange, rangeRegistries.nodePort).RunUntil
|
p.startServiceNodePortsRepair = portallocatorcontroller.NewRepair(c.Services.IPRepairInterval, client.CoreV1(), client.EventsV1(), c.Services.NodePortRange, rangeRegistries.nodePort).RunUntil
|
||||||
|
|
||||||
// create service cluster ip repair controller
|
// create service cluster ip repair controller
|
||||||
if !utilfeature.DefaultFeatureGate.Enabled(features.MultiCIDRServiceAllocator) {
|
if !utilfeature.DefaultFeatureGate.Enabled(features.MultiCIDRServiceAllocator) {
|
||||||
p.startServiceClusterIPRepair = serviceipallocatorcontroller.NewRepair(
|
p.startServiceClusterIPRepair = serviceipallocatorcontroller.NewRepair(
|
||||||
c.ServiceIPRepairInterval,
|
c.Services.IPRepairInterval,
|
||||||
client.CoreV1(),
|
client.CoreV1(),
|
||||||
client.EventsV1(),
|
client.EventsV1(),
|
||||||
&c.ServiceIPRange,
|
&c.Services.ClusterIPRange,
|
||||||
rangeRegistries.clusterIP,
|
rangeRegistries.clusterIP,
|
||||||
&c.ServiceSecondaryIPRange,
|
&c.Services.SecondaryClusterIPRange,
|
||||||
rangeRegistries.secondaryClusterIP,
|
rangeRegistries.secondaryClusterIP,
|
||||||
).RunUntil
|
).RunUntil
|
||||||
} else {
|
} else {
|
||||||
p.startServiceClusterIPRepair = serviceipallocatorcontroller.NewRepairIPAddress(
|
p.startServiceClusterIPRepair = serviceipallocatorcontroller.NewRepairIPAddress(
|
||||||
c.ServiceIPRepairInterval,
|
c.Services.IPRepairInterval,
|
||||||
client,
|
client,
|
||||||
&c.ServiceIPRange,
|
&c.Services.ClusterIPRange,
|
||||||
&c.ServiceSecondaryIPRange,
|
&c.Services.SecondaryClusterIPRange,
|
||||||
c.Informers.Core().V1().Services(),
|
c.Informers.Core().V1().Services(),
|
||||||
c.Informers.Networking().V1alpha1().IPAddresses(),
|
c.Informers.Networking().V1alpha1().IPAddresses(),
|
||||||
).RunUntil
|
).RunUntil
|
||||||
@ -287,7 +293,7 @@ func (c *legacyProvider) NewRESTStorage(apiResourceConfigSource serverstorage.AP
|
|||||||
return genericapiserver.APIGroupInfo{}, err
|
return genericapiserver.APIGroupInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeStorage, err := nodestore.NewStorage(restOptionsGetter, c.KubeletClientConfig, c.ProxyTransport)
|
nodeStorage, err := nodestore.NewStorage(restOptionsGetter, c.Proxy.KubeletClientConfig, c.Proxy.Transport)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return genericapiserver.APIGroupInfo{}, err
|
return genericapiserver.APIGroupInfo{}, err
|
||||||
}
|
}
|
||||||
@ -295,7 +301,7 @@ func (c *legacyProvider) NewRESTStorage(apiResourceConfigSource serverstorage.AP
|
|||||||
podStorage, err := podstore.NewStorage(
|
podStorage, err := podstore.NewStorage(
|
||||||
restOptionsGetter,
|
restOptionsGetter,
|
||||||
nodeStorage.KubeletConnectionInfo,
|
nodeStorage.KubeletConnectionInfo,
|
||||||
c.ProxyTransport,
|
c.Proxy.Transport,
|
||||||
podDisruptionClient,
|
podDisruptionClient,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -309,7 +315,7 @@ func (c *legacyProvider) NewRESTStorage(apiResourceConfigSource serverstorage.AP
|
|||||||
c.serviceNodePortAllocator,
|
c.serviceNodePortAllocator,
|
||||||
endpointsStorage,
|
endpointsStorage,
|
||||||
podStorage.Pod,
|
podStorage.Pod,
|
||||||
c.ProxyTransport)
|
c.Proxy.Transport)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return genericapiserver.APIGroupInfo{}, err
|
return genericapiserver.APIGroupInfo{}, err
|
||||||
}
|
}
|
||||||
@ -426,7 +432,7 @@ func (c *Config) newServiceIPAllocators() (registries rangeRegistries, primaryCl
|
|||||||
return rangeRegistries{}, nil, nil, nil, err
|
return rangeRegistries{}, nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceClusterIPRange := c.ServiceIPRange
|
serviceClusterIPRange := c.Services.ClusterIPRange
|
||||||
if serviceClusterIPRange.IP == nil {
|
if serviceClusterIPRange.IP == nil {
|
||||||
return rangeRegistries{}, nil, nil, nil, fmt.Errorf("service clusterIPRange is missing")
|
return rangeRegistries{}, nil, nil, nil, fmt.Errorf("service clusterIPRange is missing")
|
||||||
}
|
}
|
||||||
@ -460,10 +466,10 @@ func (c *Config) newServiceIPAllocators() (registries rangeRegistries, primaryCl
|
|||||||
clusterIPAllocators[primaryClusterIPAllocator.IPFamily()] = primaryClusterIPAllocator
|
clusterIPAllocators[primaryClusterIPAllocator.IPFamily()] = primaryClusterIPAllocator
|
||||||
|
|
||||||
var secondaryClusterIPAllocator ipallocator.Interface
|
var secondaryClusterIPAllocator ipallocator.Interface
|
||||||
if c.ServiceSecondaryIPRange.IP != nil {
|
if c.Services.SecondaryClusterIPRange.IP != nil {
|
||||||
if !utilfeature.DefaultFeatureGate.Enabled(features.MultiCIDRServiceAllocator) {
|
if !utilfeature.DefaultFeatureGate.Enabled(features.MultiCIDRServiceAllocator) {
|
||||||
var err error
|
var err error
|
||||||
secondaryClusterIPAllocator, err = ipallocator.New(&c.ServiceSecondaryIPRange, func(max int, rangeSpec string, offset int) (allocator.Interface, error) {
|
secondaryClusterIPAllocator, err = ipallocator.New(&c.Services.SecondaryClusterIPRange, func(max int, rangeSpec string, offset int) (allocator.Interface, error) {
|
||||||
var mem allocator.Snapshottable
|
var mem allocator.Snapshottable
|
||||||
mem = allocator.NewAllocationMapWithOffset(max, rangeSpec, offset)
|
mem = allocator.NewAllocationMapWithOffset(max, rangeSpec, offset)
|
||||||
// TODO etcdallocator package to return a storage interface via the storageFactory
|
// TODO etcdallocator package to return a storage interface via the storageFactory
|
||||||
@ -482,7 +488,7 @@ func (c *Config) newServiceIPAllocators() (registries rangeRegistries, primaryCl
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return rangeRegistries{}, nil, nil, nil, err
|
return rangeRegistries{}, nil, nil, nil, err
|
||||||
}
|
}
|
||||||
secondaryClusterIPAllocator, err = ipallocator.NewIPAllocator(&c.ServiceSecondaryIPRange, networkingv1alphaClient, c.Informers.Networking().V1alpha1().IPAddresses())
|
secondaryClusterIPAllocator, err = ipallocator.NewIPAllocator(&c.Services.SecondaryClusterIPRange, networkingv1alphaClient, c.Informers.Networking().V1alpha1().IPAddresses())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rangeRegistries{}, nil, nil, nil, fmt.Errorf("cannot create cluster secondary IP allocator: %v", err)
|
return rangeRegistries{}, nil, nil, nil, fmt.Errorf("cannot create cluster secondary IP allocator: %v", err)
|
||||||
}
|
}
|
||||||
@ -491,7 +497,7 @@ func (c *Config) newServiceIPAllocators() (registries rangeRegistries, primaryCl
|
|||||||
clusterIPAllocators[secondaryClusterIPAllocator.IPFamily()] = secondaryClusterIPAllocator
|
clusterIPAllocators[secondaryClusterIPAllocator.IPFamily()] = secondaryClusterIPAllocator
|
||||||
}
|
}
|
||||||
|
|
||||||
nodePortAllocator, err = portallocator.New(c.ServiceNodePortRange, func(max int, rangeSpec string, offset int) (allocator.Interface, error) {
|
nodePortAllocator, err = portallocator.New(c.Services.NodePortRange, func(max int, rangeSpec string, offset int) (allocator.Interface, error) {
|
||||||
mem := allocator.NewAllocationMapWithOffset(max, rangeSpec, offset)
|
mem := allocator.NewAllocationMapWithOffset(max, rangeSpec, offset)
|
||||||
// TODO etcdallocator package to return a storage interface via the storageFactory
|
// TODO etcdallocator package to return a storage interface via the storageFactory
|
||||||
etcd, err := serviceallocator.NewEtcd(mem, "/ranges/servicenodeports", serviceStorageConfig.ForResource(api.Resource("servicenodeportallocations")))
|
etcd, err := serviceallocator.NewEtcd(mem, "/ranges/servicenodeports", serviceStorageConfig.ForResource(api.Resource("servicenodeportallocations")))
|
||||||
|
Loading…
Reference in New Issue
Block a user