From 5197468bde1ff466f79bd89ece84f1fe4602638d Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Fri, 10 Jul 2020 13:05:22 +0000 Subject: [PATCH] feat: support storage class --- Makefile | 2 +- deploy/csi-smb-controller.yaml | 99 +++++++++++++++++++++++++++++ deploy/install-driver.sh | 2 + deploy/rbac-csi-smb-controller.yaml | 49 ++++++++++++++ deploy/uninstall-driver.sh | 6 +- docs/driver-parameters.md | 4 +- pkg/smb/controllerserver.go | 9 ++- pkg/smbplugin/dev.Dockerfile | 21 ++++++ 8 files changed, 184 insertions(+), 8 deletions(-) create mode 100644 deploy/csi-smb-controller.yaml create mode 100644 deploy/rbac-csi-smb-controller.yaml create mode 100644 pkg/smbplugin/dev.Dockerfile diff --git a/Makefile b/Makefile index 8544ee016..b81d7f006 100644 --- a/Makefile +++ b/Makefile @@ -100,7 +100,7 @@ smb-windows: .PHONY: container container: smb - docker build --no-cache -t $(IMAGE_TAG) -f ./pkg/smbplugin/Dockerfile . + docker build --no-cache -t $(IMAGE_TAG) -f ./pkg/smbplugin/dev.Dockerfile . .PHONY: smb-container smb-container: diff --git a/deploy/csi-smb-controller.yaml b/deploy/csi-smb-controller.yaml new file mode 100644 index 000000000..4a90cad52 --- /dev/null +++ b/deploy/csi-smb-controller.yaml @@ -0,0 +1,99 @@ +--- +kind: Deployment +apiVersion: apps/v1 +metadata: + name: csi-smb-controller + namespace: kube-system +spec: + replicas: 2 + selector: + matchLabels: + app: csi-smb-controller + template: + metadata: + labels: + app: csi-smb-controller + spec: + serviceAccountName: csi-smb-controller-sa + nodeSelector: + kubernetes.io/os: linux + priorityClassName: system-cluster-critical + tolerations: + - key: "node-role.kubernetes.io/master" + operator: "Equal" + value: "true" + effect: "NoSchedule" + containers: + - name: csi-provisioner + image: mcr.microsoft.com/oss/kubernetes-csi/csi-provisioner:v1.4.0 + args: + - "-v=5" + - "--csi-address=$(ADDRESS)" + - "--enable-leader-election" + - "--leader-election-type=leases" + env: + - name: ADDRESS + value: /csi/csi.sock + volumeMounts: + - mountPath: /csi + name: socket-dir + resources: + limits: + cpu: 1 + memory: 1Gi + requests: + cpu: 10m + memory: 20Mi + - name: liveness-probe + image: mcr.microsoft.com/oss/kubernetes-csi/livenessprobe:v1.1.0 + args: + - --csi-address=/csi/csi.sock + - --connection-timeout=3s + - --health-port=29632 + - --v=5 + volumeMounts: + - name: socket-dir + mountPath: /csi + resources: + limits: + cpu: 1 + memory: 1Gi + requests: + cpu: 10m + memory: 20Mi + - name: smb + image: mcr.microsoft.com/k8s/csi/smb-csi:latest + args: + - "--v=5" + - "--endpoint=$(CSI_ENDPOINT)" + ports: + - containerPort: 29632 + name: healthz + protocol: TCP + - containerPort: 29634 + name: metrics + protocol: TCP + livenessProbe: + failureThreshold: 5 + httpGet: + path: /healthz + port: healthz + initialDelaySeconds: 30 + timeoutSeconds: 10 + periodSeconds: 30 + env: + - name: CSI_ENDPOINT + value: unix:///csi/csi.sock + volumeMounts: + - mountPath: /csi + name: socket-dir + resources: + limits: + cpu: 1 + memory: 1Gi + requests: + cpu: 10m + memory: 20Mi + volumes: + - name: socket-dir + emptyDir: {} diff --git a/deploy/install-driver.sh b/deploy/install-driver.sh index b16bcf983..e5365f1c1 100755 --- a/deploy/install-driver.sh +++ b/deploy/install-driver.sh @@ -34,7 +34,9 @@ if [ $ver != "master" ]; then fi echo "Installing SMB CSI driver, version: $ver ..." +kubectl apply -f $repo/rbac-csi-smb-controller.yaml kubectl apply -f $repo/csi-smb-driver.yaml +kubectl apply -f $repo/csi-smb-controller.yaml kubectl apply -f $repo/csi-smb-node.yaml kubectl apply -f $repo/csi-smb-node-windows.yaml echo 'SMB CSI driver installed successfully.' diff --git a/deploy/rbac-csi-smb-controller.yaml b/deploy/rbac-csi-smb-controller.yaml new file mode 100644 index 000000000..26324c351 --- /dev/null +++ b/deploy/rbac-csi-smb-controller.yaml @@ -0,0 +1,49 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: csi-smb-controller-sa + namespace: kube-system + +--- + +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: smb-external-provisioner-role +rules: + - apiGroups: [""] + resources: ["persistentvolumes"] + verbs: ["get", "list", "watch", "create", "delete"] + - apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["get", "list", "watch", "update"] + - apiGroups: ["storage.k8s.io"] + resources: ["storageclasses"] + verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: ["events"] + verbs: ["get", "list", "watch", "create", "update", "patch"] + - apiGroups: ["storage.k8s.io"] + resources: ["csinodes"] + verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: ["nodes"] + verbs: ["get", "list", "watch"] + - apiGroups: ["coordination.k8s.io"] + resources: ["leases"] + verbs: ["get", "list", "watch", "create", "update", "patch"] +--- + +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: smb-csi-provisioner-binding +subjects: + - kind: ServiceAccount + name: csi-smb-controller-sa + namespace: kube-system +roleRef: + kind: ClusterRole + name: smb-external-provisioner-role + apiGroup: rbac.authorization.k8s.io diff --git a/deploy/uninstall-driver.sh b/deploy/uninstall-driver.sh index e20627d71..80e18cac2 100755 --- a/deploy/uninstall-driver.sh +++ b/deploy/uninstall-driver.sh @@ -21,7 +21,7 @@ if [[ "$#" -gt 0 ]]; then ver="$1" fi -repo="https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/master/deploy" +repo="https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/$ver/deploy" if [[ "$#" -gt 1 ]]; then if [[ "$2" == *"local"* ]]; then echo "use local deploy" @@ -34,7 +34,9 @@ if [ $ver != "master" ]; then fi echo "Uninstalling SMB CSI driver, version: $ver ..." -kubectl delete -f $repo/csi-smb-driver.yaml --ignore-not-found +kubectl delete -f $repo/csi-smb-controller.yaml --ignore-not-found kubectl delete -f $repo/csi-smb-node.yaml --ignore-not-found kubectl delete -f $repo/csi-smb-node-windows.yaml --ignore-not-found +kubectl delete -f $repo/csi-smb-driver.yaml --ignore-not-found +kubectl delete -f $repo/rbac-csi-smb-controller.yaml --ignore-not-found echo 'Uninstalled SMB CSI driver successfully.' diff --git a/docs/driver-parameters.md b/docs/driver-parameters.md index 5e2ad1cb6..6ed61ae5d 100644 --- a/docs/driver-parameters.md +++ b/docs/driver-parameters.md @@ -6,6 +6,6 @@ This driver only supports static provisioning Name | Meaning | Available Value | Mandatory | Default value --- | --- | --- | --- | --- -volumeAttributes.source | SMB server address | `//IP/smb-server/directory`(for azure file, format is `//accountname.file.core.windows.net/filesharename`) | Yes | -nodeStageSecretRef.name | secret name that stores `username`, `password` | existing secret name | Yes | +volumeAttributes.source | SMB server address | `//smb-server-address/sharename`(for [Azure File](https://docs.microsoft.com/en-us/azure/storage/files/storage-files-introduction), format is `//accountname.file.core.windows.net/filesharename`) | Yes | +nodeStageSecretRef.name | secret name that stores `username`, `password`(`domain` is optional) | existing secret name | Yes | nodeStageSecretRef.namespace | namespace where the secret is | k8s namespace | No | `default` diff --git a/pkg/smb/controllerserver.go b/pkg/smb/controllerserver.go index 767f54427..ac7ac8aee 100644 --- a/pkg/smb/controllerserver.go +++ b/pkg/smb/controllerserver.go @@ -25,22 +25,25 @@ import ( "k8s.io/klog/v2" ) -// CreateVolume not implemented, only for sanity test pass +// CreateVolume only supports static provisioning, no create volume action func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { + klog.V(2).Infof("CreateVolume called with request %+v", *req) volumeCapabilities := req.GetVolumeCapabilities() if len(volumeCapabilities) == 0 { return nil, status.Error(codes.InvalidArgument, "CreateVolume Volume capabilities must be provided") } return &csi.CreateVolumeResponse{ Volume: &csi.Volume{ - VolumeId: "volumeID", + VolumeId: req.GetName(), CapacityBytes: req.GetCapacityRange().GetRequiredBytes(), + VolumeContext: req.GetParameters(), }, }, nil } -// DeleteVolume not implemented, only for sanity test pass +// DeleteVolume only supports static provisioning, no delete volume action func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) { + klog.V(2).Infof("DeleteVolume called with request %v", *req) if len(req.GetVolumeId()) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request") } diff --git a/pkg/smbplugin/dev.Dockerfile b/pkg/smbplugin/dev.Dockerfile new file mode 100644 index 000000000..6978e0bb7 --- /dev/null +++ b/pkg/smbplugin/dev.Dockerfile @@ -0,0 +1,21 @@ +# Copyright 2020 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM mcr.microsoft.com/aks/fundamental/base-ubuntu:v0.0.5 +RUN apt-get update && apt-get install -y ca-certificates cifs-utils util-linux e2fsprogs mount udev xfsprogs +LABEL maintainers="andyzhangx" +LABEL description="SMB CSI Driver" + +COPY ./_output/smbplugin /smbplugin +ENTRYPOINT ["/smbplugin"]