Switch cronjob controller to batch/v1

This commit is contained in:
Maciej Szulik
2021-02-24 22:12:26 +01:00
parent 7c194bb3e3
commit 78f51f8fa5
8 changed files with 84 additions and 94 deletions

View File

@@ -19,15 +19,14 @@ package cronjob
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"sync"
batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/record"
@@ -36,9 +35,9 @@ import (
// cjControlInterface is an interface that knows how to update CronJob status
// created as an interface to allow testing.
type cjControlInterface interface {
UpdateStatus(cj *batchv1beta1.CronJob) (*batchv1beta1.CronJob, error)
UpdateStatus(cj *batchv1.CronJob) (*batchv1.CronJob, error)
// GetCronJob retrieves a CronJob.
GetCronJob(namespace, name string) (*batchv1beta1.CronJob, error)
GetCronJob(namespace, name string) (*batchv1.CronJob, error)
}
// realCJControl is the default implementation of cjControlInterface.
@@ -46,23 +45,23 @@ type realCJControl struct {
KubeClient clientset.Interface
}
func (c *realCJControl) GetCronJob(namespace, name string) (*batchv1beta1.CronJob, error) {
return c.KubeClient.BatchV1beta1().CronJobs(namespace).Get(context.TODO(), name, metav1.GetOptions{})
func (c *realCJControl) GetCronJob(namespace, name string) (*batchv1.CronJob, error) {
return c.KubeClient.BatchV1().CronJobs(namespace).Get(context.TODO(), name, metav1.GetOptions{})
}
var _ cjControlInterface = &realCJControl{}
func (c *realCJControl) UpdateStatus(cj *batchv1beta1.CronJob) (*batchv1beta1.CronJob, error) {
return c.KubeClient.BatchV1beta1().CronJobs(cj.Namespace).UpdateStatus(context.TODO(), cj, metav1.UpdateOptions{})
func (c *realCJControl) UpdateStatus(cj *batchv1.CronJob) (*batchv1.CronJob, error) {
return c.KubeClient.BatchV1().CronJobs(cj.Namespace).UpdateStatus(context.TODO(), cj, metav1.UpdateOptions{})
}
// fakeCJControl is the default implementation of cjControlInterface.
type fakeCJControl struct {
CronJob *batchv1beta1.CronJob
Updates []batchv1beta1.CronJob
CronJob *batchv1.CronJob
Updates []batchv1.CronJob
}
func (c *fakeCJControl) GetCronJob(namespace, name string) (*batchv1beta1.CronJob, error) {
func (c *fakeCJControl) GetCronJob(namespace, name string) (*batchv1.CronJob, error) {
if name == c.CronJob.Name && namespace == c.CronJob.Namespace {
return c.CronJob, nil
}
@@ -74,7 +73,7 @@ func (c *fakeCJControl) GetCronJob(namespace, name string) (*batchv1beta1.CronJo
var _ cjControlInterface = &fakeCJControl{}
func (c *fakeCJControl) UpdateStatus(cj *batchv1beta1.CronJob) (*batchv1beta1.CronJob, error) {
func (c *fakeCJControl) UpdateStatus(cj *batchv1.CronJob) (*batchv1.CronJob, error) {
c.Updates = append(c.Updates, *cj)
return cj, nil
}
@@ -105,7 +104,7 @@ type realJobControl struct {
var _ jobControlInterface = &realJobControl{}
func copyLabels(template *batchv1beta1.JobTemplateSpec) labels.Set {
func copyLabels(template *batchv1.JobTemplateSpec) labels.Set {
l := make(labels.Set)
for k, v := range template.Labels {
l[k] = v
@@ -113,7 +112,7 @@ func copyLabels(template *batchv1beta1.JobTemplateSpec) labels.Set {
return l
}
func copyAnnotations(template *batchv1beta1.JobTemplateSpec) labels.Set {
func copyAnnotations(template *batchv1.JobTemplateSpec) labels.Set {
a := make(labels.Set)
for k, v := range template.Annotations {
a[k] = v