Skip to content

Commit 8b2b6f5

Browse files
Benjamintariq1890
Benjamin
authored andcommitted
Fix VolumeAttachment API version mismatch: expected v1 but watching v1beta1
Signed-off-by: Benjamin <benjamin@yunify.com> (cherry picked from commit a2743b6)
1 parent 7710f43 commit 8b2b6f5

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

internal/store/volumeattachment.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package store
1818

1919
import (
20-
storagev1beta1 "k8s.io/api/storage/v1beta1"
20+
storagev1 "k8s.io/api/storage/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
"k8s.io/apimachinery/pkg/runtime"
2323
"k8s.io/apimachinery/pkg/watch"
@@ -37,7 +37,7 @@ var (
3737
Name: descVolumeAttachmentLabelsName,
3838
Type: metric.Gauge,
3939
Help: descVolumeAttachmentLabelsHelp,
40-
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
40+
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
4141
labelKeys, labelValues := kubeLabelsToPrometheusLabels(va.Labels)
4242
return &metric.Family{
4343
Metrics: []*metric.Metric{
@@ -54,7 +54,7 @@ var (
5454
Name: "kube_volumeattachment_info",
5555
Type: metric.Gauge,
5656
Help: "Information about volumeattachment.",
57-
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
57+
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
5858
return &metric.Family{
5959
Metrics: []*metric.Metric{
6060
{
@@ -70,7 +70,7 @@ var (
7070
Name: "kube_volumeattachment_created",
7171
Type: metric.Gauge,
7272
Help: "Unix creation timestamp",
73-
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
73+
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
7474
if !va.CreationTimestamp.IsZero() {
7575
m := metric.Metric{
7676
LabelKeys: nil,
@@ -86,7 +86,7 @@ var (
8686
Name: "kube_volumeattachment_spec_source_persistentvolume",
8787
Type: metric.Gauge,
8888
Help: "PersistentVolume source reference.",
89-
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
89+
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
9090
if va.Spec.Source.PersistentVolumeName != nil {
9191
return &metric.Family{
9292
Metrics: []*metric.Metric{
@@ -105,7 +105,7 @@ var (
105105
Name: "kube_volumeattachment_status_attached",
106106
Type: metric.Gauge,
107107
Help: "Information about volumeattachment.",
108-
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
108+
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
109109
return &metric.Family{
110110
Metrics: []*metric.Metric{
111111
{
@@ -121,7 +121,7 @@ var (
121121
Name: "kube_volumeattachment_status_attachment_metadata",
122122
Type: metric.Gauge,
123123
Help: "volumeattachment metadata.",
124-
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
124+
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
125125
labelKeys, labelValues := mapToPrometheusLabels(va.Status.AttachmentMetadata, "metadata")
126126
return &metric.Family{
127127
Metrics: []*metric.Metric{
@@ -137,9 +137,9 @@ var (
137137
}
138138
)
139139

140-
func wrapVolumeAttachmentFunc(f func(*storagev1beta1.VolumeAttachment) *metric.Family) func(interface{}) *metric.Family {
140+
func wrapVolumeAttachmentFunc(f func(*storagev1.VolumeAttachment) *metric.Family) func(interface{}) *metric.Family {
141141
return func(obj interface{}) *metric.Family {
142-
va := obj.(*storagev1beta1.VolumeAttachment)
142+
va := obj.(*storagev1.VolumeAttachment)
143143

144144
metricFamily := f(va)
145145

@@ -155,10 +155,10 @@ func wrapVolumeAttachmentFunc(f func(*storagev1beta1.VolumeAttachment) *metric.F
155155
func createVolumeAttachmentListWatch(kubeClient clientset.Interface, _ string) cache.ListerWatcher {
156156
return &cache.ListWatch{
157157
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
158-
return kubeClient.StorageV1beta1().VolumeAttachments().List(opts)
158+
return kubeClient.StorageV1().VolumeAttachments().List(opts)
159159
},
160160
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
161-
return kubeClient.StorageV1beta1().VolumeAttachments().Watch(opts)
161+
return kubeClient.StorageV1().VolumeAttachments().Watch(opts)
162162
},
163163
}
164164
}

internal/store/volumeattachment_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ limitations under the License.
1717
package store
1818

1919
import (
20-
storagev1beta1 "k8s.io/api/storage/v1beta1"
21-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22-
2320
"testing"
2421

22+
storagev1 "k8s.io/api/storage/v1"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
2525
"k8s.io/kube-state-metrics/pkg/metric"
2626
)
2727

@@ -45,23 +45,23 @@ func TestVolumeAttachmentStore(t *testing.T) {
4545
volumename = "pvc-44f6ff3f-ba9b-49c4-9b95-8b01c4bd4bab"
4646
cases = []generateMetricsTestCase{
4747
{
48-
Obj: &storagev1beta1.VolumeAttachment{
48+
Obj: &storagev1.VolumeAttachment{
4949
ObjectMeta: metav1.ObjectMeta{
5050
Generation: 2,
5151
Name: "csi-5ff16a1ad085261021e21c6cb3a6defb979a8794f25a4f90f6285664cff37224",
5252
Labels: map[string]string{
5353
"app": "foobar",
5454
},
5555
},
56-
Spec: storagev1beta1.VolumeAttachmentSpec{
56+
Spec: storagev1.VolumeAttachmentSpec{
5757
Attacher: "cinder.csi.openstack.org",
5858
NodeName: "node1",
59-
Source: storagev1beta1.VolumeAttachmentSource{
59+
Source: storagev1.VolumeAttachmentSource{
6060
PersistentVolumeName: &volumename,
6161
InlineVolumeSpec: nil,
6262
},
6363
},
64-
Status: storagev1beta1.VolumeAttachmentStatus{
64+
Status: storagev1.VolumeAttachmentStatus{
6565
Attached: true,
6666
AttachmentMetadata: map[string]string{
6767
"DevicePath": "/dev/sdd",

0 commit comments

Comments
 (0)