mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-11 06:02:18 +00:00
add cronjob_controllerv2.go
This commit is contained in:
@@ -22,12 +22,13 @@ package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"net/http"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/kubernetes/pkg/controller/cronjob"
|
||||
"k8s.io/kubernetes/pkg/controller/job"
|
||||
kubefeatures "k8s.io/kubernetes/pkg/features"
|
||||
)
|
||||
|
||||
func startJobController(ctx ControllerContext) (http.Handler, bool, error) {
|
||||
@@ -46,6 +47,17 @@ func startCronJobController(ctx ControllerContext) (http.Handler, bool, error) {
|
||||
if !ctx.AvailableResources[schema.GroupVersionResource{Group: "batch", Version: "v1beta1", Resource: "cronjobs"}] {
|
||||
return nil, false, nil
|
||||
}
|
||||
if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.CronJobControllerV2) {
|
||||
cj2c, err := cronjob.NewControllerV2(ctx.InformerFactory.Batch().V1().Jobs(),
|
||||
ctx.InformerFactory.Batch().V1beta1().CronJobs(),
|
||||
ctx.ClientBuilder.ClientOrDie("cronjob-controller"),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, true, fmt.Errorf("error creating CronJob controller V2: %v", err)
|
||||
}
|
||||
go cj2c.Run(int(ctx.ComponentConfig.CronJobController.ConcurrentCronJobSyncs), ctx.Stop)
|
||||
return nil, true, nil
|
||||
}
|
||||
cjc, err := cronjob.NewController(
|
||||
ctx.ClientBuilder.ClientOrDie("cronjob-controller"),
|
||||
)
|
||||
|
56
cmd/kube-controller-manager/app/options/cronjobcontroller.go
Normal file
56
cmd/kube-controller-manager/app/options/cronjobcontroller.go
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright 2020 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 (
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
cronjobconfig "k8s.io/kubernetes/pkg/controller/cronjob/config"
|
||||
)
|
||||
|
||||
// CronJobControllerOptions holds the CronJobController options.
|
||||
type CronJobControllerOptions struct {
|
||||
*cronjobconfig.CronJobControllerConfiguration
|
||||
}
|
||||
|
||||
// AddFlags adds flags related to JobController for controller manager to the specified FlagSet.
|
||||
func (o *CronJobControllerOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
if o == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyTo fills up JobController config with options.
|
||||
func (o *CronJobControllerOptions) ApplyTo(cfg *cronjobconfig.CronJobControllerConfiguration) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
cfg.ConcurrentCronJobSyncs = o.ConcurrentCronJobSyncs
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate checks validation of CronJobControllerOptions.
|
||||
func (o *CronJobControllerOptions) Validate() []error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
errs := []error{}
|
||||
return errs
|
||||
}
|
@@ -72,6 +72,7 @@ type KubeControllerManagerOptions struct {
|
||||
GarbageCollectorController *GarbageCollectorControllerOptions
|
||||
HPAController *HPAControllerOptions
|
||||
JobController *JobControllerOptions
|
||||
CronJobController *CronJobControllerOptions
|
||||
NamespaceController *NamespaceControllerOptions
|
||||
NodeIPAMController *NodeIPAMControllerOptions
|
||||
NodeLifecycleController *NodeLifecycleControllerOptions
|
||||
@@ -145,6 +146,9 @@ func NewKubeControllerManagerOptions() (*KubeControllerManagerOptions, error) {
|
||||
JobController: &JobControllerOptions{
|
||||
&componentConfig.JobController,
|
||||
},
|
||||
CronJobController: &CronJobControllerOptions{
|
||||
&componentConfig.CronJobController,
|
||||
},
|
||||
NamespaceController: &NamespaceControllerOptions{
|
||||
&componentConfig.NamespaceController,
|
||||
},
|
||||
@@ -245,6 +249,7 @@ func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledBy
|
||||
s.GarbageCollectorController.AddFlags(fss.FlagSet("garbagecollector controller"))
|
||||
s.HPAController.AddFlags(fss.FlagSet("horizontalpodautoscaling controller"))
|
||||
s.JobController.AddFlags(fss.FlagSet("job controller"))
|
||||
s.CronJobController.AddFlags(fss.FlagSet("cronjob controller"))
|
||||
s.NamespaceController.AddFlags(fss.FlagSet("namespace controller"))
|
||||
s.NodeIPAMController.AddFlags(fss.FlagSet("nodeipam controller"))
|
||||
s.NodeLifecycleController.AddFlags(fss.FlagSet("nodelifecycle controller"))
|
||||
@@ -310,6 +315,9 @@ func (s *KubeControllerManagerOptions) ApplyTo(c *kubecontrollerconfig.Config) e
|
||||
if err := s.JobController.ApplyTo(&c.ComponentConfig.JobController); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.CronJobController.ApplyTo(&c.ComponentConfig.CronJobController); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.NamespaceController.ApplyTo(&c.ComponentConfig.NamespaceController); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -384,6 +392,7 @@ func (s *KubeControllerManagerOptions) Validate(allControllers []string, disable
|
||||
errs = append(errs, s.GarbageCollectorController.Validate()...)
|
||||
errs = append(errs, s.HPAController.Validate()...)
|
||||
errs = append(errs, s.JobController.Validate()...)
|
||||
errs = append(errs, s.CronJobController.Validate()...)
|
||||
errs = append(errs, s.NamespaceController.Validate()...)
|
||||
errs = append(errs, s.NodeIPAMController.Validate()...)
|
||||
errs = append(errs, s.NodeLifecycleController.Validate()...)
|
||||
|
@@ -38,6 +38,7 @@ import (
|
||||
kubecontrollerconfig "k8s.io/kubernetes/cmd/kube-controller-manager/app/config"
|
||||
kubectrlmgrconfig "k8s.io/kubernetes/pkg/controller/apis/config"
|
||||
csrsigningconfig "k8s.io/kubernetes/pkg/controller/certificates/signer/config"
|
||||
cronjobconfig "k8s.io/kubernetes/pkg/controller/cronjob/config"
|
||||
daemonconfig "k8s.io/kubernetes/pkg/controller/daemon/config"
|
||||
deploymentconfig "k8s.io/kubernetes/pkg/controller/deployment/config"
|
||||
endpointconfig "k8s.io/kubernetes/pkg/controller/endpoint/config"
|
||||
@@ -314,6 +315,11 @@ func TestAddFlags(t *testing.T) {
|
||||
ConcurrentJobSyncs: 5,
|
||||
},
|
||||
},
|
||||
CronJobController: &CronJobControllerOptions{
|
||||
&cronjobconfig.CronJobControllerConfiguration{
|
||||
ConcurrentCronJobSyncs: 5,
|
||||
},
|
||||
},
|
||||
NamespaceController: &NamespaceControllerOptions{
|
||||
&namespaceconfig.NamespaceControllerConfiguration{
|
||||
NamespaceSyncPeriod: metav1.Duration{Duration: 10 * time.Minute},
|
||||
@@ -566,6 +572,9 @@ func TestApplyTo(t *testing.T) {
|
||||
JobController: jobconfig.JobControllerConfiguration{
|
||||
ConcurrentJobSyncs: 5,
|
||||
},
|
||||
CronJobController: cronjobconfig.CronJobControllerConfiguration{
|
||||
ConcurrentCronJobSyncs: 5,
|
||||
},
|
||||
NamespaceController: namespaceconfig.NamespaceControllerConfiguration{
|
||||
NamespaceSyncPeriod: metav1.Duration{Duration: 10 * time.Minute},
|
||||
ConcurrentNamespaceSyncs: 20,
|
||||
|
Reference in New Issue
Block a user