From f9bab9a60b0baaf192b9e52061b3acdfeddd170b Mon Sep 17 00:00:00 2001 From: Li Bo Date: Mon, 24 Apr 2023 18:28:14 +0800 Subject: [PATCH] add --concurrent-cron-job-syncs flag --- .../app/options/cronjobcontroller.go | 8 ++++++++ .../app/options/options_test.go | 17 ++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cmd/kube-controller-manager/app/options/cronjobcontroller.go b/cmd/kube-controller-manager/app/options/cronjobcontroller.go index 48f03ca67c0..d51eb7c4359 100644 --- a/cmd/kube-controller-manager/app/options/cronjobcontroller.go +++ b/cmd/kube-controller-manager/app/options/cronjobcontroller.go @@ -17,6 +17,8 @@ limitations under the License. package options import ( + "fmt" + "github.com/spf13/pflag" cronjobconfig "k8s.io/kubernetes/pkg/controller/cronjob/config" @@ -32,6 +34,8 @@ func (o *CronJobControllerOptions) AddFlags(fs *pflag.FlagSet) { if o == nil { return } + + fs.Int32Var(&o.ConcurrentCronJobSyncs, "concurrent-cron-job-syncs", o.ConcurrentCronJobSyncs, "The number of cron 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,9 @@ func (o *CronJobControllerOptions) Validate() []error { } errs := []error{} + if o.ConcurrentCronJobSyncs < 1 { + errs = append(errs, fmt.Errorf("concurrent-cron-job-syncs must be greater than 0, but got %d", o.ConcurrentCronJobSyncs)) + } + 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 fac8128542a..16ac3d32244 100644 --- a/cmd/kube-controller-manager/app/options/options_test.go +++ b/cmd/kube-controller-manager/app/options/options_test.go @@ -95,6 +95,7 @@ var args = []string{ "--concurrent-gc-syncs=30", "--concurrent-namespace-syncs=20", "--concurrent-job-syncs=10", + "--concurrent-cron-job-syncs=10", "--concurrent-replicaset-syncs=10", "--concurrent-resource-quota-syncs=10", "--concurrent-service-syncs=2", @@ -325,7 +326,7 @@ func TestAddFlags(t *testing.T) { }, CronJobController: &CronJobControllerOptions{ &cronjobconfig.CronJobControllerConfiguration{ - ConcurrentCronJobSyncs: 5, + ConcurrentCronJobSyncs: 10, }, }, NamespaceController: &NamespaceControllerOptions{ @@ -574,7 +575,7 @@ func TestApplyTo(t *testing.T) { ConcurrentJobSyncs: 10, }, CronJobController: cronjobconfig.CronJobControllerConfiguration{ - ConcurrentCronJobSyncs: 5, + ConcurrentCronJobSyncs: 10, }, NamespaceController: namespaceconfig.NamespaceControllerConfiguration{ NamespaceSyncPeriod: metav1.Duration{Duration: 10 * time.Minute}, @@ -1087,13 +1088,23 @@ func TestValidateControllersOptions(t *testing.T) { }, }).Validate, }, + { + name: "CronJobControllerOptions ConcurrentCronJobSyncs equal 0", + expectErrors: true, + expectedErrorSubString: "concurrent-cron-job-syncs must be greater than 0", + validate: (&CronJobControllerOptions{ + &cronjobconfig.CronJobControllerConfiguration{ + ConcurrentCronJobSyncs: 0, + }, + }).Validate, + }, /* empty errs */ { name: "CronJobControllerOptions", expectErrors: false, validate: (&CronJobControllerOptions{ &cronjobconfig.CronJobControllerConfiguration{ - ConcurrentCronJobSyncs: 5, + ConcurrentCronJobSyncs: 10, }, }).Validate, },