diff --git a/cmd/kube-controller-manager/app/batch.go b/cmd/kube-controller-manager/app/batch.go index 1ceee260b11..ceb11e6388b 100644 --- a/cmd/kube-controller-manager/app/batch.go +++ b/cmd/kube-controller-manager/app/batch.go @@ -46,7 +46,7 @@ func startCronJobController(ctx ControllerContext) (http.Handler, bool, error) { if !ctx.AvailableResources[schema.GroupVersionResource{Group: "batch", Version: "v1beta1", Resource: "cronjobs"}] { return nil, false, nil } - cjc, err := cronjob.NewCronJobController( + cjc, err := cronjob.NewController( ctx.ClientBuilder.ClientOrDie("cronjob-controller"), ) if err != nil { diff --git a/hack/.golint_failures b/hack/.golint_failures index 5814940e1b1..9db545284c6 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -79,7 +79,6 @@ pkg/controller/certificates/approver pkg/controller/certificates/signer pkg/controller/cloud pkg/controller/clusterroleaggregation -pkg/controller/cronjob pkg/controller/daemon pkg/controller/deployment pkg/controller/disruption diff --git a/pkg/controller/cronjob/controller.go b/pkg/controller/cronjob/controller.go index e2cb7d9ae36..6e75744fc6a 100644 --- a/pkg/controller/cronjob/controller.go +++ b/pkg/controller/cronjob/controller.go @@ -58,7 +58,8 @@ import ( // controllerKind contains the schema.GroupVersionKind for this controller type. var controllerKind = batchv1beta1.SchemeGroupVersion.WithKind("CronJob") -type CronJobController struct { +// Controller is a controller for CronJobs. +type Controller struct { kubeClient clientset.Interface jobControl jobControlInterface sjControl sjControlInterface @@ -66,7 +67,8 @@ type CronJobController struct { recorder record.EventRecorder } -func NewCronJobController(kubeClient clientset.Interface) (*CronJobController, error) { +// NewController creates and initializes a new Controller. +func NewController(kubeClient clientset.Interface) (*Controller, error) { eventBroadcaster := record.NewBroadcaster() eventBroadcaster.StartLogging(klog.Infof) eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}) @@ -77,7 +79,7 @@ func NewCronJobController(kubeClient clientset.Interface) (*CronJobController, e } } - jm := &CronJobController{ + jm := &Controller{ kubeClient: kubeClient, jobControl: realJobControl{KubeClient: kubeClient}, sjControl: &realSJControl{KubeClient: kubeClient}, @@ -88,8 +90,8 @@ func NewCronJobController(kubeClient clientset.Interface) (*CronJobController, e return jm, nil } -// Run the main goroutine responsible for watching and syncing jobs. -func (jm *CronJobController) Run(stopCh <-chan struct{}) { +// Run starts the main goroutine responsible for watching and syncing jobs. +func (jm *Controller) Run(stopCh <-chan struct{}) { defer utilruntime.HandleCrash() klog.Infof("Starting CronJob Manager") // Check things every 10 second. @@ -99,7 +101,7 @@ func (jm *CronJobController) Run(stopCh <-chan struct{}) { } // syncAll lists all the CronJobs and Jobs and reconciles them. -func (jm *CronJobController) syncAll() { +func (jm *Controller) syncAll() { // List children (Jobs) before parents (CronJob). // This guarantees that if we see any Job that got orphaned by the GC orphan finalizer, // we must also see that the parent CronJob has non-nil DeletionTimestamp (see #42639). diff --git a/pkg/controller/cronjob/utils.go b/pkg/controller/cronjob/utils.go index 19fb91c4baa..8b777f02b35 100644 --- a/pkg/controller/cronjob/utils.go +++ b/pkg/controller/cronjob/utils.go @@ -142,7 +142,7 @@ func getRecentUnmetScheduleTimes(sj batchv1beta1.CronJob, now time.Time) ([]time // but less than "lots". if len(starts) > 100 { // We can't get the most recent times so just return an empty slice - return []time.Time{}, fmt.Errorf("Too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.") + return []time.Time{}, fmt.Errorf("too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew") } } return starts, nil @@ -183,6 +183,7 @@ func getFinishedStatus(j *batchv1.Job) (bool, batchv1.JobConditionType) { return false, "" } +// IsJobFinished returns whether or not a job has completed successfully or failed. func IsJobFinished(j *batchv1.Job) bool { isFinished, _ := getFinishedStatus(j) return isFinished diff --git a/pkg/controller/cronjob/utils_test.go b/pkg/controller/cronjob/utils_test.go index fb6b569f2e6..f9b041f81b7 100644 --- a/pkg/controller/cronjob/utils_test.go +++ b/pkg/controller/cronjob/utils_test.go @@ -35,7 +35,7 @@ func TestGetJobFromTemplate(t *testing.T) { // and other fields, and add a created-by reference. var one int64 = 1 - var no bool = false + var no bool sj := batchv1beta1.CronJob{ ObjectMeta: metav1.ObjectMeta{ diff --git a/test/integration/cronjob/cronjob_test.go b/test/integration/cronjob/cronjob_test.go index 1a719a6b934..7d496fbf85b 100644 --- a/test/integration/cronjob/cronjob_test.go +++ b/test/integration/cronjob/cronjob_test.go @@ -38,7 +38,7 @@ import ( "k8s.io/kubernetes/test/integration/framework" ) -func setup(t *testing.T) (*httptest.Server, framework.CloseFunc, *cronjob.CronJobController, *job.JobController, informers.SharedInformerFactory, clientset.Interface, rest.Config) { +func setup(t *testing.T) (*httptest.Server, framework.CloseFunc, *cronjob.Controller, *job.JobController, informers.SharedInformerFactory, clientset.Interface, rest.Config) { masterConfig := framework.NewIntegrationTestMasterConfig() _, server, closeFn := framework.RunAMaster(masterConfig) @@ -49,7 +49,7 @@ func setup(t *testing.T) (*httptest.Server, framework.CloseFunc, *cronjob.CronJo } resyncPeriod := 12 * time.Hour informerSet := informers.NewSharedInformerFactory(clientset.NewForConfigOrDie(restclient.AddUserAgent(&config, "cronjob-informers")), resyncPeriod) - cjc, err := cronjob.NewCronJobController(clientSet) + cjc, err := cronjob.NewController(clientSet) if err != nil { t.Fatalf("Error creating CronJob controller: %v", err) }