@@ -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,58 @@ 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
+ namespacedPvcName := pvc .Namespace + "/" + pvc .Name
665
+ volumeId , ok := commonco .ContainerOrchestratorUtility .GetVolumeIDFromPVCName (namespacedPvcName )
666
+ if ! ok {
667
+ errmsg := fmt .Sprintf ("failed to get volumeId for PVC: %q, namespace: %q" , pvc .Name , pvc .Namespace )
668
+ log .Errorf ("setFileShareAnnotationsOnPVC: %s" , errmsg )
669
+ return errors .New (errmsg )
670
+ }
671
+
672
+ // Make a QueryVolume call to fetch file share export paths.
673
+ querySelection := cnstypes.CnsQuerySelection {
674
+ Names : []string {
675
+ string (cnstypes .QuerySelectionNameTypeVolumeType ),
676
+ string (cnstypes .QuerySelectionNameTypeBackingObjectDetails ),
677
+ },
678
+ }
679
+ volume , err := common .QueryVolumeByID (ctx , volumeManager , volumeId , & querySelection )
680
+ if err != nil {
681
+ log .Errorf ("setFileShareAnnotationsOnPVC: Error while performing QueryVolume on volume %s, Err: %+v" ,
682
+ volumeId , err )
683
+ }
684
+ vSANFileBackingDetails := volume .BackingObjectDetails .(* cnstypes.CnsVsanFileShareBackingDetails )
685
+ accessPoints := make (map [string ]string )
686
+ for _ , kv := range vSANFileBackingDetails .AccessPoints {
687
+ if kv .Key == common .Nfsv3AccessPointKey {
688
+ pvc .Annotations [common .Nfsv3ExportPathAnnotationKey ] = kv .Value
689
+ } else if kv .Key == common .Nfsv4AccessPointKey {
690
+ pvc .Annotations [common .Nfsv4ExportPathAnnotationKey ] = kv .Value
691
+ }
692
+ accessPoints [kv .Key ] = kv .Value
693
+ }
694
+ log .Debugf ("setFileShareAnnotationsOnPVC: Access point details for PVC: %q, namespace: %q are %+v" ,
695
+ pvc .Name , pvc .Namespace , accessPoints )
696
+
697
+ // Update PVC to add annotation on it
698
+ pvc , err = k8sClient .CoreV1 ().PersistentVolumeClaims (pvc .Namespace ).Update (ctx , pvc ,
699
+ metav1.UpdateOptions {})
700
+ if err != nil {
701
+ log .Errorf ("setFileShareAnnotationsOnPVC: Error updating PVC %q in namespace %q, Err: %v" ,
702
+ pvc .Name , pvc .Namespace , err )
703
+ return err
704
+ }
705
+ log .Infof ("setFileShareAnnotationsOnPVC: Added file share export paths annotation successfully on PVC %q, " +
706
+ "namespce %q" , pvc .Name , pvc .Namespace )
707
+ return nil
708
+ }
709
+
633
710
// cleanUpVolumeInfoCrDeletionMap removes volumes from the VolumeInfo CR deletion map
634
711
// if the volume is present in the K8s cluster.
635
712
// This may happen if is not yet created PV by the time full sync
0 commit comments