Skip to content

Commit dd7c806

Browse files
authored
Merge pull request #3656 from chethanv28/topic/chethanv28/c-pick-from-c1e90f3-to-f3467b5
Cherry-pick commits from c1e90f3 to f3467b5
2 parents ca15528 + 29e6c6c commit dd7c806

37 files changed

+1366
-758
lines changed

manifests/supervisorcluster/1.29/cns-csi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ spec:
401401
- name: vsphere-csi-controller
402402
image: localhost:5000/vmware/vsphere-csi:<vsphere_csi_ver>
403403
args:
404-
- "--enable-profile-server=false"
404+
- "--enable-profile-server=true"
405405
ports:
406406
- containerPort: 2112
407407
name: prometheus
@@ -473,7 +473,7 @@ spec:
473473
- "--leader-election-retry-period=30s"
474474
- "--storagequota-sync-interval=10m"
475475
- "--webhook-client-cert-verification"
476-
- "--enable-profile-server=false"
476+
- "--enable-profile-server=true"
477477
env:
478478
- name: CLUSTER_FLAVOR
479479
value: "WORKLOAD"

manifests/supervisorcluster/1.30/cns-csi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ spec:
404404
- name: vsphere-csi-controller
405405
image: localhost:5000/vmware/vsphere-csi:<vsphere_csi_ver>
406406
args:
407-
- "--enable-profile-server=false"
407+
- "--enable-profile-server=true"
408408
ports:
409409
- containerPort: 2112
410410
name: prometheus
@@ -476,7 +476,7 @@ spec:
476476
- "--leader-election-retry-period=30s"
477477
- "--storagequota-sync-interval=10m"
478478
- "--webhook-client-cert-verification"
479-
- "--enable-profile-server=false"
479+
- "--enable-profile-server=true"
480480
env:
481481
- name: CLUSTER_FLAVOR
482482
value: "WORKLOAD"

manifests/supervisorcluster/1.31/cns-csi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ spec:
404404
- name: vsphere-csi-controller
405405
image: localhost:5000/vmware/vsphere-csi:<vsphere_csi_ver>
406406
args:
407-
- "--enable-profile-server=false"
407+
- "--enable-profile-server=true"
408408
ports:
409409
- containerPort: 2112
410410
name: prometheus
@@ -476,7 +476,7 @@ spec:
476476
- "--leader-election-retry-period=30s"
477477
- "--storagequota-sync-interval=10m"
478478
- "--webhook-client-cert-verification"
479-
- "--enable-profile-server=false"
479+
- "--enable-profile-server=true"
480480
env:
481481
- name: CLUSTER_FLAVOR
482482
value: "WORKLOAD"

manifests/supervisorcluster/1.32/cns-csi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ spec:
404404
- name: vsphere-csi-controller
405405
image: localhost:5000/vmware/vsphere-csi:<vsphere_csi_ver>
406406
args:
407-
- "--enable-profile-server=false"
407+
- "--enable-profile-server=true"
408408
ports:
409409
- containerPort: 2112
410410
name: prometheus
@@ -476,7 +476,7 @@ spec:
476476
- "--leader-election-retry-period=30s"
477477
- "--storagequota-sync-interval=10m"
478478
- "--webhook-client-cert-verification"
479-
- "--enable-profile-server=false"
479+
- "--enable-profile-server=true"
480480
env:
481481
- name: CLUSTER_FLAVOR
482482
value: "WORKLOAD"

pkg/csi/service/logger/logger.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"sync"
78

89
"github.com/google/uuid"
910
"go.uber.org/zap"
@@ -26,7 +27,11 @@ const (
2627
LogCtxIDKey = "TraceId"
2728
)
2829

29-
var defaultLogLevel LogLevel
30+
var (
31+
defaultLogLevel LogLevel
32+
logger *zap.Logger
33+
loggerMutex sync.Mutex
34+
)
3035

