From b8169b5b86802d1caae8986a00f4cb02f7f35aed Mon Sep 17 00:00:00 2001 From: Indukuri Date: Thu, 20 Jul 2023 15:36:03 +0530 Subject: [PATCH] SCT feature related changes --- go.mod | 2 +- go.sum | 4 +++ helm/csi-unity/templates/_helpers.tpl | 11 +++++++ helm/csi-unity/templates/controller.yaml | 23 ++++++++++++++ helm/csi-unity/templates/csidriver.yaml | 1 + helm/csi-unity/values.yaml | 14 +++++++++ service/controller.go | 39 +++++++++++++++++++++++- 7 files changed, 92 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 69dc08b..7c8e051 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/dell/gocsi v1.7.0 github.com/dell/gofsutil v1.12.0 github.com/dell/goiscsi v1.7.0 - github.com/dell/gounity v1.14.1-0.20230630050209-170fa6aff515 + github.com/dell/gounity v1.14.1-0.20230719100046-57750a8fe30b github.com/fsnotify/fsnotify v1.4.9 github.com/golang/protobuf v1.5.3 github.com/kubernetes-csi/csi-lib-utils v0.7.0 diff --git a/go.sum b/go.sum index 2ddafce..b6c78d8 100644 --- a/go.sum +++ b/go.sum @@ -107,6 +107,10 @@ github.com/dell/gounity v1.14.1-0.20230519092830-2b5b5f2276eb h1:fBfl5w5HUEMqQDm github.com/dell/gounity v1.14.1-0.20230519092830-2b5b5f2276eb/go.mod h1:/HEDZZ+yKH/cWbEXvOrHqy+90eFuPZei+gUskZ9IvKk= github.com/dell/gounity v1.14.1-0.20230630050209-170fa6aff515 h1:vYUjVH0xrx3wEQZfO+XqRmwgSIpcOuXhhd4ZzE9A3kI= github.com/dell/gounity v1.14.1-0.20230630050209-170fa6aff515/go.mod h1:/HEDZZ+yKH/cWbEXvOrHqy+90eFuPZei+gUskZ9IvKk= +github.com/dell/gounity v1.14.1-0.20230718115612-fe77c112bba1 h1:KB1aIvUmbPrpl0ryLZrmqM6Oj0ZcwjyWXwfpE0uIiow= +github.com/dell/gounity v1.14.1-0.20230718115612-fe77c112bba1/go.mod h1:/HEDZZ+yKH/cWbEXvOrHqy+90eFuPZei+gUskZ9IvKk= +github.com/dell/gounity v1.14.1-0.20230719100046-57750a8fe30b h1:phkzvXS/HTMr9irzEocCZGwa8afceiCldMaHHBAQe3Q= +github.com/dell/gounity v1.14.1-0.20230719100046-57750a8fe30b/go.mod h1:/HEDZZ+yKH/cWbEXvOrHqy+90eFuPZei+gUskZ9IvKk= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= diff --git a/helm/csi-unity/templates/_helpers.tpl b/helm/csi-unity/templates/_helpers.tpl index e5bc013..d64acb2 100644 --- a/helm/csi-unity/templates/_helpers.tpl +++ b/helm/csi-unity/templates/_helpers.tpl @@ -48,3 +48,14 @@ Return the appropriate sidecar images based on k8s version {{- end -}} {{- end -}} {{- end -}} + +{{/* +Return true if storage capacity tracking is enabled and is supported based on k8s version +*/}} +{{- define "csi-unity.isStorageCapacitySupported" -}} +{{- if eq .Values.storageCapacity.enabled true -}} + {{- if and (eq .Capabilities.KubeVersion.Major "1") (ge (trimSuffix "+" .Capabilities.KubeVersion.Minor) "24") -}} + {{- true -}} + {{- end -}} +{{- end -}} +{{- end -}} diff --git a/helm/csi-unity/templates/controller.yaml b/helm/csi-unity/templates/controller.yaml index 2cf8172..2b12607 100644 --- a/helm/csi-unity/templates/controller.yaml +++ b/helm/csi-unity/templates/controller.yaml @@ -83,6 +83,18 @@ rules: - apiGroups: [""] resources: ["persistentvolumeclaims/status"] verbs: ["update", "patch"] + # Permissions for CSIStorageCapacity + {{- if eq (include "csi-unity.isStorageCapacitySupported" .) "true" }} + - apiGroups: ["storage.k8s.io"] + resources: ["csistoragecapacities"] + verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] + - apiGroups: [""] + resources: ["pods"] + verbs: ["get"] + - apiGroups: ["apps"] + resources: ["replicasets"] + verbs: ["get"] + {{- end }} --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 @@ -188,9 +200,20 @@ spec: - "--leader-election" - "--leader-election-namespace={{ .Release.Namespace }}" - "--default-fstype={{ .Values.defaultFsType | default "ext4" }}" + - "--enable-capacity={{ (include "csi-unity.isStorageCapacitySupported" .) | default false }}" + - "--capacity-ownerref-level=2" + - "--capacity-poll-interval={{ .Values.storageCapacity.pollInterval | default "5m" }}" env: - name: ADDRESS value: /var/run/csi/csi.sock + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name volumeMounts: - name: socket-dir mountPath: /var/run/csi diff --git a/helm/csi-unity/templates/csidriver.yaml b/helm/csi-unity/templates/csidriver.yaml index 8903b02..f9d5723 100644 --- a/helm/csi-unity/templates/csidriver.yaml +++ b/helm/csi-unity/templates/csidriver.yaml @@ -3,6 +3,7 @@ kind: CSIDriver metadata: name: csi-unity.dellemc.com spec: + storageCapacity: {{ (include "csi-unity.isStorageCapacitySupported" .) | default false }} attachRequired: true podInfoOnMount: true volumeLifecycleModes: diff --git a/helm/csi-unity/values.yaml b/helm/csi-unity/values.yaml index 4d6148e..04e2eef 100644 --- a/helm/csi-unity/values.yaml +++ b/helm/csi-unity/values.yaml @@ -242,6 +242,20 @@ maxUnityVolumesPerNode: 0 # Examples : "tenant2" , "tenant3" tenantName: "" +# Storage Capacity Tracking +# Note: Capacity tracking is supported in kubernetes v1.24 and above, this feature will be automatically disabled in older versions. +storageCapacity: + # enabled : Enable/Disable storage capacity tracking + # Allowed values: + # true: enable storage capacity tracking + # false: disable storage capacity tracking + # Default value: true + enabled: true + # pollInterval : Configure how often external-provisioner polls the driver to detect changed capacity + # Allowed values: 1m,2m,3m,...,10m,...,60m etc + # Default value: 5m + pollInterval: 5m + images: # "driver" defines the container image, used for the driver container. driverRepository: dellemc diff --git a/service/controller.go b/service/controller.go index 13ac917..760d14a 100644 --- a/service/controller.go +++ b/service/controller.go @@ -497,7 +497,44 @@ func (s *service) GetCapacity( ctx context.Context, req *csi.GetCapacityRequest) ( *csi.GetCapacityResponse, error) { - return nil, status.Error(codes.Unimplemented, "Not implemented") + + ctx, log, rid := GetRunidLog(ctx) + log.Debugf("Executing GetCapacity with args: %+v", *req) + + params := req.GetParameters() + + // Get arrayId from params + arrayID := strings.ToLower(strings.TrimSpace(params[keyArrayID])) + + if arrayID == "" { + return nil, status.Error(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "ArrayId cannot be empty")) + } + ctx, log = setArrayIDContext(ctx, arrayID) + + if err := s.requireProbe(ctx, arrayID); err != nil { + return nil, err + } + + unity, err := s.getUnityClient(ctx, arrayID) + + if err != nil { + return nil, err + } + + metricsAPI := gounity.NewMetrics(unity) + + resp, 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) + + return &csi.GetCapacityResponse{ + AvailableCapacity: int64(resp.Entries[0].Content.SizeFree), + }, nil + } func (s *service) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {