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