Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCT feature related changes #157

Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
11 changes: 11 additions & 0 deletions helm/csi-unity/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
23 changes: 23 additions & 0 deletions helm/csi-unity/templates/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions helm/csi-unity/templates/csidriver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions helm/csi-unity/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 38 additions & 1 deletion service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading