Skip to content

Commit

Permalink
Fix VolumeAttachment API version mismatch: expected v1 but watching v…
Browse files Browse the repository at this point in the history
…1beta1

Signed-off-by: Benjamin <benjamin@yunify.com>
  • Loading branch information
Benjamin committed May 6, 2020
1 parent 765afc9 commit a2743b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions internal/store/volumeattachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package store

import (
storagev1beta1 "k8s.io/api/storage/v1beta1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
Expand All @@ -38,7 +38,7 @@ var (
Name: descVolumeAttachmentLabelsName,
Type: metric.Gauge,
Help: descVolumeAttachmentLabelsHelp,
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
labelKeys, labelValues := kubeLabelsToPrometheusLabels(va.Labels)
return &metric.Family{
Metrics: []*metric.Metric{
Expand All @@ -55,7 +55,7 @@ var (
Name: "kube_volumeattachment_info",
Type: metric.Gauge,
Help: "Information about volumeattachment.",
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -71,7 +71,7 @@ var (
Name: "kube_volumeattachment_created",
Type: metric.Gauge,
Help: "Unix creation timestamp",
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
if !va.CreationTimestamp.IsZero() {
m := metric.Metric{
LabelKeys: nil,
Expand All @@ -87,7 +87,7 @@ var (
Name: "kube_volumeattachment_spec_source_persistentvolume",
Type: metric.Gauge,
Help: "PersistentVolume source reference.",
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
if va.Spec.Source.PersistentVolumeName != nil {
return &metric.Family{
Metrics: []*metric.Metric{
Expand All @@ -106,7 +106,7 @@ var (
Name: "kube_volumeattachment_status_attached",
Type: metric.Gauge,
Help: "Information about volumeattachment.",
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -122,7 +122,7 @@ var (
Name: "kube_volumeattachment_status_attachment_metadata",
Type: metric.Gauge,
Help: "volumeattachment metadata.",
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1beta1.VolumeAttachment) *metric.Family {
GenerateFunc: wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
labelKeys, labelValues := mapToPrometheusLabels(va.Status.AttachmentMetadata, "metadata")
return &metric.Family{
Metrics: []*metric.Metric{
Expand All @@ -138,9 +138,9 @@ var (
}
)

func wrapVolumeAttachmentFunc(f func(*storagev1beta1.VolumeAttachment) *metric.Family) func(interface{}) *metric.Family {
func wrapVolumeAttachmentFunc(f func(*storagev1.VolumeAttachment) *metric.Family) func(interface{}) *metric.Family {
return func(obj interface{}) *metric.Family {
va := obj.(*storagev1beta1.VolumeAttachment)
va := obj.(*storagev1.VolumeAttachment)

metricFamily := f(va)

Expand All @@ -156,10 +156,10 @@ func wrapVolumeAttachmentFunc(f func(*storagev1beta1.VolumeAttachment) *metric.F
func createVolumeAttachmentListWatch(kubeClient clientset.Interface, _ string) cache.ListerWatcher {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
return kubeClient.StorageV1beta1().VolumeAttachments().List(opts)
return kubeClient.StorageV1().VolumeAttachments().List(opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
return kubeClient.StorageV1beta1().VolumeAttachments().Watch(opts)
return kubeClient.StorageV1().VolumeAttachments().Watch(opts)
},
}
}
10 changes: 5 additions & 5 deletions internal/store/volumeattachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package store
import (
"testing"

storagev1beta1 "k8s.io/api/storage/v1beta1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

generator "k8s.io/kube-state-metrics/pkg/metric_generator"
Expand All @@ -45,23 +45,23 @@ func TestVolumeAttachmentStore(t *testing.T) {
volumename = "pvc-44f6ff3f-ba9b-49c4-9b95-8b01c4bd4bab"
cases = []generateMetricsTestCase{
{
Obj: &storagev1beta1.VolumeAttachment{
Obj: &storagev1.VolumeAttachment{
ObjectMeta: metav1.ObjectMeta{
Generation: 2,
Name: "csi-5ff16a1ad085261021e21c6cb3a6defb979a8794f25a4f90f6285664cff37224",
Labels: map[string]string{
"app": "foobar",
},
},
Spec: storagev1beta1.VolumeAttachmentSpec{
Spec: storagev1.VolumeAttachmentSpec{
Attacher: "cinder.csi.openstack.org",
NodeName: "node1",
Source: storagev1beta1.VolumeAttachmentSource{
Source: storagev1.VolumeAttachmentSource{
PersistentVolumeName: &volumename,
InlineVolumeSpec: nil,
},
},
Status: storagev1beta1.VolumeAttachmentStatus{
Status: storagev1.VolumeAttachmentStatus{
Attached: true,
AttachmentMetadata: map[string]string{
"DevicePath": "/dev/sdd",
Expand Down

0 comments on commit a2743b6

Please sign in to comment.