@@ -60,6 +60,17 @@ func init() {
60
60
61
61
type opCounts map [string ]int64
62
62
63
+ // migrationOpCheck validates migrated metrics.
64
+ type migrationOpCheck struct {
65
+ cs clientset.Interface
66
+ pluginName string
67
+ skipCheck bool
68
+
69
+ // The old ops are not set if skipCheck is true.
70
+ oldInTreeOps opCounts
71
+ oldMigratedOps opCounts
72
+ }
73
+
63
74
// BaseSuites is a list of storage test suites that work for in-tree and CSI drivers
64
75
var BaseSuites = []func () TestSuite {
65
76
InitVolumesTestSuite ,
@@ -687,24 +698,18 @@ func getMigrationVolumeOpCounts(cs clientset.Interface, pluginName string) (opCo
687
698
return opCounts {}, opCounts {}
688
699
}
689
700
690
- func validateMigrationVolumeOpCounts (cs clientset.Interface , pluginName string , oldInTreeOps , oldMigratedOps opCounts ) {
701
+ func newMigrationOpCheck (cs clientset.Interface , pluginName string ) * migrationOpCheck {
702
+ moc := migrationOpCheck {
703
+ cs : cs ,
704
+ pluginName : pluginName ,
705
+ }
691
706
if len (pluginName ) == 0 {
692
707
// This is a native CSI Driver and we don't check ops
693
- return
708
+ moc .skipCheck = true
709
+ return & moc
694
710
}
695
711
696
- if sets .NewString (strings .Split (* migratedPlugins , "," )... ).Has (pluginName ) {
697
- // If this plugin is migrated based on the test flag storage.migratedPlugins
698
- newInTreeOps , _ := getMigrationVolumeOpCounts (cs , pluginName )
699
-
700
- for op , count := range newInTreeOps {
701
- if count != oldInTreeOps [op ] {
702
- framework .Failf ("In-tree plugin %v migrated to CSI Driver, however found %v %v metrics for in-tree plugin" , pluginName , count - oldInTreeOps [op ], op )
703
- }
704
- }
705
- // We don't check for migrated metrics because some negative test cases
706
- // may not do any volume operations and therefore not emit any metrics
707
- } else {
712
+ if ! sets .NewString (strings .Split (* migratedPlugins , "," )... ).Has (pluginName ) {
708
713
// In-tree plugin is not migrated
709
714
framework .Logf ("In-tree plugin %v is not migrated, not validating any metrics" , pluginName )
710
715
@@ -721,7 +726,27 @@ func validateMigrationVolumeOpCounts(cs clientset.Interface, pluginName string,
721
726
// and native CSI Driver metrics. This way we can check the counts for
722
727
// migrated version of the driver for stronger negative test case
723
728
// guarantees (as well as more informative metrics).
729
+ moc .skipCheck = true
730
+ return & moc
731
+ }
732
+ moc .oldInTreeOps , moc .oldMigratedOps = getMigrationVolumeOpCounts (cs , pluginName )
733
+ return & moc
734
+ }
735
+
736
+ func (moc * migrationOpCheck ) validateMigrationVolumeOpCounts () {
737
+ if moc .skipCheck {
738
+ return
739
+ }
740
+
741
+ newInTreeOps , _ := getMigrationVolumeOpCounts (moc .cs , moc .pluginName )
742
+
743
+ for op , count := range newInTreeOps {
744
+ if count != moc .oldInTreeOps [op ] {
745
+ framework .Failf ("In-tree plugin %v migrated to CSI Driver, however found %v %v metrics for in-tree plugin" , moc .pluginName , count - moc .oldInTreeOps [op ], op )
746
+ }
724
747
}
748
+ // We don't check for migrated metrics because some negative test cases
749
+ // may not do any volume operations and therefore not emit any metrics
725
750
}
726
751
727
752
// Skip skipVolTypes patterns if the driver supports dynamic provisioning
0 commit comments