chore: update to batch/v1 instead of the deprecated batch/v1beta1
This commit is contained in:
@@ -3,19 +3,20 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/multiplay/go-slack/chat"
|
|
||||||
"github.com/multiplay/go-slack/webhook"
|
|
||||||
"github.com/robfig/cron"
|
|
||||||
"gopkg.in/alecthomas/kingpin.v2"
|
|
||||||
"io"
|
"io"
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/client-go/kubernetes"
|
|
||||||
"k8s.io/client-go/kubernetes/typed/batch/v1beta1"
|
|
||||||
"k8s.io/client-go/rest"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/multiplay/go-slack/chat"
|
||||||
|
"github.com/multiplay/go-slack/webhook"
|
||||||
|
"github.com/robfig/cron"
|
||||||
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/client-go/kubernetes"
|
||||||
|
batchv1 "k8s.io/client-go/kubernetes/typed/batch/v1"
|
||||||
|
"k8s.io/client-go/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
var checkFunc = doCheck
|
var checkFunc = doCheck
|
||||||
@@ -56,7 +57,7 @@ func doCheck(client Client, slackUrl string, ic chan os.Signal, sleepTime time.D
|
|||||||
_, _ = fmt.Fprintf(out, "Got SIGTERM signal, exiting\n")
|
_, _ = fmt.Fprintf(out, "Got SIGTERM signal, exiting\n")
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
cronJobs, err := client.BatchV1beta1().CronJobs("").List(context.Background(), v1.ListOptions{})
|
cronJobs, err := client.BatchV1().CronJobs("").List(context.Background(), v1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting cronjobs: %w", err)
|
return fmt.Errorf("error getting cronjobs: %w", err)
|
||||||
}
|
}
|
||||||
@@ -92,7 +93,7 @@ func doCheck(client Client, slackUrl string, ic chan os.Signal, sleepTime time.D
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Client interface {
|
type Client interface {
|
||||||
BatchV1beta1() v1beta1.BatchV1beta1Interface
|
BatchV1() batchv1.BatchV1Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClientProvider interface {
|
type ClientProvider interface {
|
||||||
|
|||||||
+57
-52
@@ -14,14 +14,14 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sanity-io/litter"
|
"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"
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"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/discovery"
|
||||||
"k8s.io/client-go/kubernetes"
|
"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"
|
"k8s.io/client-go/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ func Test_doCheck(t *testing.T) {
|
|||||||
client: &brokenClient{
|
client: &brokenClient{
|
||||||
batchApi: &batchApi{
|
batchApi: &batchApi{
|
||||||
cronApi: &cronApi{
|
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")
|
return nil, errors.New("error")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -128,8 +128,8 @@ func Test_doCheck(t *testing.T) {
|
|||||||
client: &brokenClient{
|
client: &brokenClient{
|
||||||
batchApi: &batchApi{
|
batchApi: &batchApi{
|
||||||
cronApi: &cronApi{
|
cronApi: &cronApi{
|
||||||
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
|
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
|
||||||
return &beta1.CronJobList{}, nil
|
return &cronjobv1.CronJobList{}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -144,11 +144,11 @@ func Test_doCheck(t *testing.T) {
|
|||||||
client: &brokenClient{
|
client: &brokenClient{
|
||||||
batchApi: &batchApi{
|
batchApi: &batchApi{
|
||||||
cronApi: &cronApi{
|
cronApi: &cronApi{
|
||||||
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
|
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
|
||||||
return &beta1.CronJobList{
|
return &cronjobv1.CronJobList{
|
||||||
Items: []beta1.CronJob{
|
Items: []cronjobv1.CronJob{
|
||||||
{
|
{
|
||||||
Spec: beta1.CronJobSpec{Suspend: boolP(true)},
|
Spec: cronjobv1.CronJobSpec{Suspend: boolP(true)},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
@@ -166,11 +166,11 @@ func Test_doCheck(t *testing.T) {
|
|||||||
client: &brokenClient{
|
client: &brokenClient{
|
||||||
batchApi: &batchApi{
|
batchApi: &batchApi{
|
||||||
cronApi: &cronApi{
|
cronApi: &cronApi{
|
||||||
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
|
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
|
||||||
return &beta1.CronJobList{
|
return &cronjobv1.CronJobList{
|
||||||
Items: []beta1.CronJob{
|
Items: []cronjobv1.CronJob{
|
||||||
{
|
{
|
||||||
Spec: beta1.CronJobSpec{Schedule: "abc"},
|
Spec: cronjobv1.CronJobSpec{Schedule: "abc"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
@@ -187,16 +187,16 @@ func Test_doCheck(t *testing.T) {
|
|||||||
client: &brokenClient{
|
client: &brokenClient{
|
||||||
batchApi: &batchApi{
|
batchApi: &batchApi{
|
||||||
cronApi: &cronApi{
|
cronApi: &cronApi{
|
||||||
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
|
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
|
||||||
return &beta1.CronJobList{
|
return &cronjobv1.CronJobList{
|
||||||
Items: []beta1.CronJob{
|
Items: []cronjobv1.CronJob{
|
||||||
{
|
{
|
||||||
ObjectMeta: v1.ObjectMeta{CreationTimestamp: v1.Time{Time: time.Now()}},
|
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: "* * * * *"},
|
Spec: cronjobv1.CronJobSpec{Schedule: "* * * * *"},
|
||||||
Status: beta1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now()}},
|
Status: cronjobv1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now()}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
@@ -214,13 +214,13 @@ func Test_doCheck(t *testing.T) {
|
|||||||
client: &brokenClient{
|
client: &brokenClient{
|
||||||
batchApi: &batchApi{
|
batchApi: &batchApi{
|
||||||
cronApi: &cronApi{
|
cronApi: &cronApi{
|
||||||
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
|
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
|
||||||
return &beta1.CronJobList{
|
return &cronjobv1.CronJobList{
|
||||||
Items: []beta1.CronJob{
|
Items: []cronjobv1.CronJob{
|
||||||
{
|
{
|
||||||
ObjectMeta: v1.ObjectMeta{Name: "some-name", Namespace: "some-ns"},
|
ObjectMeta: v1.ObjectMeta{Name: "some-name", Namespace: "some-ns"},
|
||||||
Spec: beta1.CronJobSpec{Schedule: "* * * * *"},
|
Spec: cronjobv1.CronJobSpec{Schedule: "* * * * *"},
|
||||||
Status: beta1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
|
Status: cronjobv1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
@@ -240,13 +240,13 @@ func Test_doCheck(t *testing.T) {
|
|||||||
client: &brokenClient{
|
client: &brokenClient{
|
||||||
batchApi: &batchApi{
|
batchApi: &batchApi{
|
||||||
cronApi: &cronApi{
|
cronApi: &cronApi{
|
||||||
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
|
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
|
||||||
return &beta1.CronJobList{
|
return &cronjobv1.CronJobList{
|
||||||
Items: []beta1.CronJob{
|
Items: []cronjobv1.CronJob{
|
||||||
{
|
{
|
||||||
ObjectMeta: v1.ObjectMeta{Name: "some-name", Namespace: "some-ns"},
|
ObjectMeta: v1.ObjectMeta{Name: "some-name", Namespace: "some-ns"},
|
||||||
Spec: beta1.CronJobSpec{Schedule: "* * * * *"},
|
Spec: cronjobv1.CronJobSpec{Schedule: "* * * * *"},
|
||||||
Status: beta1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
|
Status: cronjobv1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
@@ -266,13 +266,13 @@ func Test_doCheck(t *testing.T) {
|
|||||||
client: &brokenClient{
|
client: &brokenClient{
|
||||||
batchApi: &batchApi{
|
batchApi: &batchApi{
|
||||||
cronApi: &cronApi{
|
cronApi: &cronApi{
|
||||||
listFn: func(_ context.Context, _ v1.ListOptions) (*beta1.CronJobList, error) {
|
listFn: func(_ context.Context, _ v1.ListOptions) (*cronjobv1.CronJobList, error) {
|
||||||
return &beta1.CronJobList{
|
return &cronjobv1.CronJobList{
|
||||||
Items: []beta1.CronJob{
|
Items: []cronjobv1.CronJob{
|
||||||
{
|
{
|
||||||
ObjectMeta: v1.ObjectMeta{Name: "some-name", Namespace: "some-ns"},
|
ObjectMeta: v1.ObjectMeta{Name: "some-name", Namespace: "some-ns"},
|
||||||
Spec: beta1.CronJobSpec{Schedule: "* * * * *"},
|
Spec: cronjobv1.CronJobSpec{Schedule: "* * * * *"},
|
||||||
Status: beta1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
|
Status: cronjobv1.CronJobStatus{LastScheduleTime: &v1.Time{Time: time.Now().Add(-3 * time.Minute)}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
@@ -382,46 +382,51 @@ func (b brokenClientProvider) Provide() (Client, error) {
|
|||||||
var _ ClientProvider = &brokenClientProvider{}
|
var _ ClientProvider = &brokenClientProvider{}
|
||||||
|
|
||||||
type brokenClient struct {
|
type brokenClient struct {
|
||||||
batchApi v1beta1.BatchV1beta1Interface
|
batchApi batchv1.BatchV1Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b brokenClient) BatchV1beta1() v1beta1.BatchV1beta1Interface {
|
func (b brokenClient) BatchV1() batchv1.BatchV1Interface {
|
||||||
return b.batchApi
|
return b.batchApi
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Client = &brokenClient{}
|
var _ Client = &brokenClient{}
|
||||||
|
|
||||||
type batchApi struct {
|
type batchApi struct {
|
||||||
cronApi v1beta1.CronJobInterface
|
cronApi batchv1.CronJobInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b batchApi) RESTClient() rest.Interface {
|
func (b batchApi) RESTClient() rest.Interface {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b batchApi) CronJobs(namespace string) v1beta1.CronJobInterface {
|
func (b batchApi) CronJobs(namespace string) batchv1.CronJobInterface {
|
||||||
return b.cronApi
|
return b.cronApi
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ v1beta1.BatchV1beta1Interface = &batchApi{}
|
func (b batchApi) Jobs(namespace string) batchv1.JobInterface {
|
||||||
|
//TODO implement me
|
||||||
type cronApi struct {
|
panic("implement me")
|
||||||
listFn func(ctx context.Context, opts v1.ListOptions) (*beta1.CronJobList, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
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")
|
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")
|
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")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,7 +438,7 @@ func (c cronApi) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, li
|
|||||||
panic("implement me")
|
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")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,19 +446,19 @@ func (c cronApi) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interfac
|
|||||||
panic("implement me")
|
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")
|
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")
|
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")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ v1beta1.CronJobInterface = &cronApi{}
|
var _ batchv1.CronJobInterface = &cronApi{}
|
||||||
|
|
||||||
func boolP(b bool) *bool {
|
func boolP(b bool) *bool {
|
||||||
return &b
|
return &b
|
||||||
|
|||||||
Reference in New Issue
Block a user