Merge pull request #97029 from andrewsykim/routes-controller-allocate-node-cidr-check

cloud-controller-manager: routes controller should not depend on --allocate-node-cidrs
This commit is contained in:
Kubernetes Prow Robot 2020-12-08 22:00:50 -08:00 committed by GitHub
commit 74a7fc46c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 9 deletions

View File

@ -99,15 +99,15 @@ func startServiceController(ctx *config.CompletedConfig, cloud cloudprovider.Int
} }
func startRouteController(ctx *config.CompletedConfig, cloud cloudprovider.Interface, stopCh <-chan struct{}) (http.Handler, bool, error) { func startRouteController(ctx *config.CompletedConfig, cloud cloudprovider.Interface, stopCh <-chan struct{}) (http.Handler, bool, error) {
if !ctx.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs || !ctx.ComponentConfig.KubeCloudShared.ConfigureCloudRoutes { if !ctx.ComponentConfig.KubeCloudShared.ConfigureCloudRoutes {
klog.Infof("Will not configure cloud provider routes for allocate-node-cidrs: %v, configure-cloud-routes: %v.", ctx.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs, ctx.ComponentConfig.KubeCloudShared.ConfigureCloudRoutes) klog.Infof("Will not configure cloud provider routes, --configure-cloud-routes: %v", ctx.ComponentConfig.KubeCloudShared.ConfigureCloudRoutes)
return nil, false, nil return nil, false, nil
} }
// If CIDRs should be allocated for pods and set on the CloudProvider, then start the route controller // If CIDRs should be allocated for pods and set on the CloudProvider, then start the route controller
routes, ok := cloud.Routes() routes, ok := cloud.Routes()
if !ok { if !ok {
klog.Warning("configure-cloud-routes is set, but cloud provider does not support routes. Will not configure cloud provider routes.") klog.Warning("--configure-cloud-routes is set, but cloud provider does not support routes. Will not configure cloud provider routes.")
return nil, false, nil return nil, false, nil
} }

View File

@ -56,6 +56,12 @@ var _ cloudprovider.Clusters = (*Cloud)(nil)
// Cloud is a test-double implementation of Interface, LoadBalancer, Instances, and Routes. It is useful for testing. // Cloud is a test-double implementation of Interface, LoadBalancer, Instances, and Routes. It is useful for testing.
type Cloud struct { type Cloud struct {
DisableInstances bool
DisableRoutes bool
DisableLoadBalancers bool
DisableZones bool
DisableClusters bool
Exists bool Exists bool
Err error Err error
@ -126,7 +132,7 @@ func (f *Cloud) Master(ctx context.Context, name string) (string, error) {
// Clusters returns a clusters interface. Also returns true if the interface is supported, false otherwise. // Clusters returns a clusters interface. Also returns true if the interface is supported, false otherwise.
func (f *Cloud) Clusters() (cloudprovider.Clusters, bool) { func (f *Cloud) Clusters() (cloudprovider.Clusters, bool) {
return f, true return f, !f.DisableClusters
} }
// ProviderName returns the cloud provider ID. // ProviderName returns the cloud provider ID.
@ -145,14 +151,14 @@ func (f *Cloud) HasClusterID() bool {
// LoadBalancer returns a fake implementation of LoadBalancer. // LoadBalancer returns a fake implementation of LoadBalancer.
// Actually it just returns f itself. // Actually it just returns f itself.
func (f *Cloud) LoadBalancer() (cloudprovider.LoadBalancer, bool) { func (f *Cloud) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
return f, true return f, !f.DisableLoadBalancers
} }
// Instances returns a fake implementation of Instances. // Instances returns a fake implementation of Instances.
// //
// Actually it just returns f itself. // Actually it just returns f itself.
func (f *Cloud) Instances() (cloudprovider.Instances, bool) { func (f *Cloud) Instances() (cloudprovider.Instances, bool) {
return f, true return f, !f.DisableInstances
} }
// InstancesV2 returns a fake implementation of InstancesV2. // InstancesV2 returns a fake implementation of InstancesV2.
@ -167,12 +173,12 @@ func (f *Cloud) InstancesV2() (cloudprovider.InstancesV2, bool) {
// Zones returns a zones interface. Also returns true if the interface is supported, false otherwise. // Zones returns a zones interface. Also returns true if the interface is supported, false otherwise.
func (f *Cloud) Zones() (cloudprovider.Zones, bool) { func (f *Cloud) Zones() (cloudprovider.Zones, bool) {
return f, true return f, !f.DisableZones
} }
// Routes returns a routes interface along with whether the interface is supported. // Routes returns a routes interface along with whether the interface is supported.
func (f *Cloud) Routes() (cloudprovider.Routes, bool) { func (f *Cloud) Routes() (cloudprovider.Routes, bool) {
return f, true return f, !f.DisableRoutes
} }
// GetLoadBalancer is a stub implementation of LoadBalancer.GetLoadBalancer. // GetLoadBalancer is a stub implementation of LoadBalancer.GetLoadBalancer.

View File

@ -327,5 +327,7 @@ func intPtr(x int) *int {
} }
func fakeCloudProviderFactory(io.Reader) (cloudprovider.Interface, error) { func fakeCloudProviderFactory(io.Reader) (cloudprovider.Interface, error) {
return &fake.Cloud{}, nil return &fake.Cloud{
DisableRoutes: true, // disable routes for server tests, otherwise --cluster-cidr is required
}, nil
} }