feat: support storage class

This commit is contained in:
andyzhangx 2020-07-10 13:05:22 +00:00
parent a04e8864bc
commit 5197468bde
8 changed files with 184 additions and 8 deletions

View File

@ -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:

View File

@ -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: {}

View File

@ -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.'

View File

@ -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

View File

@ -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.'

View File

@ -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`

View File

@ -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")
}

View File

@ -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"]