@@ -41,6 +41,7 @@ import (
41
41
cnsconfig "sigs.k8s.io/vsphere-csi-driver/v3/pkg/common/config"
42
42
"sigs.k8s.io/vsphere-csi-driver/v3/pkg/common/unittestcommon"
43
43
"sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service/common"
44
+ "sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service/common/commonco"
44
45
csitypes "sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/types"
45
46
k8s "sigs.k8s.io/vsphere-csi-driver/v3/pkg/kubernetes"
46
47
)
@@ -216,6 +217,7 @@ func TestSyncerWorkflows(t *testing.T) {
216
217
dsList = append (dsList , datastoreInfoObj .Datastore .Reference ())
217
218
runTestMetadataSyncInformer (t )
218
219
runTestFullSyncWorkflows (t )
220
+ runTestCsiFullSync_WorkloadCluster (t )
219
221
t .Log ("TestSyncerWorkflows: end" )
220
222
}
221
223
@@ -991,3 +993,47 @@ func TestGetVCForTopologySegments(t *testing.T) {
991
993
})
992
994
}
993
995
}
996
+
997
+ // TestCsiFullSync_WorkloadCluster tests that CsiFullSync works correctly for WORKLOAD clusters
998
+ // This test runs as a subtest within TestSyncerWorkflows to ensure proper initialization
999
+ func runTestCsiFullSync_WorkloadCluster (t * testing.T ) {
1000
+ ctx , cancel := context .WithCancel (context .Background ())
1001
+ defer cancel ()
1002
+
1003
+ // Initialize commonco.ContainerOrchestratorUtility for WORKLOAD cluster testing
1004
+ // This is required for CsiFullSync to work properly with WORKLOAD clusters
1005
+ fakeCommonCO , err := unittestcommon .GetFakeContainerOrchestratorInterface (common .Kubernetes )
1006
+ if err != nil {
1007
+ t .Fatalf ("Failed to get fake CO interface: %v" , err )
1008
+ }
1009
+ // Store the original value to restore later
1010
+ originalCO := commonco .ContainerOrchestratorUtility
1011
+ commonco .ContainerOrchestratorUtility = fakeCommonCO
1012
+ defer func () {
1013
+ commonco .ContainerOrchestratorUtility = originalCO
1014
+ }()
1015
+
1016
+ // Create a WORKLOAD cluster metadataSyncer (note: volumeManagers map is NOT populated)
1017
+ // This simulates the real WORKLOAD cluster setup where only volumeManager is set
1018
+ workloadMetadataSyncer := & metadataSyncInformer {
1019
+ clusterFlavor : cnstypes .CnsClusterFlavorWorkload ,
1020
+ volumeManager : volumeManager , // Use the initialized global volumeManager
1021
+ host : virtualCenter .Config .Host ,
1022
+ configInfo : metadataSyncer .configInfo , // Use the global metadataSyncer's configInfo
1023
+ coCommonInterface : metadataSyncer .coCommonInterface , // Use the global metadataSyncer's coCommonInterface
1024
+ // Copy the Kubernetes listers from the global metadataSyncer
1025
+ pvLister : metadataSyncer .pvLister ,
1026
+ pvcLister : metadataSyncer .pvcLister ,
1027
+ podLister : metadataSyncer .podLister ,
1028
+ // volumeManagers map is intentionally NOT populated to simulate real WORKLOAD cluster
1029
+ }
1030
+
1031
+ // Test that CsiFullSync works for WORKLOAD cluster - this is the high-level test
1032
+ // that verifies the entire full sync flow doesn't fail due to the regression
1033
+ err = CsiFullSync (ctx , workloadMetadataSyncer , virtualCenter .Config .Host )
1034
+ if err != nil {
1035
+ t .Errorf ("CsiFullSync failed for WORKLOAD cluster: %v" , err )
1036
+ }
1037
+
1038
+ t .Logf ("CsiFullSync completed successfully for WORKLOAD cluster" )
1039
+ }
0 commit comments