Skip to content

Commit 41eea36

Browse files
authored
Merge pull request #1491 from bison/deprecated-versions
Use v1 PodDisruptionBudget and CronJob resources
2 parents 081cc3c + d01ad03 commit 41eea36

File tree

7 files changed

+51
-52
lines changed

7 files changed

+51
-52
lines changed

internal/store/builder.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ import (
2929
appsv1 "k8s.io/api/apps/v1"
3030
autoscaling "k8s.io/api/autoscaling/v2beta2"
3131
batchv1 "k8s.io/api/batch/v1"
32-
batchv1beta1 "k8s.io/api/batch/v1beta1"
3332
certv1 "k8s.io/api/certificates/v1"
3433
coordinationv1 "k8s.io/api/coordination/v1"
3534
v1 "k8s.io/api/core/v1"
3635
networkingv1 "k8s.io/api/networking/v1"
37-
policy "k8s.io/api/policy/v1beta1"
36+
policyv1 "k8s.io/api/policy/v1"
3837
storagev1 "k8s.io/api/storage/v1"
3938
vpaautoscaling "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta2"
4039
vpaclientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
@@ -310,7 +309,7 @@ func (b *Builder) buildConfigMapStores() []cache.Store {
310309
}
311310

312311
func (b *Builder) buildCronJobStores() []cache.Store {
313-
return b.buildStoresFunc(cronJobMetricFamilies(b.allowAnnotationsList["cronjobs"], b.allowLabelsList["cronjobs"]), &batchv1beta1.CronJob{}, createCronJobListWatch, b.useAPIServerCache)
312+
return b.buildStoresFunc(cronJobMetricFamilies(b.allowAnnotationsList["cronjobs"], b.allowLabelsList["cronjobs"]), &batchv1.CronJob{}, createCronJobListWatch, b.useAPIServerCache)
314313
}
315314

316315
func (b *Builder) buildDaemonSetStores() []cache.Store {
@@ -366,7 +365,7 @@ func (b *Builder) buildPersistentVolumeStores() []cache.Store {
366365
}
367366

368367
func (b *Builder) buildPodDisruptionBudgetStores() []cache.Store {
369-
return b.buildStoresFunc(podDisruptionBudgetMetricFamilies(b.allowAnnotationsList["poddisruptionbudgets"], b.allowLabelsList["poddisruptionbudgets"]), &policy.PodDisruptionBudget{}, createPodDisruptionBudgetListWatch, b.useAPIServerCache)
368+
return b.buildStoresFunc(podDisruptionBudgetMetricFamilies(b.allowAnnotationsList["poddisruptionbudgets"], b.allowLabelsList["poddisruptionbudgets"]), &policyv1.PodDisruptionBudget{}, createPodDisruptionBudgetListWatch, b.useAPIServerCache)
370369
}
371370

372371
func (b *Builder) buildReplicaSetStores() []cache.Store {

internal/store/cronjob.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/pkg/errors"
2424
"github.com/robfig/cron/v3"
25-
batchv1beta1 "k8s.io/api/batch/v1beta1"
25+
batchv1 "k8s.io/api/batch/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/runtime"
2828
"k8s.io/apimachinery/pkg/watch"
@@ -48,7 +48,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
4848
descCronJobAnnotationsHelp,
4949
metric.Gauge,
5050
"",
51-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
51+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
5252
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", j.Annotations, allowAnnotationsList)
5353
return &metric.Family{
5454
Metrics: []*metric.Metric{
@@ -66,7 +66,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
6666
descCronJobLabelsHelp,
6767
metric.Gauge,
6868
"",
69-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
69+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
7070
labelKeys, labelValues := createPrometheusLabelKeysValues("label", j.Labels, allowLabelsList)
7171
return &metric.Family{
7272
Metrics: []*metric.Metric{
@@ -84,7 +84,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
8484
"Info about cronjob.",
8585
metric.Gauge,
8686
"",
87-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
87+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
8888
return &metric.Family{
8989
Metrics: []*metric.Metric{
9090
{
@@ -101,7 +101,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
101101
"Unix creation timestamp",
102102
metric.Gauge,
103103
"",
104-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
104+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
105105
ms := []*metric.Metric{}
106106
if !j.CreationTimestamp.IsZero() {
107107
ms = append(ms, &metric.Metric{
@@ -121,7 +121,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
121121
"Active holds pointers to currently running jobs.",
122122
metric.Gauge,
123123
"",
124-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
124+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
125125
return &metric.Family{
126126
Metrics: []*metric.Metric{
127127
{
@@ -138,7 +138,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
138138
"LastScheduleTime keeps information of when was the last time the job was successfully scheduled.",
139139
metric.Gauge,
140140
"",
141-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
141+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
142142
ms := []*metric.Metric{}
143143

144144
if j.Status.LastScheduleTime != nil {
@@ -159,7 +159,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
159159
"Suspend flag tells the controller to suspend subsequent executions.",
160160
metric.Gauge,
161161
"",
162-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
162+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
163163
ms := []*metric.Metric{}
164164

165165
if j.Spec.Suspend != nil {
@@ -180,7 +180,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
180180
"Deadline in seconds for starting the job if it misses scheduled time for any reason.",
181181
metric.Gauge,
182182
"",
183-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
183+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
184184
ms := []*metric.Metric{}
185185

186186
if j.Spec.StartingDeadlineSeconds != nil {
@@ -202,7 +202,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
202202
"Next time the cronjob should be scheduled. The time after lastScheduleTime, or after the cron job's creation time if it's never been scheduled. Use this to determine if the job is delayed.",
203203
metric.Gauge,
204204
"",
205-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
205+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
206206
ms := []*metric.Metric{}
207207

208208
// If the cron job is suspended, don't track the next scheduled time
@@ -227,7 +227,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
227227
"Resource version representing a specific version of the cronjob.",
228228
metric.Gauge,
229229
"",
230-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
230+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
231231
return &metric.Family{
232232
Metrics: resourceVersionMetric(j.ObjectMeta.ResourceVersion),
233233
}
@@ -238,7 +238,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
238238
"Successful job history limit tells the controller how many completed jobs should be preserved.",
239239
metric.Gauge,
240240
"",
241-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
241+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
242242
ms := []*metric.Metric{}
243243

244244
if j.Spec.SuccessfulJobsHistoryLimit != nil {
@@ -259,7 +259,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
259259
"Failed job history limit tells the controller how many failed jobs should be preserved.",
260260
metric.Gauge,
261261
"",
262-
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
262+
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
263263
ms := []*metric.Metric{}
264264

265265
if j.Spec.FailedJobsHistoryLimit != nil {
@@ -278,9 +278,9 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
278278
}
279279
}
280280

281-
func wrapCronJobFunc(f func(*batchv1beta1.CronJob) *metric.Family) func(interface{}) *metric.Family {
281+
func wrapCronJobFunc(f func(*batchv1.CronJob) *metric.Family) func(interface{}) *metric.Family {
282282
return func(obj interface{}) *metric.Family {
283-
cronJob := obj.(*batchv1beta1.CronJob)
283+
cronJob := obj.(*batchv1.CronJob)
284284

285285
metricFamily := f(cronJob)
286286

@@ -297,11 +297,11 @@ func createCronJobListWatch(kubeClient clientset.Interface, ns string, fieldSele
297297
return &cache.ListWatch{
298298
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
299299
opts.FieldSelector = fieldSelector
300-
return kubeClient.BatchV1beta1().CronJobs(ns).List(context.TODO(), opts)
300+
return kubeClient.BatchV1().CronJobs(ns).List(context.TODO(), opts)
301301
},
302302
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
303303
opts.FieldSelector = fieldSelector
304-
return kubeClient.BatchV1beta1().CronJobs(ns).Watch(context.TODO(), opts)
304+
return kubeClient.BatchV1().CronJobs(ns).Watch(context.TODO(), opts)
305305
},
306306
}
307307
}

internal/store/cronjob_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"testing"
2323
"time"
2424

25-
batchv1beta1 "k8s.io/api/batch/v1beta1"
25+
batchv1 "k8s.io/api/batch/v1"
2626
v1 "k8s.io/api/core/v1"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828

@@ -106,7 +106,7 @@ func TestCronJobStore(t *testing.T) {
106106
AllowAnnotationsList: []string{
107107
"app.k8s.io/owner",
108108
},
109-
Obj: &batchv1beta1.CronJob{
109+
Obj: &batchv1.CronJob{
110110
ObjectMeta: metav1.ObjectMeta{
111111
Name: "ActiveRunningCronJob1",
112112
Namespace: "ns1",
@@ -120,11 +120,11 @@ func TestCronJobStore(t *testing.T) {
120120
"app.k8s.io/owner": "@foo",
121121
},
122122
},
123-
Status: batchv1beta1.CronJobStatus{
123+
Status: batchv1.CronJobStatus{
124124
Active: []v1.ObjectReference{{Name: "FakeJob1"}, {Name: "FakeJob2"}},
125125
LastScheduleTime: &metav1.Time{Time: ActiveRunningCronJob1LastScheduleTime},
126126
},
127-
Spec: batchv1beta1.CronJobSpec{
127+
Spec: batchv1.CronJobSpec{
128128
StartingDeadlineSeconds: &StartingDeadlineSeconds300,
129129
ConcurrencyPolicy: "Forbid",
130130
Suspend: &SuspendFalse,
@@ -186,7 +186,7 @@ func TestCronJobStore(t *testing.T) {
186186
},
187187
},
188188
{
189-
Obj: &batchv1beta1.CronJob{
189+
Obj: &batchv1.CronJob{
190190
ObjectMeta: metav1.ObjectMeta{
191191
Name: "SuspendedCronJob1",
192192
Namespace: "ns1",
@@ -196,11 +196,11 @@ func TestCronJobStore(t *testing.T) {
196196
"app": "example-suspended-1",
197197
},
198198
},
199-
Status: batchv1beta1.CronJobStatus{
199+
Status: batchv1.CronJobStatus{
200200
Active: []v1.ObjectReference{},
201201
LastScheduleTime: &metav1.Time{Time: SuspendedCronJob1LastScheduleTime},
202202
},
203-
Spec: batchv1beta1.CronJobSpec{
203+
Spec: batchv1.CronJobSpec{
204204
StartingDeadlineSeconds: &StartingDeadlineSeconds300,
205205
ConcurrencyPolicy: "Forbid",
206206
Suspend: &SuspendTrue,
@@ -243,7 +243,7 @@ func TestCronJobStore(t *testing.T) {
243243
MetricNames: []string{"kube_cronjob_spec_starting_deadline_seconds", "kube_cronjob_status_active", "kube_cronjob_metadata_resource_version", "kube_cronjob_spec_suspend", "kube_cronjob_info", "kube_cronjob_created", "kube_cronjob_labels", "kube_cronjob_status_last_schedule_time", "kube_cronjob_spec_successful_job_history_limit", "kube_cronjob_spec_failed_job_history_limit"},
244244
},
245245
{
246-
Obj: &batchv1beta1.CronJob{
246+
Obj: &batchv1.CronJob{
247247
ObjectMeta: metav1.ObjectMeta{
248248
Name: "ActiveCronJob1NoLastScheduled",
249249
CreationTimestamp: metav1.Time{Time: ActiveCronJob1NoLastScheduledCreationTimestamp},
@@ -254,11 +254,11 @@ func TestCronJobStore(t *testing.T) {
254254
"app": "example-active-no-last-scheduled-1",
255255
},
256256
},
257-
Status: batchv1beta1.CronJobStatus{
257+
Status: batchv1.CronJobStatus{
258258
Active: []v1.ObjectReference{},
259259
LastScheduleTime: nil,
260260
},
261-
Spec: batchv1beta1.CronJobSpec{
261+
Spec: batchv1.CronJobSpec{
262262
StartingDeadlineSeconds: &StartingDeadlineSeconds300,
263263
ConcurrencyPolicy: "Forbid",
264264
Suspend: &SuspendFalse,

internal/store/poddisruptionbudget.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package store
1919
import (
2020
"context"
2121

22-
"k8s.io/api/policy/v1beta1"
22+
policyv1 "k8s.io/api/policy/v1"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
"k8s.io/apimachinery/pkg/runtime"
2525
"k8s.io/apimachinery/pkg/watch"
@@ -45,7 +45,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
4545
descPodDisruptionBudgetAnnotationsHelp,
4646
metric.Gauge,
4747
"",
48-
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
48+
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
4949
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", p.Annotations, allowAnnotationsList)
5050
return &metric.Family{
5151
Metrics: []*metric.Metric{
@@ -63,7 +63,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
6363
descPodDisruptionBudgetLabelsHelp,
6464
metric.Gauge,
6565
"",
66-
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
66+
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
6767
labelKeys, labelValues := createPrometheusLabelKeysValues("label", p.Labels, allowLabelsList)
6868
return &metric.Family{
6969
Metrics: []*metric.Metric{
@@ -81,7 +81,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
8181
"Unix creation timestamp",
8282
metric.Gauge,
8383
"",
84-
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
84+
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
8585
ms := []*metric.Metric{}
8686

8787
if !p.CreationTimestamp.IsZero() {
@@ -100,7 +100,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
100100
"Current number of healthy pods",
101101
metric.Gauge,
102102
"",
103-
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
103+
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
104104
return &metric.Family{
105105
Metrics: []*metric.Metric{
106106
{
@@ -115,7 +115,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
115115
"Minimum desired number of healthy pods",
116116
metric.Gauge,
117117
"",
118-
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
118+
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
119119
return &metric.Family{
120120
Metrics: []*metric.Metric{
121121
{
@@ -130,7 +130,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
130130
"Number of pod disruptions that are currently allowed",
131131
metric.Gauge,
132132
"",
133-
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
133+
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
134134
return &metric.Family{
135135
Metrics: []*metric.Metric{
136136
{
@@ -145,7 +145,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
145145
"Total number of pods counted by this disruption budget",
146146
metric.Gauge,
147147
"",
148-
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
148+
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
149149
return &metric.Family{
150150
Metrics: []*metric.Metric{
151151
{
@@ -160,7 +160,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
160160
"Most recent generation observed when updating this PDB status",
161161
metric.Gauge,
162162
"",
163-
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
163+
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
164164
return &metric.Family{
165165
Metrics: []*metric.Metric{
166166
{
@@ -173,9 +173,9 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
173173
}
174174
}
175175

176-
func wrapPodDisruptionBudgetFunc(f func(*v1beta1.PodDisruptionBudget) *metric.Family) func(interface{}) *metric.Family {
176+
func wrapPodDisruptionBudgetFunc(f func(*policyv1.PodDisruptionBudget) *metric.Family) func(interface{}) *metric.Family {
177177
return func(obj interface{}) *metric.Family {
178-
podDisruptionBudget := obj.(*v1beta1.PodDisruptionBudget)
178+
podDisruptionBudget := obj.(*policyv1.PodDisruptionBudget)
179179

180180
metricFamily := f(podDisruptionBudget)
181181

@@ -192,11 +192,11 @@ func createPodDisruptionBudgetListWatch(kubeClient clientset.Interface, ns strin
192192
return &cache.ListWatch{
193193
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
194194
opts.FieldSelector = fieldSelector
195-
return kubeClient.PolicyV1beta1().PodDisruptionBudgets(ns).List(context.TODO(), opts)
195+
return kubeClient.PolicyV1().PodDisruptionBudgets(ns).List(context.TODO(), opts)
196196
},
197197
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
198198
opts.FieldSelector = fieldSelector
199-
return kubeClient.PolicyV1beta1().PodDisruptionBudgets(ns).Watch(context.TODO(), opts)
199+
return kubeClient.PolicyV1().PodDisruptionBudgets(ns).Watch(context.TODO(), opts)
200200
},
201201
}
202202
}

0 commit comments

Comments
 (0)