Skip to content

Commit

Permalink
Merge pull request #1491 from bison/deprecated-versions
Browse files Browse the repository at this point in the history
Use v1 PodDisruptionBudget and CronJob resources
  • Loading branch information
k8s-ci-robot authored Jan 4, 2022
2 parents 081cc3c + d01ad03 commit 41eea36
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 52 deletions.
7 changes: 3 additions & 4 deletions internal/store/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ import (
appsv1 "k8s.io/api/apps/v1"
autoscaling "k8s.io/api/autoscaling/v2beta2"
batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
certv1 "k8s.io/api/certificates/v1"
coordinationv1 "k8s.io/api/coordination/v1"
v1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
policy "k8s.io/api/policy/v1beta1"
policyv1 "k8s.io/api/policy/v1"
storagev1 "k8s.io/api/storage/v1"
vpaautoscaling "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta2"
vpaclientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -310,7 +309,7 @@ func (b *Builder) buildConfigMapStores() []cache.Store {
}

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

func (b *Builder) buildDaemonSetStores() []cache.Store {
Expand Down Expand Up @@ -366,7 +365,7 @@ func (b *Builder) buildPersistentVolumeStores() []cache.Store {
}

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

func (b *Builder) buildReplicaSetStores() []cache.Store {
Expand Down
34 changes: 17 additions & 17 deletions internal/store/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/pkg/errors"
"github.com/robfig/cron/v3"
batchv1beta1 "k8s.io/api/batch/v1beta1"
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
Expand All @@ -48,7 +48,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
descCronJobAnnotationsHelp,
metric.Gauge,
"",
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", j.Annotations, allowAnnotationsList)
return &metric.Family{
Metrics: []*metric.Metric{
Expand All @@ -66,7 +66,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
descCronJobLabelsHelp,
metric.Gauge,
"",
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
labelKeys, labelValues := createPrometheusLabelKeysValues("label", j.Labels, allowLabelsList)
return &metric.Family{
Metrics: []*metric.Metric{
Expand All @@ -84,7 +84,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
"Info about cronjob.",
metric.Gauge,
"",
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -101,7 +101,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
"Unix creation timestamp",
metric.Gauge,
"",
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
ms := []*metric.Metric{}
if !j.CreationTimestamp.IsZero() {
ms = append(ms, &metric.Metric{
Expand All @@ -121,7 +121,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
"Active holds pointers to currently running jobs.",
metric.Gauge,
"",
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -138,7 +138,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
"LastScheduleTime keeps information of when was the last time the job was successfully scheduled.",
metric.Gauge,
"",
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
ms := []*metric.Metric{}

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

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

if j.Spec.StartingDeadlineSeconds != nil {
Expand All @@ -202,7 +202,7 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
"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.",
metric.Gauge,
"",
wrapCronJobFunc(func(j *batchv1beta1.CronJob) *metric.Family {
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
ms := []*metric.Metric{}

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

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

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

func wrapCronJobFunc(f func(*batchv1beta1.CronJob) *metric.Family) func(interface{}) *metric.Family {
func wrapCronJobFunc(f func(*batchv1.CronJob) *metric.Family) func(interface{}) *metric.Family {
return func(obj interface{}) *metric.Family {
cronJob := obj.(*batchv1beta1.CronJob)
cronJob := obj.(*batchv1.CronJob)

metricFamily := f(cronJob)

Expand All @@ -297,11 +297,11 @@ func createCronJobListWatch(kubeClient clientset.Interface, ns string, fieldSele
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.BatchV1beta1().CronJobs(ns).List(context.TODO(), opts)
return kubeClient.BatchV1().CronJobs(ns).List(context.TODO(), opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.BatchV1beta1().CronJobs(ns).Watch(context.TODO(), opts)
return kubeClient.BatchV1().CronJobs(ns).Watch(context.TODO(), opts)
},
}
}
Expand Down
20 changes: 10 additions & 10 deletions internal/store/cronjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"testing"
"time"

batchv1beta1 "k8s.io/api/batch/v1beta1"
batchv1 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -106,7 +106,7 @@ func TestCronJobStore(t *testing.T) {
AllowAnnotationsList: []string{
"app.k8s.io/owner",
},
Obj: &batchv1beta1.CronJob{
Obj: &batchv1.CronJob{
ObjectMeta: metav1.ObjectMeta{
Name: "ActiveRunningCronJob1",
Namespace: "ns1",
Expand All @@ -120,11 +120,11 @@ func TestCronJobStore(t *testing.T) {
"app.k8s.io/owner": "@foo",
},
},
Status: batchv1beta1.CronJobStatus{
Status: batchv1.CronJobStatus{
Active: []v1.ObjectReference{{Name: "FakeJob1"}, {Name: "FakeJob2"}},
LastScheduleTime: &metav1.Time{Time: ActiveRunningCronJob1LastScheduleTime},
},
Spec: batchv1beta1.CronJobSpec{
Spec: batchv1.CronJobSpec{
StartingDeadlineSeconds: &StartingDeadlineSeconds300,
ConcurrencyPolicy: "Forbid",
Suspend: &SuspendFalse,
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestCronJobStore(t *testing.T) {
},
},
{
Obj: &batchv1beta1.CronJob{
Obj: &batchv1.CronJob{
ObjectMeta: metav1.ObjectMeta{
Name: "SuspendedCronJob1",
Namespace: "ns1",
Expand All @@ -196,11 +196,11 @@ func TestCronJobStore(t *testing.T) {
"app": "example-suspended-1",
},
},
Status: batchv1beta1.CronJobStatus{
Status: batchv1.CronJobStatus{
Active: []v1.ObjectReference{},
LastScheduleTime: &metav1.Time{Time: SuspendedCronJob1LastScheduleTime},
},
Spec: batchv1beta1.CronJobSpec{
Spec: batchv1.CronJobSpec{
StartingDeadlineSeconds: &StartingDeadlineSeconds300,
ConcurrencyPolicy: "Forbid",
Suspend: &SuspendTrue,
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestCronJobStore(t *testing.T) {
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"},
},
{
Obj: &batchv1beta1.CronJob{
Obj: &batchv1.CronJob{
ObjectMeta: metav1.ObjectMeta{
Name: "ActiveCronJob1NoLastScheduled",
CreationTimestamp: metav1.Time{Time: ActiveCronJob1NoLastScheduledCreationTimestamp},
Expand All @@ -254,11 +254,11 @@ func TestCronJobStore(t *testing.T) {
"app": "example-active-no-last-scheduled-1",
},
},
Status: batchv1beta1.CronJobStatus{
Status: batchv1.CronJobStatus{
Active: []v1.ObjectReference{},
LastScheduleTime: nil,
},
Spec: batchv1beta1.CronJobSpec{
Spec: batchv1.CronJobSpec{
StartingDeadlineSeconds: &StartingDeadlineSeconds300,
ConcurrencyPolicy: "Forbid",
Suspend: &SuspendFalse,
Expand Down
26 changes: 13 additions & 13 deletions internal/store/poddisruptionbudget.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package store
import (
"context"

"k8s.io/api/policy/v1beta1"
policyv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
Expand All @@ -45,7 +45,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
descPodDisruptionBudgetAnnotationsHelp,
metric.Gauge,
"",
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", p.Annotations, allowAnnotationsList)
return &metric.Family{
Metrics: []*metric.Metric{
Expand All @@ -63,7 +63,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
descPodDisruptionBudgetLabelsHelp,
metric.Gauge,
"",
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
labelKeys, labelValues := createPrometheusLabelKeysValues("label", p.Labels, allowLabelsList)
return &metric.Family{
Metrics: []*metric.Metric{
Expand All @@ -81,7 +81,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
"Unix creation timestamp",
metric.Gauge,
"",
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
ms := []*metric.Metric{}

if !p.CreationTimestamp.IsZero() {
Expand All @@ -100,7 +100,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
"Current number of healthy pods",
metric.Gauge,
"",
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -115,7 +115,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
"Minimum desired number of healthy pods",
metric.Gauge,
"",
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -130,7 +130,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
"Number of pod disruptions that are currently allowed",
metric.Gauge,
"",
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -145,7 +145,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
"Total number of pods counted by this disruption budget",
metric.Gauge,
"",
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -160,7 +160,7 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
"Most recent generation observed when updating this PDB status",
metric.Gauge,
"",
wrapPodDisruptionBudgetFunc(func(p *v1beta1.PodDisruptionBudget) *metric.Family {
wrapPodDisruptionBudgetFunc(func(p *policyv1.PodDisruptionBudget) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -173,9 +173,9 @@ func podDisruptionBudgetMetricFamilies(allowAnnotationsList, allowLabelsList []s
}
}

func wrapPodDisruptionBudgetFunc(f func(*v1beta1.PodDisruptionBudget) *metric.Family) func(interface{}) *metric.Family {
func wrapPodDisruptionBudgetFunc(f func(*policyv1.PodDisruptionBudget) *metric.Family) func(interface{}) *metric.Family {
return func(obj interface{}) *metric.Family {
podDisruptionBudget := obj.(*v1beta1.PodDisruptionBudget)
podDisruptionBudget := obj.(*policyv1.PodDisruptionBudget)

metricFamily := f(podDisruptionBudget)

Expand All @@ -192,11 +192,11 @@ func createPodDisruptionBudgetListWatch(kubeClient clientset.Interface, ns strin
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.PolicyV1beta1().PodDisruptionBudgets(ns).List(context.TODO(), opts)
return kubeClient.PolicyV1().PodDisruptionBudgets(ns).List(context.TODO(), opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.PolicyV1beta1().PodDisruptionBudgets(ns).Watch(context.TODO(), opts)
return kubeClient.PolicyV1().PodDisruptionBudgets(ns).Watch(context.TODO(), opts)
},
}
}
Loading

0 comments on commit 41eea36

Please sign in to comment.