@@ -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,57 @@ func patchVolumeAccessibleTopologyToPVC(ctx context.Context, k8sClient clientset
630
655
return nil
631
656
}
632
657
658
+ func setFileShareAnnotationsOnPVC (ctx context.Context , k8sClient clientset.Interface ,
659
+ volumeManager volumes.Manager , pvc * v1.PersistentVolumeClaim ) error {
660
+ log := logger .GetLogger (ctx )
661
+ log .Infof ("setFileShareAnnotationsOnPVC: Setting file share annotation for pvc: %q, namespace: %q" ,
662
+ pvc .Name , pvc .Namespace )
663
+
664
+ pv , err := k8sClient .CoreV1 ().PersistentVolumes ().Get (ctx , pvc .Spec .VolumeName , metav1.GetOptions {})
665
+ if err != nil {
666
+ log .Errorf ("setFileShareAnnotationsOnPVC: Failed to get PV: %q , Err: %v." ,
667
+ pvc .Spec .VolumeName , err )
668
+ return err
669
+ }
670
+
671
+ // Make a QueryVolume call to fetch file share export paths.
672
+ querySelection := cnstypes.CnsQuerySelection {
673
+ Names : []string {
674
+ string (cnstypes .QuerySelectionNameTypeVolumeType ),
675
+ string (cnstypes .QuerySelectionNameTypeBackingObjectDetails ),
676
+ },
677
+ }
678
+ volume , err := common .QueryVolumeByID (ctx , volumeManager , pv .Spec .CSI .VolumeHandle , & querySelection )
679
+ if err != nil {
680
+ log .Errorf ("setFileShareAnnotationsOnPVC: Error while performing QueryVolume on volume %s, Err: %+v" ,
681
+ pv .Spec .CSI .VolumeHandle , err )
682
+ }
683
+ vSANFileBackingDetails := volume .BackingObjectDetails .(* cnstypes.CnsVsanFileShareBackingDetails )
684
+ accessPoints := make (map [string ]string )
685
+ for _ , kv := range vSANFileBackingDetails .AccessPoints {
686
+ if kv .Key == common .Nfsv3AccessPointKey {
687
+ pvc .Annotations [common .Nfsv3ExportPathAnnotationKey ] = kv .Value
688
+ } else if kv .Key == common .Nfsv4AccessPointKey {
689
+ pvc .Annotations [common .Nfsv4ExportPathAnnotationKey ] = kv .Value
690
+ }
691
+ accessPoints [kv .Key ] = kv .Value
692
+ }
693
+ log .Debugf ("setFileShareAnnotationsOnPVC: Access point details for pvc: %q, namespace: %q are %+v" ,
694
+ pvc .Name , pvc .Namespace , accessPoints )
695
+
696
+ // Update PVC to add annotation on it
697
+ pvc , err = k8sClient .CoreV1 ().PersistentVolumeClaims (pvc .Namespace ).Update (ctx , pvc ,
698
+ metav1.UpdateOptions {})
699
+ if err != nil {
700
+ log .Errorf ("setFileShareAnnotationsOnPVC: Error updating PVC %q in namespace %q, Err: %v" ,
701
+ pvc .Name , pvc .Namespace , err )
702
+ return err
703
+ }
704
+ log .Infof ("setFileShareAnnotationsOnPVC: Added file share export paths annotation successfully on PVC %q, " +
705
+ "namespce %q" , pvc .Name , pvc .Namespace )
706
+ return nil
707
+ }
708
+
633
709
// cleanUpVolumeInfoCrDeletionMap removes volumes from the VolumeInfo CR deletion map
634
710
// if the volume is present in the K8s cluster.
635
711
// This may happen if is not yet created PV by the time full sync
0 commit comments