@@ -32,7 +32,9 @@ import (
3232 clientset "k8s.io/client-go/kubernetes"
3333 "k8s.io/component-base/metrics/testutil"
3434 "k8s.io/component-helpers/storage/ephemeral"
35+ "k8s.io/kubernetes/pkg/features"
3536 kubeletmetrics "k8s.io/kubernetes/pkg/kubelet/metrics"
37+ "k8s.io/kubernetes/test/e2e/feature"
3638 "k8s.io/kubernetes/test/e2e/framework"
3739 e2emetrics "k8s.io/kubernetes/test/e2e/framework/metrics"
3840 e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
@@ -499,10 +501,11 @@ var _ = utils.SIGDescribe(framework.WithSerial(), "Volume metrics", func() {
499501 // Test for pv controller metrics, concretely: bound/unbound pv/pvc count.
500502 ginkgo .Describe ("PVController" , func () {
501503 const (
502- classKey = "storage_class"
503- namespaceKey = "namespace"
504- pluginNameKey = "plugin_name"
505- volumeModeKey = "volume_mode"
504+ namespaceKey = "namespace"
505+ pluginNameKey = "plugin_name"
506+ volumeModeKey = "volume_mode"
507+ storageClassKey = "storage_class"
508+ volumeAttributeClassKey = "volume_attributes_class"
506509
507510 totalPVKey = "pv_collector_total_pv_count"
508511 boundPVKey = "pv_collector_bound_pv_count"
@@ -515,22 +518,24 @@ var _ = utils.SIGDescribe(framework.WithSerial(), "Volume metrics", func() {
515518 pv * v1.PersistentVolume
516519 pvc * v1.PersistentVolumeClaim
517520
518- className = "bound-unbound-count-test-sc"
519- pvConfig = e2epv.PersistentVolumeConfig {
521+ storageClassName = "bound-unbound-count-test-sc"
522+ pvConfig = e2epv.PersistentVolumeConfig {
520523 PVSource : v1.PersistentVolumeSource {
521524 HostPath : & v1.HostPathVolumeSource {Path : "/data" },
522525 },
523526 NamePrefix : "pv-test-" ,
524- StorageClassName : className ,
527+ StorageClassName : storageClassName ,
525528 }
526- pvcConfig = e2epv.PersistentVolumeClaimConfig {StorageClassName : & className }
529+ // TODO: Insert volumeAttributesClassName into pvcConfig when "VolumeAttributesClass" is GA
530+ volumeAttributesClassName = "bound-unbound-count-test-vac"
531+ pvcConfig = e2epv.PersistentVolumeClaimConfig {StorageClassName : & storageClassName }
527532
528533 e2emetrics = []struct {
529534 name string
530535 dimension string
531536 }{
532- {boundPVKey , classKey },
533- {unboundPVKey , classKey },
537+ {boundPVKey , storageClassKey },
538+ {unboundPVKey , storageClassKey },
534539 {boundPVCKey , namespaceKey },
535540 {unboundPVCKey , namespaceKey },
536541 }
@@ -556,7 +561,7 @@ var _ = utils.SIGDescribe(framework.WithSerial(), "Volume metrics", func() {
556561 if expectValues == nil {
557562 expectValues = make (map [string ]int64 )
558563 }
559- // We using relative increment value instead of absolute value to reduce unexpected flakes.
564+ // We use relative increment value instead of absolute value to reduce unexpected flakes.
560565 // Concretely, we expect the difference of the updated values and original values for each
561566 // test suit are equal to expectValues.
562567 actualValues := calculateRelativeValues (originMetricValues [i ],
@@ -604,8 +609,8 @@ var _ = utils.SIGDescribe(framework.WithSerial(), "Volume metrics", func() {
604609 var err error
605610 pv , err = e2epv .CreatePV (ctx , c , f .Timeouts , pv )
606611 framework .ExpectNoError (err , "Error creating pv: %v" , err )
607- waitForPVControllerSync (ctx , metricsGrabber , unboundPVKey , classKey )
608- validator (ctx , []map [string ]int64 {nil , {className : 1 }, nil , nil })
612+ waitForPVControllerSync (ctx , metricsGrabber , unboundPVKey , storageClassKey )
613+ validator (ctx , []map [string ]int64 {nil , {storageClassName : 1 }, nil , nil })
609614 })
610615
611616 ginkgo .It ("should create unbound pvc count metrics for pvc controller after creating pvc only" ,
@@ -622,11 +627,45 @@ var _ = utils.SIGDescribe(framework.WithSerial(), "Volume metrics", func() {
622627 var err error
623628 pv , pvc , err = e2epv .CreatePVPVC (ctx , c , f .Timeouts , pvConfig , pvcConfig , ns , true )
624629 framework .ExpectNoError (err , "Error creating pv pvc: %v" , err )
625- waitForPVControllerSync (ctx , metricsGrabber , boundPVKey , classKey )
630+ waitForPVControllerSync (ctx , metricsGrabber , boundPVKey , storageClassKey )
626631 waitForPVControllerSync (ctx , metricsGrabber , boundPVCKey , namespaceKey )
627- validator (ctx , []map [string ]int64 {{className : 1 }, nil , {ns : 1 }, nil })
632+ validator (ctx , []map [string ]int64 {{storageClassName : 1 }, nil , {ns : 1 }, nil })
633+ })
634+
635+ // TODO: Merge with bound/unbound tests when "VolumeAttributesClass" feature is enabled by default
636+ f .It ("should create unbound pvc count metrics for pvc controller with volume attributes class dimension after creating pvc only" ,
637+ feature .VolumeAttributesClass , framework .WithFeatureGate (features .VolumeAttributesClass ), func (ctx context.Context ) {
638+ var err error
639+ dimensions := []string {namespaceKey , storageClassKey , volumeAttributeClassKey }
640+ pvcConfigWithVAC := pvcConfig
641+ pvcConfigWithVAC .VolumeAttributesClassName = & volumeAttributesClassName
642+ pvcWithVAC := e2epv .MakePersistentVolumeClaim (pvcConfigWithVAC , ns )
643+ pvc , err = e2epv .CreatePVC (ctx , c , ns , pvcWithVAC )
644+ framework .ExpectNoError (err , "Error creating pvc: %v" , err )
645+ waitForPVControllerSync (ctx , metricsGrabber , unboundPVCKey , volumeAttributeClassKey )
646+ controllerMetrics , err := metricsGrabber .GrabFromControllerManager (ctx )
647+ framework .ExpectNoError (err , "Error getting c-m metricValues: %v" , err )
648+ err = testutil .ValidateMetrics (testutil .Metrics (controllerMetrics ), unboundPVCKey , dimensions ... )
649+ framework .ExpectNoError (err , "Invalid metric in Controller Manager metrics: %q" , unboundPVCKey )
650+ })
628651
652+ // TODO: Merge with bound/unbound tests when "VolumeAttributesClass" feature is enabled by default
653+ f .It ("should create bound pv/pvc count metrics for pvc controller with volume attributes class dimension after creating both pv and pvc" ,
654+ feature .VolumeAttributesClass , framework .WithFeatureGate (features .VolumeAttributesClass ), func (ctx context.Context ) {
655+ var err error
656+ dimensions := []string {namespaceKey , storageClassKey , volumeAttributeClassKey }
657+ pvcConfigWithVAC := pvcConfig
658+ pvcConfigWithVAC .VolumeAttributesClassName = & volumeAttributesClassName
659+ pv , pvc , err = e2epv .CreatePVPVC (ctx , c , f .Timeouts , pvConfig , pvcConfigWithVAC , ns , true )
660+ framework .ExpectNoError (err , "Error creating pv pvc: %v" , err )
661+ waitForPVControllerSync (ctx , metricsGrabber , boundPVKey , storageClassKey )
662+ waitForPVControllerSync (ctx , metricsGrabber , boundPVCKey , volumeAttributeClassKey )
663+ controllerMetrics , err := metricsGrabber .GrabFromControllerManager (ctx )
664+ framework .ExpectNoError (err , "Error getting c-m metricValues: %v" , err )
665+ err = testutil .ValidateMetrics (testutil .Metrics (controllerMetrics ), boundPVCKey , dimensions ... )
666+ framework .ExpectNoError (err , "Invalid metric in Controller Manager metrics: %q" , boundPVCKey )
629667 })
668+
630669 ginkgo .It ("should create total pv count metrics for with plugin and volume mode labels after creating pv" ,
631670 func (ctx context.Context ) {
632671 var err error
0 commit comments