From c69689659a6868912c109903b21e9fe2b3e25a15 Mon Sep 17 00:00:00 2001 From: Antoni Zawodny Date: Thu, 6 Apr 2023 12:23:12 +0200 Subject: [PATCH] Add `--concurrent-job-syncs` flag to kube-controller-manager --- .../app/options/jobcontroller.go | 7 +++++++ .../app/options/options_test.go | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/kube-controller-manager/app/options/jobcontroller.go b/cmd/kube-controller-manager/app/options/jobcontroller.go index 2e7d66790b0..cf631a25d63 100644 --- a/cmd/kube-controller-manager/app/options/jobcontroller.go +++ b/cmd/kube-controller-manager/app/options/jobcontroller.go @@ -17,6 +17,8 @@ limitations under the License. package options import ( + "fmt" + "github.com/spf13/pflag" jobconfig "k8s.io/kubernetes/pkg/controller/job/config" @@ -32,6 +34,8 @@ func (o *JobControllerOptions) AddFlags(fs *pflag.FlagSet) { if o == nil { return } + + fs.Int32Var(&o.ConcurrentJobSyncs, "concurrent-job-syncs", o.ConcurrentJobSyncs, "The number of job objects that are allowed to sync concurrently. Larger number = more responsive jobs, but more CPU (and network) load") } // ApplyTo fills up JobController config with options. @@ -52,5 +56,8 @@ func (o *JobControllerOptions) Validate() []error { } errs := []error{} + if o.ConcurrentJobSyncs < 1 { + errs = append(errs, fmt.Errorf("concurrent-job-syncs must be greater than 0, but got %d", o.ConcurrentJobSyncs)) + } return errs } diff --git a/cmd/kube-controller-manager/app/options/options_test.go b/cmd/kube-controller-manager/app/options/options_test.go index d7ee588116a..d281ce1a471 100644 --- a/cmd/kube-controller-manager/app/options/options_test.go +++ b/cmd/kube-controller-manager/app/options/options_test.go @@ -94,6 +94,7 @@ var args = []string{ "--concurrent-service-endpoint-syncs=10", "--concurrent-gc-syncs=30", "--concurrent-namespace-syncs=20", + "--concurrent-job-syncs=10", "--concurrent-replicaset-syncs=10", "--concurrent-resource-quota-syncs=10", "--concurrent-service-syncs=2", @@ -319,7 +320,7 @@ func TestAddFlags(t *testing.T) { }, JobController: &JobControllerOptions{ &jobconfig.JobControllerConfiguration{ - ConcurrentJobSyncs: 5, + ConcurrentJobSyncs: 10, }, }, CronJobController: &CronJobControllerOptions{ @@ -570,7 +571,7 @@ func TestApplyTo(t *testing.T) { HorizontalPodAutoscalerTolerance: 0.1, }, JobController: jobconfig.JobControllerConfiguration{ - ConcurrentJobSyncs: 5, + ConcurrentJobSyncs: 10, }, CronJobController: cronjobconfig.CronJobControllerConfiguration{ ConcurrentCronJobSyncs: 5, @@ -1076,6 +1077,16 @@ func TestValidateControllersOptions(t *testing.T) { }, }).Validate, }, + { + name: "JobControllerOptions ConcurrentJobSyncs equal 0", + expectErrors: true, + expectedErrorSubString: "concurrent-job-syncs must be greater than 0", + validate: (&JobControllerOptions{ + &jobconfig.JobControllerConfiguration{ + ConcurrentJobSyncs: 0, + }, + }).Validate, + }, /* empty errs */ { name: "CronJobControllerOptions", @@ -1139,7 +1150,7 @@ func TestValidateControllersOptions(t *testing.T) { expectErrors: false, validate: (&JobControllerOptions{ &jobconfig.JobControllerConfiguration{ - ConcurrentJobSyncs: 5, + ConcurrentJobSyncs: 10, }, }).Validate, },