@@ -224,6 +224,31 @@ func CsiFullSync(ctx context.Context, metadataSyncer *metadataSyncInformer, vc s
224
224
}
225
225
}
226
226
227
+ // Iterate over all the file volume PVCs and check if file share export paths are added as annotations
228
+ // on it. If not added, then add file share export path annotations on such PVCs.
229
+ if metadataSyncer .clusterFlavor == cnstypes .CnsClusterFlavorWorkload {
230
+ k8sClient , err := k8sNewClient (ctx )
231
+ if err != nil {
232
+ log .Errorf ("FullSync for VC %s: Failed to create kubernetes client. Err: %+v" , vc , err )
233
+ return err
234
+ }
235
+ for _ , pv := range k8sPVs {
236
+ if IsFileVolume (pv ) {
237
+ if pvc , ok := pvToPVCMap [pv .Name ]; ok {
238
+ // Check if file share export path is available as annotation on PVC
239
+ if pvc .ObjectMeta .Annotations [common .Nfsv3ExportPathAnnotationKey ] == "" {
240
+ err = setFileShareAnnotationsOnPVC (ctx , k8sClient , metadataSyncer .volumeManager , pvc )
241
+ if err != nil {
242
+ log .Errorf ("FullSync for VC %s: Failed to add file share export path annotations " +
243
+ "for PVC %s, Err: %v. Continuing for other PVCs." , pvc .Name , err )
244
+ continue
245
+ }
246
+ }
247
+ }
248
+ }
249
+ }
250
+ }
251
+
227
252
var queryAllResult * cnstypes.CnsQueryResult
228
253
if metadataSyncer .configInfo .Cfg .Global .ClusterID != "" {
229
254
// Cluster ID is removed from vSphere Config Secret post 9.0 release in Supervisor
@@ -630,6 +655,60 @@ func patchVolumeAccessibleTopologyToPVC(ctx context.Context, k8sClient clientset
630
655
return nil
631
656
}
632
657
658
+ // setFileShareAnnotationsOnPVC sets file share export paths as annotation on file volume PVC if it
659
+ // is not already added. In case of upgrade from old version to VC 9.1 compatible CSI driver, this
660
+ // will add these annotations on all existing file volume PVCs.
661
+ func setFileShareAnnotationsOnPVC (ctx context.Context , k8sClient clientset.Interface ,
662
+ volumeManager volumes.Manager , pvc * v1.PersistentVolumeClaim ) error {
663
+ log := logger .GetLogger (ctx )
664
+ log .Infof ("setFileShareAnnotationsOnPVC: Setting file share annotation for PVC: %q, namespace: %q" ,
665
+ pvc .Name , pvc .Namespace )
666
+
667
+ namespacedPvcName := pvc .Namespace + "/" + pvc .Name
668
+ volumeId , ok := commonco .ContainerOrchestratorUtility .GetVolumeIDFromPVCName (namespacedPvcName )
669
+ if ! ok {
670
+ errmsg := fmt .Sprintf ("failed to get volumeId for PVC: %q, namespace: %q" , pvc .Name , pvc .Namespace )
671
+ log .Errorf ("setFileShareAnnotationsOnPVC: %s" , errmsg )
672
+ return errors .New (errmsg )
673
+ }
674
+
675
+ // Make a QueryVolume call to fetch file share export paths.
676
+ querySelection := cnstypes.CnsQuerySelection {
677
+ Names : []string {
678
+ string (cnstypes .QuerySelectionNameTypeBackingObjectDetails ),
679
+ },
680
+ }
681
+ volume , err := common .QueryVolumeByID (ctx , volumeManager , volumeId , & querySelection )
682
+ if err != nil {
683
+ log .Errorf ("setFileShareAnnotationsOnPVC: Error while performing QueryVolume on volume %s, Err: %+v" ,
684
+ volumeId , err )
685
+ }
686
+ vSANFileBackingDetails := volume .BackingObjectDetails .(* cnstypes.CnsVsanFileShareBackingDetails )
687
+ accessPoints := make (map [string ]string )
688
+ for _ , kv := range vSANFileBackingDetails .AccessPoints {
689
+ if kv .Key == common .Nfsv3AccessPointKey {
690
+ pvc .Annotations [common .Nfsv3ExportPathAnnotationKey ] = kv .Value
691
+ } else if kv .Key == common .Nfsv4AccessPointKey {
692
+ pvc .Annotations [common .Nfsv4ExportPathAnnotationKey ] = kv .Value
693
+ }
694
+ accessPoints [kv .Key ] = kv .Value
695
+ }
696
+ log .Debugf ("setFileShareAnnotationsOnPVC: Access point details for PVC: %q, namespace: %q are %+v" ,
697
+ pvc .Name , pvc .Namespace , accessPoints )
698
+
699
+ // Update PVC to add annotation on it
700
+ pvc , err = k8sClient .CoreV1 ().PersistentVolumeClaims (pvc .Namespace ).Update (ctx , pvc ,
701
+ metav1.UpdateOptions {})
702
+ if err != nil {
703
+ log .Errorf ("setFileShareAnnotationsOnPVC: Error updating PVC %q in namespace %q, Err: %v" ,
704
+ pvc .Name , pvc .Namespace , err )
705
+ return err
706
+ }
707
+ log .Infof ("setFileShareAnnotationsOnPVC: Added file share export paths annotation successfully on PVC %q, " +
708
+ "namespce %q" , pvc .Name , pvc .Namespace )
709
+ return nil
710
+ }
711
+
633
712
// cleanUpVolumeInfoCrDeletionMap removes volumes from the VolumeInfo CR deletion map
634
713
// if the volume is present in the K8s cluster.
635
714
// This may happen if is not yet created PV by the time full sync
0 commit comments