Skip to content

Commit 912cd98

Browse files
authored
remove usage of cluster-id in CSI full-sync for supervisor (#3415)
1 parent ebeec89 commit 912cd98

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

pkg/syncer/fullsync.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/json"
2222
"errors"
2323
"fmt"
24+
"slices"
2425
"strings"
2526
"sync"
2627
"time"
@@ -32,8 +33,6 @@ import (
3233
"sigs.k8s.io/controller-runtime/pkg/client"
3334
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3435

35-
"slices"
36-
3736
"github.com/container-storage-interface/spec/lib/go/csi"
3837
"github.com/davecgh/go-spew/spew"
3938
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
233232
}
234233
}
235234

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")
241247
}
242248
if metadataSyncer.clusterFlavor == cnstypes.CnsClusterFlavorWorkload &&
243249
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+
245258
var volumeIDsWithOldClusterID []cnstypes.CnsVolumeId
246-
if len(queryAllResult.Volumes) > 0 {
259+
if queryAllResult != nil && len(queryAllResult.Volumes) > 0 {
247260
for _, volume := range queryAllResult.Volumes {
248261
volumeIDsWithOldClusterID = append(volumeIDsWithOldClusterID, volume.VolumeId)
249262
}

0 commit comments

Comments
 (0)