From d2be5b3117b0ec7dcd3ea4089b72f7e712687790 Mon Sep 17 00:00:00 2001 From: Denis Romanenko Date: Tue, 28 Nov 2023 09:48:32 +0300 Subject: [PATCH] calculate iops on disk create Signed-off-by: Denis Romanenko --- go.mod | 2 +- pkg/vcdcsiclient/disks.go | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index db70b3ac..7c46a4cc 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/stretchr/testify v1.7.0 github.com/thecodeteam/gofsutil v0.1.2 // indirect github.com/vmware/cloud-provider-for-cloud-director v0.0.0-20231106193352-8393493c09e0 - github.com/vmware/go-vcloud-director/v2 v2.14.0-rc.3 + github.com/vmware/go-vcloud-director/v2 v2.21.0 golang.org/x/oauth2 v0.7.0 // indirect golang.org/x/sys v0.13.0 google.golang.org/grpc v1.56.3 diff --git a/pkg/vcdcsiclient/disks.go b/pkg/vcdcsiclient/disks.go index ea50693c..15b1653f 100644 --- a/pkg/vcdcsiclient/disks.go +++ b/pkg/vcdcsiclient/disks.go @@ -9,17 +9,19 @@ import ( "context" "encoding/json" "fmt" - "github.com/vmware/cloud-director-named-disk-csi-driver/pkg/util" - "github.com/vmware/cloud-director-named-disk-csi-driver/pkg/vcdtypes" - "github.com/vmware/cloud-director-named-disk-csi-driver/version" + "net/http" + "strings" + "time" + "github.com/vmware/cloud-provider-for-cloud-director/pkg/vcdsdk" swaggerClient "github.com/vmware/cloud-provider-for-cloud-director/pkg/vcdswaggerclient_36_0" "github.com/vmware/go-vcloud-director/v2/govcd" "github.com/vmware/go-vcloud-director/v2/types/v56" "k8s.io/klog" - "net/http" - "strings" - "time" + + "github.com/vmware/cloud-director-named-disk-csi-driver/pkg/util" + "github.com/vmware/cloud-director-named-disk-csi-driver/pkg/vcdtypes" + "github.com/vmware/cloud-director-named-disk-csi-driver/version" ) type DiskManager struct { @@ -161,6 +163,23 @@ func (diskManager *DiskManager) CreateDisk(diskName string, sizeMB int64, busTyp diskParams.Disk.StorageProfile = &types.Reference{ HREF: storageReference.HREF, } + + storageProfileData, err := diskManager.VCDClient.VCDClient.GetStorageProfileByHref(storageReference.HREF) + if err != nil { + return nil, fmt.Errorf("unable to get storage profile [%s] for disk [%s] by HREF [%s]", + storageProfile, diskName, storageReference.HREF) + } + + if storageProfileData.IopsSettings != nil { + if storageProfileData.IopsSettings.Enabled { + // If storageProfile Max IOPS per Gb is set + iops := storageProfileData.IopsSettings.DiskIopsPerGbMax * d.SizeMb / 1024 + if iops == 0 { + iops = storageProfileData.IopsSettings.DiskIopsMax + } + d.Iops = iops + } + } } task, err := diskManager.createDisk(diskParams)