diff --git a/staging/src/k8s.io/cloud-provider/app/core.go b/staging/src/k8s.io/cloud-provider/app/core.go index 426cb79349b..d94c29d4113 100644 --- a/staging/src/k8s.io/cloud-provider/app/core.go +++ b/staging/src/k8s.io/cloud-provider/app/core.go @@ -48,7 +48,7 @@ func startCloudNodeController(ctx context.Context, initContext ControllerInitCon completedConfig.ClientBuilder.ClientOrDie(initContext.ClientName), cloud, completedConfig.ComponentConfig.NodeStatusUpdateFrequency.Duration, - completedConfig.ComponentConfig.NodeController.WorkerCount, + completedConfig.ComponentConfig.NodeController.ConcurrentNodeSyncs, ) if err != nil { klog.Warningf("failed to start cloud node controller: %s", err) diff --git a/staging/src/k8s.io/cloud-provider/controllers/node/config/types.go b/staging/src/k8s.io/cloud-provider/controllers/node/config/types.go index 403775e62c1..af7c7880351 100644 --- a/staging/src/k8s.io/cloud-provider/controllers/node/config/types.go +++ b/staging/src/k8s.io/cloud-provider/controllers/node/config/types.go @@ -18,6 +18,7 @@ package config // NodeControllerConfiguration contains elements describing NodeController. type NodeControllerConfiguration struct { - // WorkerCount is the number of workers that are synchronizing nodes. - WorkerCount int32 + // ConcurrentNodeSyncs is the number of workers + // concurrently synchronizing nodes + ConcurrentNodeSyncs int32 } diff --git a/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/defaults.go b/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/defaults.go index ae2d491d0d8..5f5ff95ff12 100644 --- a/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/defaults.go +++ b/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/defaults.go @@ -17,7 +17,7 @@ limitations under the License. package v1alpha1 func RecommendedDefaultNodeControllerConfiguration(obj *NodeControllerConfiguration) { - if obj.WorkerCount <= 0 { - obj.WorkerCount = 1 + if obj.ConcurrentNodeSyncs == 0 { + obj.ConcurrentNodeSyncs = 1 } } diff --git a/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/types.go b/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/types.go index f32ce69e1c8..ca85a557cbf 100644 --- a/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/types.go +++ b/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/types.go @@ -18,6 +18,7 @@ package v1alpha1 // NodeControllerConfiguration contains elements describing NodeController. type NodeControllerConfiguration struct { - // WorkerCount is the number of workers that are synchronizing nodes. - WorkerCount int32 + // ConcurrentNodeSyncs is the number of workers + // concurrently synchronizing nodes + ConcurrentNodeSyncs int32 } diff --git a/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/zz_generated.conversion.go b/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/zz_generated.conversion.go index 6b79d712b73..cf3852db294 100644 --- a/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/zz_generated.conversion.go +++ b/staging/src/k8s.io/cloud-provider/controllers/node/config/v1alpha1/zz_generated.conversion.go @@ -48,11 +48,11 @@ func RegisterConversions(s *runtime.Scheme) error { } func autoConvert_v1alpha1_NodeControllerConfiguration_To_config_NodeControllerConfiguration(in *NodeControllerConfiguration, out *config.NodeControllerConfiguration, s conversion.Scope) error { - out.WorkerCount = in.WorkerCount + out.ConcurrentNodeSyncs = in.ConcurrentNodeSyncs return nil } func autoConvert_config_NodeControllerConfiguration_To_v1alpha1_NodeControllerConfiguration(in *config.NodeControllerConfiguration, out *NodeControllerConfiguration, s conversion.Scope) error { - out.WorkerCount = in.WorkerCount + out.ConcurrentNodeSyncs = in.ConcurrentNodeSyncs return nil } diff --git a/staging/src/k8s.io/cloud-provider/options/nodecontroller.go b/staging/src/k8s.io/cloud-provider/options/nodecontroller.go index 641aabfea71..953e549e615 100644 --- a/staging/src/k8s.io/cloud-provider/options/nodecontroller.go +++ b/staging/src/k8s.io/cloud-provider/options/nodecontroller.go @@ -17,6 +17,8 @@ limitations under the License. package options import ( + "fmt" + "github.com/spf13/pflag" nodeconfig "k8s.io/cloud-provider/controllers/node/config" @@ -33,7 +35,7 @@ func (o *NodeControllerOptions) AddFlags(fs *pflag.FlagSet) { return } - fs.Int32Var(&o.WorkerCount, "node-controller-worker-count", o.WorkerCount, "Number of workers synchronizing node status.") + fs.Int32Var(&o.ConcurrentNodeSyncs, "concurrent-node-syncs", o.ConcurrentNodeSyncs, "Number of workers concurrently synchronizing nodes.") } // ApplyTo fills up ServiceController config with options. @@ -42,7 +44,7 @@ func (o *NodeControllerOptions) ApplyTo(cfg *nodeconfig.NodeControllerConfigurat return nil } - cfg.WorkerCount = o.WorkerCount + cfg.ConcurrentNodeSyncs = o.ConcurrentNodeSyncs return nil } @@ -52,6 +54,9 @@ func (o *NodeControllerOptions) Validate() []error { if o == nil { return nil } - - return []error{} + var errors []error + if o.ConcurrentNodeSyncs < 0 { + errors = append(errors, fmt.Errorf("concurrent-node-syncs must be a positive number")) + } + return errors } diff --git a/staging/src/k8s.io/cloud-provider/options/nodecontroller_test.go b/staging/src/k8s.io/cloud-provider/options/nodecontroller_test.go new file mode 100644 index 00000000000..350b10c48b4 --- /dev/null +++ b/staging/src/k8s.io/cloud-provider/options/nodecontroller_test.go @@ -0,0 +1,67 @@ +/* +Copyright 2022 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 options + +import ( + "fmt" + "testing" + + nodeconfig "k8s.io/cloud-provider/controllers/node/config" +) + +func errSliceEq(a []error, b []error) bool { + if len(a) != len(b) { + return false + } + for i := 0; i < len(a); i++ { + if a[i].Error() != b[i].Error() { + return false + } + } + return true +} + +func TestNodeControllerConcurrentNodeSyncsValidation(t *testing.T) { + testCases := []struct { + desc string + input *NodeControllerOptions + expect []error + }{ + { + desc: "empty options", + }, + { + desc: "negative value", + input: &NodeControllerOptions{NodeControllerConfiguration: &nodeconfig.NodeControllerConfiguration{ConcurrentNodeSyncs: -5}}, + expect: []error{fmt.Errorf("node-controller-concurrent-node-syncs must be a positive number")}, + }, + { + desc: "non negative value", + input: &NodeControllerOptions{NodeControllerConfiguration: &nodeconfig.NodeControllerConfiguration{ConcurrentNodeSyncs: 0}}, + }, + { + desc: "positive value", + input: &NodeControllerOptions{NodeControllerConfiguration: &nodeconfig.NodeControllerConfiguration{ConcurrentNodeSyncs: 5}}, + }, + } + for _, tc := range testCases { + got := tc.input.Validate() + if !errSliceEq(tc.expect, got) { + t.Errorf("%v: expected: %v got: %v", tc.desc, tc.expect, got) + } + } +} diff --git a/staging/src/k8s.io/cloud-provider/options/options.go b/staging/src/k8s.io/cloud-provider/options/options.go index 09ccbd4a493..fdf8e65c704 100644 --- a/staging/src/k8s.io/cloud-provider/options/options.go +++ b/staging/src/k8s.io/cloud-provider/options/options.go @@ -204,7 +204,7 @@ func (o *CloudControllerManagerOptions) ApplyTo(c *config.Config, userAgent stri // sync back to component config // TODO: find more elegant way than syncing back the values. c.ComponentConfig.NodeStatusUpdateFrequency = o.NodeStatusUpdateFrequency - c.ComponentConfig.NodeController.WorkerCount = o.NodeController.WorkerCount + c.ComponentConfig.NodeController.ConcurrentNodeSyncs = o.NodeController.ConcurrentNodeSyncs return nil } diff --git a/staging/src/k8s.io/cloud-provider/options/options_test.go b/staging/src/k8s.io/cloud-provider/options/options_test.go index 021e3c6a591..b7d10ca5d2c 100644 --- a/staging/src/k8s.io/cloud-provider/options/options_test.go +++ b/staging/src/k8s.io/cloud-provider/options/options_test.go @@ -87,7 +87,7 @@ func TestDefaultFlags(t *testing.T) { }, NodeController: &NodeControllerOptions{ NodeControllerConfiguration: &nodeconfig.NodeControllerConfiguration{ - WorkerCount: 1, + ConcurrentNodeSyncs: 1, }, }, ServiceController: &ServiceControllerOptions{ @@ -175,7 +175,7 @@ func TestAddFlags(t *testing.T) { "--route-reconciliation-period=30s", "--secure-port=10001", "--use-service-account-credentials=false", - "--node-controller-worker-count=5", + "--concurrent-node-syncs=5", } err = fs.Parse(args) if err != nil { @@ -231,7 +231,7 @@ func TestAddFlags(t *testing.T) { }, NodeController: &NodeControllerOptions{ NodeControllerConfiguration: &nodeconfig.NodeControllerConfiguration{ - WorkerCount: 5, + ConcurrentNodeSyncs: 5, }, }, ServiceController: &ServiceControllerOptions{