@@ -21,6 +21,7 @@ import (
21
21
"encoding/json"
22
22
"errors"
23
23
"fmt"
24
+ "slices"
24
25
"strings"
25
26
"sync"
26
27
"time"
@@ -32,8 +33,6 @@ import (
32
33
"sigs.k8s.io/controller-runtime/pkg/client"
33
34
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
34
35
35
- "slices"
36
-
37
36
"github.com/container-storage-interface/spec/lib/go/csi"
38
37
"github.com/davecgh/go-spew/spew"
39
38
snapv1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
@@ -233,17 +232,31 @@ func CsiFullSync(ctx context.Context, metadataSyncer *metadataSyncInformer, vc s
233
232
}
234
233
}
235
234
236
- queryAllResult , err := utils .QueryAllVolumesForCluster (ctx , volManager ,
237
- metadataSyncer .configInfo .Cfg .Global .ClusterID , cnstypes.CnsQuerySelection {})
238
- if err != nil {
239
- log .Errorf ("FullSync for VC %s: QueryVolume failed with err=%+v" , vc , err .Error ())
240
- return err
235
+ var queryAllResult * cnstypes.CnsQueryResult
236
+ if metadataSyncer .configInfo .Cfg .Global .ClusterID != "" {
237
+ // Cluster ID is removed from vSphere Config Secret post 9.0 release in Supervisor
238
+ queryAllResult , err = utils .QueryAllVolumesForCluster (ctx , volManager ,
239
+ metadataSyncer .configInfo .Cfg .Global .ClusterID , cnstypes.CnsQuerySelection {})
240
+ if err != nil {
241
+ log .Errorf ("FullSync for VC %s: QueryVolume failed with err=%+v" , vc , err .Error ())
242
+ return err
243
+ }
244
+ } else {
245
+ log .Infof ("observed emptry string cluster-id in the vSphere Config secret. " +
246
+ "Skipping to replace volume metadata with older cluster-id to new supervisor-id" )
241
247
}
242
248
if metadataSyncer .clusterFlavor == cnstypes .CnsClusterFlavorWorkload &&
243
249
commonco .ContainerOrchestratorUtility .IsFSSEnabled (ctx , common .TKGsHA ) {
244
- // Replace Volume Metadata using old cluster ID and replace with the new SupervisorID
250
+ // Replace the Cluster-ID in the volume metadata with the new Supervisor-ID.
251
+ //
252
+ // Note:
253
+ // - In vSphere 9.1 and later, this replacement is not required because volume metadata already contains
254
+ // the correct Supervisor-ID.
255
+ // - In vSphere 9.0, the Cluster ID field in the metadata stores the Supervisor-ID. volume metadata created
256
+ // before 9.0 has already been updated to use the new Supervisor-ID.
257
+
245
258
var volumeIDsWithOldClusterID []cnstypes.CnsVolumeId
246
- if len (queryAllResult .Volumes ) > 0 {
259
+ if queryAllResult != nil && len (queryAllResult .Volumes ) > 0 {
247
260
for _ , volume := range queryAllResult .Volumes {
248
261
volumeIDsWithOldClusterID = append (volumeIDsWithOldClusterID , volume .VolumeId )
249
262
}
0 commit comments