Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ go 1.23.4
require (
github.com/blang/semver v3.5.1+incompatible
github.com/google/go-cmp v0.7.0
github.com/openshift/api v0.0.0-20250305122440-3e04d3af8c3e
github.com/openshift/api v0.0.0-20250327202946-4521905c611e
github.com/openshift/build-machinery-go v0.0.0-20250102153059-e85a1a7ecb5c
github.com/openshift/client-go v0.0.0-20250131180035-f7ec47e2d87a
github.com/openshift/client-go v0.0.0-20250330132942-bc2e3c2af6e1
github.com/openshift/library-go v0.0.0-20250325143551-78a24021cf40
github.com/prometheus/client_golang v1.21.1
github.com/spf13/cobra v1.9.1
github.com/vmware/govmomi v0.48.1
gopkg.in/gcfg.v1 v1.2.3
gopkg.in/ini.v1 v1.67.0
k8s.io/api v0.32.2
k8s.io/api v0.32.3
k8s.io/apiextensions-apiserver v0.32.2
k8s.io/apimachinery v0.32.2
k8s.io/apimachinery v0.32.3
k8s.io/client-go v0.32.2
k8s.io/cloud-provider-vsphere v1.32.2
k8s.io/component-base v0.32.2
Expand Down Expand Up @@ -93,14 +93,14 @@ require (
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.35.0 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/exp v0.0.0-20250228200357-dead58393ab7 // indirect
golang.org/x/net v0.36.0 // indirect
golang.org/x/net v0.37.0 // indirect
golang.org/x/oauth2 v0.28.0 // indirect
golang.org/x/sync v0.12.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/term v0.30.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/time v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20240725223205-93522f1f2a9f // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb // indirect
Expand Down
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM
github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/openshift/api v0.0.0-20250305122440-3e04d3af8c3e h1:bEcCutNr5RLU/DudWNs/nlOLBqMxrfsHtVuMttkxvWE=
github.com/openshift/api v0.0.0-20250305122440-3e04d3af8c3e/go.mod h1:yk60tHAmHhtVpJQo3TwVYq2zpuP70iJIFDCmeKMIzPw=
github.com/openshift/api v0.0.0-20250327202946-4521905c611e h1:RUKfJ9SPZF6NFoE2tVfymrCrztFG3sUTlz5YLGhFxN8=
github.com/openshift/api v0.0.0-20250327202946-4521905c611e/go.mod h1:yk60tHAmHhtVpJQo3TwVYq2zpuP70iJIFDCmeKMIzPw=
github.com/openshift/build-machinery-go v0.0.0-20250102153059-e85a1a7ecb5c h1:6XcszPFZpan4qll5XbdLll7n1So3IsPn28aw2j1obMo=
github.com/openshift/build-machinery-go v0.0.0-20250102153059-e85a1a7ecb5c/go.mod h1:8jcm8UPtg2mCAsxfqKil1xrmRMI3a+XU2TZ9fF8A7TE=
github.com/openshift/client-go v0.0.0-20250131180035-f7ec47e2d87a h1:duO3JMrUOqVx50QhzxvDeOYIwTNOB8/EEuRLPyvAMBg=
github.com/openshift/client-go v0.0.0-20250131180035-f7ec47e2d87a/go.mod h1:Qw3ThpzVZ0bfTILpBNYg4LGyjtNxfyCiGh/uDLOOTP8=
github.com/openshift/client-go v0.0.0-20250330132942-bc2e3c2af6e1 h1:9SaT0p5FsRDvz4STV1VnxMyfXXzAXv1PubZ0nczzDYk=
github.com/openshift/client-go v0.0.0-20250330132942-bc2e3c2af6e1/go.mod h1:6a0Hj32FrkokKMeTck1uStmNV0wHYv46dHWAWER5iis=
github.com/openshift/library-go v0.0.0-20250325143551-78a24021cf40 h1:he++2Lr5qeZqgczkEMmOXYpLlO30SXfnqXrDKpxfik8=
github.com/openshift/library-go v0.0.0-20250325143551-78a24021cf40/go.mod h1:GHwvopE5KXXCz4ULHp871sTPLLW+FB+hu/RIzlNwxx8=
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
Expand Down Expand Up @@ -248,8 +248,8 @@ go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
golang.org/x/exp v0.0.0-20250228200357-dead58393ab7 h1:aWwlzYV971S4BXRS9AmqwDLAD85ouC6X+pocatKY58c=
golang.org/x/exp v0.0.0-20250228200357-dead58393ab7/go.mod h1:BHOTPb3L19zxehTsLoJXVaTktb06DFgmdW6Wb9s8jqk=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
Expand All @@ -258,8 +258,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA=
golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I=
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc=
golang.org/x/oauth2 v0.28.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -276,12 +276,12 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down Expand Up @@ -324,12 +324,12 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.32.2 h1:bZrMLEkgizC24G9eViHGOPbW+aRo9duEISRIJKfdJuw=
k8s.io/api v0.32.2/go.mod h1:hKlhk4x1sJyYnHENsrdCWw31FEmCijNGPJO5WzHiJ6Y=
k8s.io/api v0.32.3 h1:Hw7KqxRusq+6QSplE3NYG4MBxZw1BZnq4aP4cJVINls=
k8s.io/api v0.32.3/go.mod h1:2wEDTXADtm/HA7CCMD8D8bK4yuBUptzaRhYcYEEYA3k=
k8s.io/apiextensions-apiserver v0.32.2 h1:2YMk285jWMk2188V2AERy5yDwBYrjgWYggscghPCvV4=
k8s.io/apiextensions-apiserver v0.32.2/go.mod h1:GPwf8sph7YlJT3H6aKUWtd0E+oyShk/YHWQHf/OOgCA=
k8s.io/apimachinery v0.32.2 h1:yoQBR9ZGkA6Rgmhbp/yuT9/g+4lxtsGYwW6dR6BDPLQ=
k8s.io/apimachinery v0.32.2/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
k8s.io/apimachinery v0.32.3 h1:JmDuDarhDmA/Li7j3aPrwhpNBA94Nvk5zLeOge9HH1U=
k8s.io/apimachinery v0.32.3/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
k8s.io/apiserver v0.32.2 h1:WzyxAu4mvLkQxwD9hGa4ZfExo3yZZaYzoYvvVDlM6vw=
k8s.io/apiserver v0.32.2/go.mod h1:PEwREHiHNU2oFdte7BjzA1ZyjWjuckORLIK/wLV5goM=
k8s.io/client-go v0.32.2 h1:4dYCD4Nz+9RApM2b/3BtVvBHw54QjMFUl1OLcJG5yOA=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ func getCheckAPIDependency(apiClients *utils.APIClient) checks.KubeAPIInterface
kubeInformers := apiClients.KubeInformers

csiDriverLister := kubeInformers.InformersFor("").Storage().V1().CSIDrivers().Lister()
clusterCSIDriverLister := apiClients.ClusterCSIDriverInformer.Lister()
csiNodeLister := kubeInformers.InformersFor("").Storage().V1().CSINodes().Lister()
nodeLister := apiClients.NodeInformer.Lister()
i := &checks.KubeAPIInterfaceImpl{
Infrastructure: testlib.GetInfraObject(),
CSINodeLister: csiNodeLister,
CSIDriverLister: csiDriverLister,
NodeLister: nodeLister,
Infrastructure: testlib.GetInfraObject(),
CSINodeLister: csiNodeLister,
CSIDriverLister: csiDriverLister,
ClusterCSIDriverLister: clusterCSIDriverLister,
NodeLister: nodeLister,
}

return i
Expand Down
11 changes: 11 additions & 0 deletions pkg/operator/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ func addOption(options map[string]string, name string, intValue *uint32) {
options[name] = strconv.FormatUint(uint64(*intValue), 10)
}

func GetMaxVolumesPerNode(clusterCSIDriver *opv1.ClusterCSIDriver) int {
maxVolumesPerNode := MaxVolumesPerNodeVSphere7

if clusterCSIDriver != nil && clusterCSIDriver.Spec.DriverConfig.VSphere != nil &&
clusterCSIDriver.Spec.DriverConfig.VSphere.MaxAllowedBlockVolumesPerNode > 0 {
maxVolumesPerNode = int(clusterCSIDriver.Spec.DriverConfig.VSphere.MaxAllowedBlockVolumesPerNode)
}

return maxVolumesPerNode
}

func GetSnapshotOptions(clusterCSIDriver *opv1.ClusterCSIDriver) map[string]string {
snapshotOptions := map[string]string{}
if clusterCSIDriver == nil || clusterCSIDriver.Spec.DriverConfig.VSphere == nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ const (
VSphereDriverName = "csi.vsphere.vmware.com"
DefaultNamespace = "openshift-cluster-csi-drivers"
InfraGlobalName = "cluster"
MaxVolumesPerNodeVSphere7 = 59
)
18 changes: 13 additions & 5 deletions pkg/operator/vspherecontroller/checks/api_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package checks

import (
ocpv1 "github.com/openshift/api/config/v1"
opv1 "github.com/openshift/api/operator/v1"
clustercsidriverlister "github.com/openshift/client-go/operator/listers/operator/v1"
v1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -14,17 +16,19 @@ type KubeAPIInterface interface {
// ListLinuxNodes returns list of all linux nodes in the cluster.
ListLinuxNodes() ([]*v1.Node, error)
GetCSIDriver(name string) (*storagev1.CSIDriver, error)
GetClusterCSIDriver(name string) (*opv1.ClusterCSIDriver, error)
ListCSINodes() ([]*storagev1.CSINode, error)
GetStorageClass(name string) (*storagev1.StorageClass, error)
GetInfrastructure() *ocpv1.Infrastructure
}

type KubeAPIInterfaceImpl struct {
Infrastructure *ocpv1.Infrastructure
NodeLister corelister.NodeLister
CSINodeLister storagelister.CSINodeLister
CSIDriverLister storagelister.CSIDriverLister
StorageClassLister storagelister.StorageClassLister
Infrastructure *ocpv1.Infrastructure
NodeLister corelister.NodeLister
CSINodeLister storagelister.CSINodeLister
CSIDriverLister storagelister.CSIDriverLister
ClusterCSIDriverLister clustercsidriverlister.ClusterCSIDriverLister
StorageClassLister storagelister.StorageClassLister
}

func getLinuxNodeSelector() labels.Selector {
Expand All @@ -45,6 +49,10 @@ func (k *KubeAPIInterfaceImpl) GetCSIDriver(name string) (*storagev1.CSIDriver,
return k.CSIDriverLister.Get(name)
}

func (k *KubeAPIInterfaceImpl) GetClusterCSIDriver(name string) (*opv1.ClusterCSIDriver, error) {
return k.ClusterCSIDriverLister.Get(name)
}

func (k *KubeAPIInterfaceImpl) ListCSINodes() ([]*storagev1.CSINode, error) {
return k.CSINodeLister.List(labels.Everything())
}
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/vspherecontroller/checks/check_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
CheckStatusDeprecatedESXIVersion CheckStatusType = "check_deprecated_esxi_version"
CheckStatusVcenterAPIError CheckStatusType = "vcenter_api_error"
CheckStatusGenericError CheckStatusType = "generic_error"
CheckStatusBlockVolumeLimitError CheckStatusType = "block_volume_limit_error"
)

type ClusterCheckStatus string
Expand Down
33 changes: 27 additions & 6 deletions pkg/operator/vspherecontroller/checks/check_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

"github.com/openshift/api/features"
"github.com/openshift/vmware-vsphere-csi-driver-operator/pkg/operator/utils"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
Expand All @@ -18,12 +19,13 @@ import (
)

const (
nodeCheckTimeout = 5 * time.Minute
hardwareVersionPrefix = "vmx-"
minHardwareVersion = 15
minRequiredHostVersion = "6.7.3"
minUpgradeableHostVersion = "7.0.2"
workerCount = 10
nodeCheckTimeout = 5 * time.Minute
hardwareVersionPrefix = "vmx-"
minHardwareVersion = 15
minRequiredHostVersion = "6.7.3"
minRequiredHostVersionForIncreasedVolLimit = "8.0.0"
minUpgradeableHostVersion = "7.0.2"
workerCount = 10
)

var (
Expand Down Expand Up @@ -169,6 +171,25 @@ func (n *NodeChecker) checkOnNode(workInfo nodeChannelWorkData) ClusterCheckResu
return MakeClusterUnupgradeableError(CheckStatusDeprecatedESXIVersion, reason)
}

// Check for maxAllowedBlockVolumesPerNode and degrade if host is not on minimal required ESXI version
if workInfo.checkOpts.featureGate.Enabled(features.FeatureGateVSphereConfigurableMaxAllowedBlockVolumesPerNode) {
clusterCSIDriver, err := workInfo.checkOpts.apiClient.GetClusterCSIDriver(utils.VSphereDriverName)
if err != nil {
klog.Errorf("failed to get ClusterCSIDriver: %s", err)
}
currentMaxVolumesPerNode := utils.GetMaxVolumesPerNode(clusterCSIDriver)
if currentMaxVolumesPerNode > utils.MaxVolumesPerNodeVSphere7 {
hasRequiredMinimumForVolumesPerNode, err := utils.IsMinimumVersion(minRequiredHostVersionForIncreasedVolLimit, hostAPIVersion)
if err != nil {
klog.Errorf("error parsing host version for node %s and host %s: %v", node.Name, hostName, err)
}
if !hasRequiredMinimumForVolumesPerNode {
reason := fmt.Errorf("host %s is on ESXI version %s, which is below minimum required version %s for maxAllowedBlockVolumesPerNode set in clusterCSIDriver", hostName, hostAPIVersion, minRequiredHostVersionForIncreasedVolLimit)
return MakeClusterDegradedError(CheckStatusBlockVolumeLimitError, reason)
}
}
}

return MakeClusterCheckResultPass()
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/vspherecontroller/checks/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
type CheckArgs struct {
vmConnection []*check.VSphereConnection
apiClient KubeAPIInterface
featureGate featuregates.FeatureGate
}

func NewCheckArgs(connection []*check.VSphereConnection, apiClient KubeAPIInterface, gates featuregates.FeatureGate) CheckArgs {
return CheckArgs{
vmConnection: connection,
apiClient: apiClient,
featureGate: gates,
}
}

Expand Down
49 changes: 49 additions & 0 deletions pkg/operator/vspherecontroller/driver_starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"context"
"crypto/sha256"
"fmt"
"github.com/openshift/api/features"
"os"
"strconv"

"github.com/openshift/library-go/pkg/operator/resource/resourcehash"
"github.com/openshift/vmware-vsphere-csi-driver-operator/pkg/operator/utils"

operatorapi "github.com/openshift/api/operator/v1"
"github.com/openshift/library-go/pkg/controller/factory"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
"github.com/openshift/library-go/pkg/operator/csi/csicontrollerset"
"github.com/openshift/library-go/pkg/operator/csi/csidrivercontrollerservicecontroller"
"github.com/openshift/library-go/pkg/operator/csi/csidrivernodeservicecontroller"
Expand All @@ -23,6 +26,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1informers "k8s.io/client-go/informers/core/v1"
"k8s.io/klog/v2"

operatorlistersv1 "github.com/openshift/client-go/operator/listers/operator/v1"
)

func (c *VSphereController) createCSIDriver() {
Expand Down Expand Up @@ -150,6 +155,7 @@ func (c *VSphereController) createCSIDriver() {
c.apiClients.ConfigMapInformer,
),
WithSecretDaemonSetAnnotationHook(driverConfigSecretName, defaultNamespace, c.apiClients.SecretInformer),
WithMaxVolumesPerNodeDaemonSetHook(c.apiClients.ClusterCSIDriverInformer.Lister(), c.featureGates),
).WithServiceMonitorController(
"VMWareVSphereDriverServiceMonitorController",
c.apiClients.DynamicClient,
Expand Down Expand Up @@ -324,3 +330,46 @@ func getOperatorSyncState(operatorClient v1helpers.OperatorClientWithFinalizers)
}
return opSpec.ManagementState
}

// WithMaxVolumesPerNodeDaemonSetHook sets the MAX_VOLUMES_PER_NODE environment variable in the DaemonSet container specifications.
func WithMaxVolumesPerNodeDaemonSetHook(clusterCSIDriverLister operatorlistersv1.ClusterCSIDriverLister, featureGate featuregates.FeatureGate) csidrivernodeservicecontroller.DaemonSetHookFunc {
return func(opSpec *operatorapi.OperatorSpec, ds *appsv1.DaemonSet) error {
if !featureGate.Enabled(features.FeatureGateVSphereConfigurableMaxAllowedBlockVolumesPerNode) {
return nil
}

// Get ClusterCSIDriver object
clusterCSIDriver, err := clusterCSIDriverLister.Get(utils.VSphereDriverName)
if err != nil {
return fmt.Errorf("failed to get ClusterCSIDriver: %v", err)
}

// Get the maximum volume limit
maxVolumesPerNode := utils.GetMaxVolumesPerNode(clusterCSIDriver)

// Set the environment variable in all containers
containers := ds.Spec.Template.Spec.Containers
for i := range containers {
container := &containers[i]

// Find and update existing MAX_VOLUMES_PER_NODE env var if it exists
envVarFound := false
for j := range container.Env {
if container.Env[j].Name == "MAX_VOLUMES_PER_NODE" {
container.Env[j].Value = strconv.FormatInt(int64(maxVolumesPerNode), 10)
envVarFound = true
break
}
}

// If not found, append it
if !envVarFound {
container.Env = append(container.Env, v1.EnvVar{
Name: "MAX_VOLUMES_PER_NODE",
Value: strconv.FormatInt(int64(maxVolumesPerNode), 10),
})
}
}
return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,16 @@ func TestEnvironmentCheck(t *testing.T) {
}
}
csiDriverLister := commonApiClient.KubeInformers.InformersFor("").Storage().V1().CSIDrivers().Lister()
clusterCSIDriverLister := commonApiClient.ClusterCSIDriverInformer.Lister()
csiNodeLister := commonApiClient.KubeInformers.InformersFor("").Storage().V1().CSINodes().Lister()
nodeLister := commonApiClient.NodeInformer.Lister()

checkerApiClient := &checks.KubeAPIInterfaceImpl{
Infrastructure: testlib.GetInfraObject(),
CSINodeLister: csiNodeLister,
CSIDriverLister: csiDriverLister,
NodeLister: nodeLister,
Infrastructure: testlib.GetInfraObject(),
CSINodeLister: csiNodeLister,
CSIDriverLister: csiDriverLister,
ClusterCSIDriverLister: clusterCSIDriverLister,
NodeLister: nodeLister,
}

fg := featuregates.NewFeatureGate([]v1.FeatureGateName{}, []v1.FeatureGateName{})
Expand Down
9 changes: 5 additions & 4 deletions pkg/operator/vspherecontroller/vspherecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,11 @@ func (c *VSphereController) runClusterCheck(ctx context.Context, infra *ocpv1.In

func (c *VSphereController) getCheckAPIDependency(infra *ocpv1.Infrastructure) checks.KubeAPIInterface {
checkerApiClient := &checks.KubeAPIInterfaceImpl{
Infrastructure: infra,
CSINodeLister: c.csiNodeLister,
CSIDriverLister: c.csiDriverLister,
NodeLister: c.nodeLister,
Infrastructure: infra,
CSINodeLister: c.csiNodeLister,
CSIDriverLister: c.csiDriverLister,
ClusterCSIDriverLister: c.clusterCSIDriverLister,
NodeLister: c.nodeLister,
}
return checkerApiClient
}
Expand Down
Loading