@@ -27,6 +27,7 @@ import (
2727
2828 vmoperatortypes "github.com/vmware-tanzu/vm-operator/api/v1alpha5"
2929 cnstypes "github.com/vmware/govmomi/cns/types"
30+ vsanfstypes "github.com/vmware/govmomi/vsan/vsanfs/types"
3031 v1 "k8s.io/api/core/v1"
3132 apierrors "k8s.io/apimachinery/pkg/api/errors"
3233 "k8s.io/apimachinery/pkg/runtime"
@@ -39,13 +40,10 @@ import (
3940 "sigs.k8s.io/controller-runtime/pkg/client/config"
4041 "sigs.k8s.io/controller-runtime/pkg/controller"
4142 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
42-
4343 "sigs.k8s.io/controller-runtime/pkg/handler"
4444 "sigs.k8s.io/controller-runtime/pkg/manager"
4545 "sigs.k8s.io/controller-runtime/pkg/reconcile"
4646 "sigs.k8s.io/controller-runtime/pkg/source"
47-
48- vsanfstypes "github.com/vmware/govmomi/vsan/vsanfs/types"
4947 cnsoperatorapis "sigs.k8s.io/vsphere-csi-driver/v3/pkg/apis/cnsoperator"
5048 cnsfileaccessconfigv1alpha1 "sigs.k8s.io/vsphere-csi-driver/v3/pkg/apis/cnsoperator/cnsfileaccessconfig/v1alpha1"
5149 volumes "sigs.k8s.io/vsphere-csi-driver/v3/pkg/common/cns-lib/volume"
@@ -57,13 +55,14 @@ import (
5755 k8s "sigs.k8s.io/vsphere-csi-driver/v3/pkg/kubernetes"
5856 "sigs.k8s.io/vsphere-csi-driver/v3/pkg/syncer"
5957 cnsoperatortypes "sigs.k8s.io/vsphere-csi-driver/v3/pkg/syncer/cnsoperator/types"
60- cnsoperatorutil "sigs.k8s.io/vsphere-csi-driver/v3/pkg/syncer/cnsoperator/util"
58+ "sigs.k8s.io/vsphere-csi-driver/v3/pkg/syncer/cnsoperator/util"
6159)
6260
6361const (
64- defaultMaxWorkerThreadsForFileAccessConfig = 10
65- capvVmLabelKey = "capv.vmware.com"
66- devopsUserLabelKey = "cns.vmware.com/user-created"
62+ workerThreadsEnvVar = "WORKER_THREADS_CNS_FILE_ACCESS_CONFIG"
63+ defaultMaxWorkerThreads = 10
64+ capvVmLabelKey = "capv.vmware.com"
65+ devopsUserLabelKey = "cns.vmware.com/user-created"
6766)
6867
6968// backOffDuration is a map of cnsfileaccessconfig name's to the time after
@@ -87,18 +86,16 @@ func Add(mgr manager.Manager, clusterFlavor cnstypes.CnsClusterFlavor,
8786 return nil
8887 }
8988
90- if clusterFlavor == cnstypes .CnsClusterFlavorWorkload {
91- if commonco .ContainerOrchestratorUtility .IsFSSEnabled (ctx , common .TKGsHA ) {
92- clusterComputeResourceMoIds , _ , err := common .GetClusterComputeResourceMoIds (ctx )
93- if err != nil {
94- log .Errorf ("failed to get clusterComputeResourceMoIds. err: %v" , err )
95- return err
96- }
97- if len (clusterComputeResourceMoIds ) > 1 &&
98- ! commonco .ContainerOrchestratorUtility .IsFSSEnabled (ctx , common .WorkloadDomainIsolation ) {
99- log .Infof ("Not initializing the CnsFileAccessConfig Controller as stretched supervisor is detected." )
100- return nil
101- }
89+ if commonco .ContainerOrchestratorUtility .IsFSSEnabled (ctx , common .TKGsHA ) {
90+ clusterComputeResourceMoIds , _ , err := common .GetClusterComputeResourceMoIds (ctx )
91+ if err != nil {
92+ log .Errorf ("failed to get clusterComputeResourceMoIds. err: %v" , err )
93+ return err
94+ }
95+ if len (clusterComputeResourceMoIds ) > 1 &&
96+ ! commonco .ContainerOrchestratorUtility .IsFSSEnabled (ctx , common .WorkloadDomainIsolation ) {
97+ log .Infof ("Not initializing the CnsFileAccessConfig Controller as stretched supervisor is detected." )
98+ return nil
10299 }
103100 }
104101 volumePermissionLockMap = & sync.Map {}
@@ -164,17 +161,23 @@ func Add(mgr manager.Manager, clusterFlavor cnstypes.CnsClusterFlavor,
164161func newReconciler (mgr manager.Manager , configInfo * commonconfig.ConfigurationInfo ,
165162 volumeManager volumes.Manager , vmOperatorClient client.Client , dynamicClient dynamic.Interface ,
166163 recorder record.EventRecorder ) reconcile.Reconciler {
167- return & ReconcileCnsFileAccessConfig {client : mgr .GetClient (), scheme : mgr .GetScheme (),
168- configInfo : configInfo , volumeManager : volumeManager , vmOperatorClient : vmOperatorClient ,
169- dynamicClient : dynamicClient , recorder : recorder }
164+ return & ReconcileCnsFileAccessConfig {
165+ client : mgr .GetClient (),
166+ scheme : mgr .GetScheme (),
167+ configInfo : configInfo ,
168+ volumeManager : volumeManager ,
169+ vmOperatorClient : vmOperatorClient ,
170+ dynamicClient : dynamicClient ,
171+ recorder : recorder ,
172+ }
170173}
171174
172175// add adds a new Controller to mgr with r as the reconcile.Reconciler.
173176func add (mgr manager.Manager , r reconcile.Reconciler ) error {
174177 ctx , log := logger .GetNewContextWithLogger ()
175178
176- maxWorkerThreads := getMaxWorkerThreadsToReconcileCnsFileAccessConfig (ctx )
177-
179+ maxWorkerThreads := util . GetMaxWorkerThreads (ctx ,
180+ workerThreadsEnvVar , defaultMaxWorkerThreads )
178181 // Create a new controller.
179182 c , err := controller .New ("cnsfileaccessconfig-controller" , mgr ,
180183 controller.Options {Reconciler : r , MaxConcurrentReconciles : maxWorkerThreads })
@@ -261,7 +264,7 @@ func (r *ReconcileCnsFileAccessConfig) Reconcile(ctx context.Context,
261264 instance .Name , instance .Spec .VMName )
262265 // Fetch the PVC and PV instance and get volume ID
263266 skipConfigureVolumeACL := false
264- volumeID , err := cnsoperatorutil .GetVolumeID (ctx , r .client , instance .Spec .PvcName , instance .Namespace )
267+ volumeID , err := util .GetVolumeID (ctx , r .client , instance .Spec .PvcName , instance .Namespace )
265268 if err != nil {
266269 if apierrors .IsNotFound (err ) {
267270 // If PVC instance is NotFound (deleted), then there is no need to configure ACL on file volume.
@@ -330,7 +333,7 @@ func (r *ReconcileCnsFileAccessConfig) Reconcile(ctx context.Context,
330333 if instance .DeletionTimestamp != nil {
331334 log .Infof ("CnsFileAccessConfig instance %q has deletion timestamp set" , instance .Name )
332335 volumeExists := true
333- volumeID , err := cnsoperatorutil .GetVolumeID (ctx , r .client , instance .Spec .PvcName , instance .Namespace )
336+ volumeID , err := util .GetVolumeID (ctx , r .client , instance .Spec .PvcName , instance .Namespace )
334337 if err != nil {
335338 if ifFileVolumesWithVmserviceVmsSupported &&
336339 apierrors .IsNotFound (err ) {
@@ -447,7 +450,7 @@ func (r *ReconcileCnsFileAccessConfig) Reconcile(ctx context.Context,
447450 log .Infof ("Reconciling CnsFileAccessConfig with instance: %q from namespace: %q. timeout %q seconds" ,
448451 instance .Name , instance .Namespace , timeout )
449452 if ! instance .Status .Done {
450- volumeID , err := cnsoperatorutil .GetVolumeID (ctx , r .client , instance .Spec .PvcName , instance .Namespace )
453+ volumeID , err := util .GetVolumeID (ctx , r .client , instance .Spec .PvcName , instance .Namespace )
451454 if err != nil {
452455 msg := fmt .Sprintf ("Failed to get volumeID from pvcName: %q. Error: %+v" , instance .Spec .PvcName , err )
453456 log .Error (msg )
@@ -780,7 +783,7 @@ func (r *ReconcileCnsFileAccessConfig) configureVolumeACLs(ctx context.Context,
780783func (r * ReconcileCnsFileAccessConfig ) getVMExternalIP (ctx context.Context ,
781784 vm * vmoperatortypes.VirtualMachine ) (string , error ) {
782785 log := logger .GetLogger (ctx )
783- networkProvider , err := cnsoperatorutil .GetNetworkProvider (ctx )
786+ networkProvider , err := util .GetNetworkProvider (ctx )
784787 if err != nil {
785788 return "" , logger .LogNewErrorf (log , "Failed to identify the network provider. Error: %+v" , err )
786789 }
@@ -789,11 +792,11 @@ func (r *ReconcileCnsFileAccessConfig) getVMExternalIP(ctx context.Context,
789792 return "" , logger .LogNewError (log , "unable to find network provider information" )
790793 }
791794
792- networkTypes := []string {cnsoperatorutil .NSXTNetworkProvider , cnsoperatorutil .
795+ networkTypes := []string {util .NSXTNetworkProvider , util .
793796 VDSNetworkProvider }
794797
795798 if commonco .ContainerOrchestratorUtility .IsFSSEnabled (ctx , common .VPCCapabilitySupervisor ) {
796- networkTypes = append (networkTypes , cnsoperatorutil .VPCNetworkProvider )
799+ networkTypes = append (networkTypes , util .VPCNetworkProvider )
797800 }
798801
799802 supported_found := false
@@ -808,7 +811,7 @@ func (r *ReconcileCnsFileAccessConfig) getVMExternalIP(ctx context.Context,
808811 return "" , logger .LogNewErrorf (log , "Unknown network provider. Error: %+v" , err )
809812 }
810813
811- tkgVMIP , err := cnsoperatorutil .GetTKGVMIP (ctx , r .vmOperatorClient ,
814+ tkgVMIP , err := util .GetTKGVMIP (ctx , r .vmOperatorClient ,
812815 r .dynamicClient , vm .Namespace , vm .Name , networkProvider )
813816 if err != nil {
814817 return "" , logger .LogNewErrorf (log , "Failed to get external facing IP address for VM %q/%q. Err: %+v" ,
0 commit comments