3136
// loggerKey holds the context key used for loggers.
3237
type loggerKey struct{}
@@ -76,9 +81,22 @@ func withFields(ctx context.Context, fields ...zapcore.Field) context.Context {
7681
return context.WithValue(ctx, loggerKey{}, getLogger(ctx).With(fields...))
7782
}
7883

79-
// newLogger creates and return a new logger depending logLevel set.
84+
// newLogger creates and returns a logger according to the logLevel set.
85+
// Uses singleton pattern to create only one instance of logger.
8086
func newLogger() *zap.Logger {
81-
var logger *zap.Logger
87+
if logger != nil {
88+
// logger is already initialized
89+
return logger
90+
}
91+
92+
loggerMutex.Lock()
93+
defer loggerMutex.Unlock()
94+
// this check ensures that multiple threads don't override the logger
95+
// created by the first thread acquiring the lock.
96+
if logger != nil {
97+
return logger
98+
}
99+
82100
if defaultLogLevel == DevelopmentLogLevel {
83101
logger, _ = zap.NewDevelopment()
84102
} else {
@@ -87,6 +105,7 @@ func newLogger() *zap.Logger {
87105
loggerConfig.EncoderConfig.EncodeTime = zapcore.RFC3339NanoTimeEncoder
88106
logger, _ = loggerConfig.Build()
89107
}
108+
90109
return logger
91110
}
92111

pkg/csi/service/vanilla/controller.go

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ func (c *controller) createBlockVolumeWithPlacementEngineForMultiVC(ctx context.
551551
// Check if requested volume size and source snapshot size matches.
552552
volumeSource := req.GetVolumeContentSource()
553553
var contentSourceSnapshotID, snapshotDatastoreURL string
554-
var vCenterWithTransactionSupport bool
555554
if volumeSource != nil {
556555
sourceSnapshot := volumeSource.GetSnapshot()
557556
if sourceSnapshot == nil {
@@ -582,13 +581,6 @@ func (c *controller) createBlockVolumeWithPlacementEngineForMultiVC(ctx context.
582581
"VC %q does not support snapshot operations", vCenterHost)
583582
}
584583

585-
vCenterWithTransactionSupport, err = c.managers.VcenterManager.IsCnsTransactionSupported(ctx, vCenterHost)
586-
if err != nil {
587-
return nil, csifault.CSIUnimplementedFault, logger.LogNewErrorCodef(log, codes.Internal,
588-
"failed to check if cns transaction APIs are supported on VC %q due to error: %v",
589-
vCenterHost, err)
590-
}
591-
592584
// Query capacity in MB and datastore url for block volume snapshot.
593585
volumeIds := []cnstypes.CnsVolumeId{{Id: cnsVolumeID}}
594586
cnsVolumeDetailsMap, err := utils.QueryVolumeDetailsUtil(ctx, volumeManager, volumeIds)
@@ -650,8 +642,6 @@ func (c *controller) createBlockVolumeWithPlacementEngineForMultiVC(ctx context.
650642
}
651643
break
652644
}
653-
654-
isTransactionAPIsSupported := vCenterWithTransactionSupport && isCSITransactionSupportEnabled
655645
volumeOperationDetails, err := operationStore.GetRequestDetails(ctx, req.Name)
656646
if err != nil {
657647
if apierrors.IsNotFound(err) {
@@ -661,7 +651,7 @@ func (c *controller) createBlockVolumeWithPlacementEngineForMultiVC(ctx context.
661651
"error occurred while getting CreateVolume task details for block volume %q. Error: %+v",
662652
req.Name, err)
663653
}
664-
} else if !isTransactionAPIsSupported && volumeOperationDetails.OperationDetails != nil {
654+
} else if !isCSITransactionSupportEnabled && volumeOperationDetails.OperationDetails != nil {
665655
if volumeOperationDetails.OperationDetails.TaskStatus ==
666656
cnsvolumeoperationrequest.TaskInvocationStatusSuccess &&
667657
volumeOperationDetails.VolumeID != "" {
@@ -689,7 +679,7 @@ func (c *controller) createBlockVolumeWithPlacementEngineForMultiVC(ctx context.
689679
},
690680
}
691681
volTaskAlreadyRegistered = true
692-
} else if !isTransactionAPIsSupported && cnsvolume.IsTaskPending(volumeOperationDetails) {
682+
} else if !isCSITransactionSupportEnabled && cnsvolume.IsTaskPending(volumeOperationDetails) {
693683
// If task is already created in CNS for this volume but task is in progress,
694684
// we need to monitor the task to check if volume creation is complete or not.
695685
log.Infof("Volume with name %s has CreateVolume task %s pending on VC %q.",
@@ -883,7 +873,7 @@ func (c *controller) createBlockVolumeWithPlacementEngineForMultiVC(ctx context.
883873
ClusterFlavor: cnstypes.CnsClusterFlavorVanilla,
884874
},
885875
common.CreateBlockVolumeOptions{
886-
IsCSITransactionSupportEnabled: isTransactionAPIsSupported,
876+
IsCSITransactionSupportEnabled: isCSITransactionSupportEnabled,
887877
})
888878
if err != nil {
889879
if cnsvolume.IsNotSupportedFaultType(ctx, faultType) {
@@ -968,7 +958,7 @@ func (c *controller) createBlockVolumeWithPlacementEngineForMultiVC(ctx context.
968958
ClusterFlavor: cnstypes.CnsClusterFlavorVanilla,
969959
},
970960
common.CreateBlockVolumeOptions{
971-
IsCSITransactionSupportEnabled: isTransactionAPIsSupported,
961+
IsCSITransactionSupportEnabled: isCSITransactionSupportEnabled,
972962
})
973963
if err != nil {
974964
if cnsvolume.IsNotSupportedFaultType(ctx, faultType) {
@@ -2570,15 +2560,9 @@ func (c *controller) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshot
25702560
// VolumeID and SnapshotID as the input, while corresponding snapshot APIs in upstream CSI require SnapshotID.
25712561
// So, we need to bridge the gap in vSphere CSI driver and return a combined SnapshotID to CSI Snapshotter.
25722562

2573-
vCenterWithTransactionSupport, err := vCenterManager.IsCnsTransactionSupported(ctx, vCenterHost)
2574-
if err != nil {
2575-
return nil, logger.LogNewErrorCodef(log, codes.Internal,
2576-
"failed to check if cns transaction APIs are supported on VC %q due to error: %v",
2577-
vCenterHost, err)
2578-
}
25792563
snapshotID, cnsSnapshotInfo, err := common.CreateSnapshotUtil(ctx, volumeManager,
25802564
volumeID, req.Name, &cnsvolume.CreateSnapshotExtraParams{
2581-
IsCSITransactionSupportEnabled: isCSITransactionSupportEnabled && vCenterWithTransactionSupport,
2565+
IsCSITransactionSupportEnabled: isCSITransactionSupportEnabled,
25822566
})
25832567
if err != nil {
25842568
return nil, logger.LogNewErrorCodef(log, codes.Internal,

pkg/csi/service/wcp/controller_helper_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ import (
1313
k8stesting "k8s.io/client-go/testing"
1414
"sigs.k8s.io/vsphere-csi-driver/v3/pkg/common/unittestcommon"
1515
"sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service/common/commonco"
16-
"sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service/logger"
1716
)
1817

1918
func TestGetPodVMUUID(t *testing.T) {
20-
logger.SetLoggerLevel(logger.DevelopmentLogLevel)
2119
containerOrchOriginal := commonco.ContainerOrchestratorUtility
2220
commonco.ContainerOrchestratorUtility = &unittestcommon.FakeK8SOrchestrator{}
2321
newK8sClientOriginal := newK8sClient

pkg/syncer/cnsoperator/controller/cnsfileaccessconfig/cnsfileaccessconfig_controller.go

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6361
const (
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,
164161
func 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.
173176
func 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,
780783
func (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

Comments
 (0)