chore: update to batch/v1 instead of the deprecated batch/v1beta1

This commit is contained in:
2022-09-23 18:38:02 +02:00
parent 54722aafd9
commit 715939d794
2 changed files with 68 additions and 62 deletions
+57 -52
View File
@@ -14,14 +14,14 @@ import (
"time"
"github.com/sanity-io/litter"
beta1 "k8s.io/api/batch/v1beta1"
cronjobv1 "k8s.io/api/batch/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
v1beta12 "k8s.io/client-go/applyconfigurations/batch/v1beta1"
applyv1 "k8s.io/client-go/applyconfigurations/batch/v1"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/typed/batch/v1beta1"
batchv1 "k8s.io/client-go/kubernetes/typed/batch/v1"
"k8s.io/client-go/rest"
)
@@ -113,7 +113,7 @@ func Test_doCheck(t *testing.T) {
client: &brokenClient{
batchApi: &batchApi{
cronApi: &cronApi{
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
return nil, errors.New("error")
},
},
@@ -128,8 +128,8 @@ func Test_doCheck(t *testing.T) {
client: &brokenClient{
batchApi: &batchApi{
cronApi: &cronApi{
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
return &beta1.CronJobList{}, nil
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
return &cronjobv1.CronJobList{}, nil
},
},
},
@@ -144,11 +144,11 @@ func Test_doCheck(t *testing.T) {
client: &brokenClient{
batchApi: &batchApi{
cronApi: &cronApi{
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
return &beta1.CronJobList{
Items: []beta1.CronJob{
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
return &cronjobv1.CronJobList{
Items: []cronjobv1.CronJob{
{
Spec: beta1.CronJobSpec{Suspend: boolP(true)},
Spec: cronjobv1.CronJobSpec{Suspend: boolP(true)},
},
},
}, nil
@@ -166,11 +166,11 @@ func Test_doCheck(t *testing.T) {
client: &brokenClient{
batchApi: &batchApi{
cronApi: &cronApi{
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
return &beta1.CronJobList{
Items: []beta1.CronJob{
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
return &cronjobv1.CronJobList{
Items: []cronjobv1.CronJob{
{
Spec: beta1.CronJobSpec{Schedule: "abc"},
Spec: cronjobv1.CronJobSpec{Schedule: "abc"},
},
},
}, nil
@@ -187,16 +187,16 @@ func Test_doCheck(t *testing.T) {
client: &brokenClient{
batchApi: &batchApi{
cronApi: &cronApi{
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
return &beta1.CronJobList{
Items: []beta1.CronJob{
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
return &cronjobv1.CronJobList{
Items: []cronjobv1.CronJob{
{
ObjectMeta: v1.ObjectMeta{CreationTimestamp: v1.Time{Time: time.Now()}},
Spec: beta1.CronJobSpec{Schedule: "* * * * *", Suspend: boolP(false)},
Spec: cronjobv1.CronJobSpec{Schedule: "* * * * *", Suspend: boolP(false)},
},
{
Spec: beta1.CronJobSpec{Schedule: "* * * * *"},
Status: beta1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now()}},
Spec: cronjobv1.CronJobSpec{Schedule: "* * * * *"},
Status: cronjobv1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now()}},
},
},
}, nil
@@ -214,13 +214,13 @@ func Test_doCheck(t *testing.T) {
client: &brokenClient{
batchApi: &batchApi{
cronApi: &cronApi{
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
return &beta1.CronJobList{
Items: []beta1.CronJob{
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
return &cronjobv1.CronJobList{
Items: []cronjobv1.CronJob{
{
ObjectMeta: v1.ObjectMeta{Name: "some-name", Namespace: "some-ns"},
Spec: beta1.CronJobSpec{Schedule: "* * * * *"},
Status: beta1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
Spec: cronjobv1.CronJobSpec{Schedule: "* * * * *"},
Status: cronjobv1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
},
},
}, nil
@@ -240,13 +240,13 @@ func Test_doCheck(t *testing.T) {
client: &brokenClient{
batchApi: &batchApi{
cronApi: &cronApi{
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
return &beta1.CronJobList{
Items: []beta1.CronJob{
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
return &cronjobv1.CronJobList{
Items: []cronjobv1.CronJob{
{
ObjectMeta: v1.ObjectMeta{Name: "some-name", Namespace: "some-ns"},
Spec: beta1.CronJobSpec{Schedule: "* * * * *"},
Status: beta1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
Spec: cronjobv1.CronJobSpec{Schedule: "* * * * *"},
Status: cronjobv1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
},
},
}, nil
@@ -266,13 +266,13 @@ func Test_doCheck(t *testing.T) {
client: &brokenClient{
batchApi: &batchApi{
cronApi: &cronApi{
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
return &beta1.CronJobList{
Items: []beta1.CronJob{
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
return &cronjobv1.CronJobList{
Items: []cronjobv1.CronJob{
{
ObjectMeta: v1.ObjectMeta{Name: "some-name", Namespace: "some-ns"},
Spec: beta1.CronJobSpec{Schedule: "* * * * *"},
Status: beta1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
Spec: cronjobv1.CronJobSpec{Schedule: "* * * * *"},
Status: cronjobv1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
},
},
}, nil
@@ -382,46 +382,51 @@ func (b brokenClientProvider) Provide() (Client, error) {
var _ ClientProvider = &brokenClientProvider{}
type brokenClient struct {
batchApi v1beta1.BatchV1beta1Interface
batchApi batchv1.BatchV1Interface
}
func (b brokenClient) BatchV1beta1() v1beta1.BatchV1beta1Interface {
func (b brokenClient) BatchV1() batchv1.BatchV1Interface {
return b.batchApi
}
var _ Client = &brokenClient{}
type batchApi struct {
cronApi v1beta1.CronJobInterface
cronApi batchv1.CronJobInterface
}
func (b batchApi) RESTClient() rest.Interface {
panic("implement me")
}
func (b batchApi) CronJobs(namespace string) v1beta1.CronJobInterface {
func (b batchApi) CronJobs(namespace string) batchv1.CronJobInterface {
return b.cronApi
}
var _ v1beta1.BatchV1beta1Interface = &batchApi{}
type cronApi struct {
listFn func(ctx context.Context, opts v1.ListOptions) (*beta1.CronJobList, error)
func (b batchApi) Jobs(namespace string) batchv1.JobInterface {
//TODO implement me
panic("implement me")
}
func (c cronApi) List(ctx context.Context, opts v1.ListOptions) (*beta1.CronJobList, error) {
var _ batchv1.BatchV1Interface = &batchApi{}
type cronApi struct {
listFn func(ctx context.Context, opts v1.ListOptions) (*cronjobv1.CronJobList, error)
}
func (c cronApi) List(ctx context.Context, opts v1.ListOptions) (*cronjobv1.CronJobList, error) {
return c.listFn(ctx, opts)
}
func (c cronApi) Create(ctx context.Context, cronJob *beta1.CronJob, opts v1.CreateOptions) (*beta1.CronJob, error) {
func (c cronApi) Create(ctx context.Context, cronJob *cronjobv1.CronJob, opts v1.CreateOptions) (*cronjobv1.CronJob, error) {
panic("implement me")
}
func (c cronApi) Update(ctx context.Context, cronJob *beta1.CronJob, opts v1.UpdateOptions) (*beta1.CronJob, error) {
func (c cronApi) Update(ctx context.Context, cronJob *cronjobv1.CronJob, opts v1.UpdateOptions) (*cronjobv1.CronJob, error) {
panic("implement me")
}
func (c cronApi) UpdateStatus(ctx context.Context, cronJob *beta1.CronJob, opts v1.UpdateOptions) (*beta1.CronJob, error) {
func (c cronApi) UpdateStatus(ctx context.Context, cronJob *cronjobv1.CronJob, opts v1.UpdateOptions) (*cronjobv1.CronJob, error) {
panic("implement me")
}
@@ -433,7 +438,7 @@ func (c cronApi) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, li
panic("implement me")
}
func (c cronApi) Get(ctx context.Context, name string, opts v1.GetOptions) (*beta1.CronJob, error) {
func (c cronApi) Get(ctx context.Context, name string, opts v1.GetOptions) (*cronjobv1.CronJob, error) {
panic("implement me")
}
@@ -441,19 +446,19 @@ func (c cronApi) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interfac
panic("implement me")
}
func (c cronApi) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *beta1.CronJob, err error) {
func (c cronApi) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *cronjobv1.CronJob, err error) {
panic("implement me")
}
func (c cronApi) Apply(ctx context.Context, cronJob *v1beta12.CronJobApplyConfiguration, opts v1.ApplyOptions) (result *beta1.CronJob, err error) {
func (c cronApi) Apply(ctx context.Context, cronJob *applyv1.CronJobApplyConfiguration, opts v1.ApplyOptions) (result *cronjobv1.CronJob, err error) {
panic("implement me")
}
func (c cronApi) ApplyStatus(ctx context.Context, cronJob *v1beta12.CronJobApplyConfiguration, opts v1.ApplyOptions) (result *beta1.CronJob, err error) {
func (c cronApi) ApplyStatus(ctx context.Context, cronJob *applyv1.CronJobApplyConfiguration, opts v1.ApplyOptions) (result *cronjobv1.CronJob, err error) {
panic("implement me")
}
var _ v1beta1.CronJobInterface = &cronApi{}
var _ batchv1.CronJobInterface = &cronApi{}
func boolP(b bool) *bool {
return &b