From 2007ba85cc80070097d26047570eaf87a191eb94 Mon Sep 17 00:00:00 2001 From: Malgorzata Dutka Date: Mon, 23 Oct 2023 08:45:07 -0400 Subject: [PATCH] add max volume size feature --- README.md | 2 +- service/controller.go | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8328e735..b3d254cf 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ ## Description CSI Driver for Unity XT is part of the [CSM (Container Storage Modules)](https://github.com/dell/csm) open-source suite of Kubernetes storage enablers for Dell products. CSI Driver for Unity XT is a Container Storage Interface (CSI) driver that provides support for provisioning persistent storage using Dell Unity XT storage array. -It supports CSI specification version 1.5. +It supports CSI specification version 1.6. This project may be compiled as a stand-alone binary using Golang that, when run, provides a valid CSI endpoint. It also can be used as a precompiled container image. diff --git a/service/controller.go b/service/controller.go index 760d14a9..a4582bd6 100644 --- a/service/controller.go +++ b/service/controller.go @@ -31,6 +31,7 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/wrapperspb" ) const ( @@ -523,20 +524,41 @@ func (s *service) GetCapacity( metricsAPI := gounity.NewMetrics(unity) - resp, err := metricsAPI.GetCapacity(ctx) + capacity, err := metricsAPI.GetCapacity(ctx) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } - log.Infof("Available capacity from the Array: %d", resp.Entries[0].Content.SizeFree) + log.Infof("Available capacity from the Array: %d", capacity.Entries[0].Content.SizeFree) + + maxVolSize := s.getMaximumVolumeSize(ctx, arrayID) + + if maxVolSize == 0 { + return &csi.GetCapacityResponse{ + AvailableCapacity: int64(capacity.Entries[0].Content.SizeFree), + }, nil + } return &csi.GetCapacityResponse{ - AvailableCapacity: int64(resp.Entries[0].Content.SizeFree), + AvailableCapacity: int64(capacity.Entries[0].Content.SizeFree), + MaximumVolumeSize: wrapperspb.Int64(maxVolSize), }, nil } +func (s *service) getMaximumVolumeSize(ctx context.Context, arrayID string) int64 { + ctx, log, _ := GetRunidLog(ctx) + unity, err := s.getUnityClient(ctx, arrayID) + volumeAPI := gounity.NewVolume(unity) + maxVolumeSize, err := volumeAPI.GetMaxVolumeSize(ctx, "Limit_MaxLUNSize") + if err != nil { + log.Debugf("GetMaxVolumeSize returning: %v for Array having GlobalId %s", err, arrayID) + return 0 + } + return maxVolumeSize +} + func (s *service) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) { ctx, log, rid := GetRunidLog(ctx) log.Debugf("Executing CreateSnapshot with args: %+v", *req)