Renamed WorkerCount option in node controller to ConcurrentNodeSyncs

This commit is contained in:
Paweł Banaszewski 2022-10-25 12:07:01 +00:00
parent ceb6a4ebf9
commit 0816394e63
9 changed files with 91 additions and 17 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}
}
}

View File

@ -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
}

View File

@ -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{