Skip to content

Commit 5197468

Browse files
committed
feat: support storage class
1 parent a04e886 commit 5197468

File tree

8 files changed

+184
-8
lines changed

8 files changed

+184
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ smb-windows:
100100

101101
.PHONY: container
102102
container: smb
103-
docker build --no-cache -t $(IMAGE_TAG) -f ./pkg/smbplugin/Dockerfile .
103+
docker build --no-cache -t $(IMAGE_TAG) -f ./pkg/smbplugin/dev.Dockerfile .
104104

105105
.PHONY: smb-container
106106
smb-container:

deploy/csi-smb-controller.yaml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
kind: Deployment
3+
apiVersion: apps/v1
4+
metadata:
5+
name: csi-smb-controller
6+
namespace: kube-system
7+
spec:
8+
replicas: 2
9+
selector:
10+
matchLabels:
11+
app: csi-smb-controller
12+
template:
13+
metadata:
14+
labels:
15+
app: csi-smb-controller
16+
spec:
17+
serviceAccountName: csi-smb-controller-sa
18+
nodeSelector:
19+
kubernetes.io/os: linux
20+
priorityClassName: system-cluster-critical
21+
tolerations:
22+
- key: "node-role.kubernetes.io/master"
23+
operator: "Equal"
24+
value: "true"
25+
effect: "NoSchedule"
26+
containers:
27+
- name: csi-provisioner
28+
image: mcr.microsoft.com/oss/kubernetes-csi/csi-provisioner:v1.4.0
29+
args:
30+
- "-v=5"
31+
- "--csi-address=$(ADDRESS)"
32+
- "--enable-leader-election"
33+
- "--leader-election-type=leases"
34+
env:
35+
- name: ADDRESS
36+
value: /csi/csi.sock
37+
volumeMounts:
38+
- mountPath: /csi
39+
name: socket-dir
40+
resources:
41+
limits:
42+
cpu: 1
43+
memory: 1Gi
44+
requests:
45+
cpu: 10m
46+
memory: 20Mi
47+
- name: liveness-probe
48+
image: mcr.microsoft.com/oss/kubernetes-csi/livenessprobe:v1.1.0
49+
args:
50+
- --csi-address=/csi/csi.sock
51+
- --connection-timeout=3s
52+
- --health-port=29632
53+
- --v=5
54+
volumeMounts:
55+
- name: socket-dir
56+
mountPath: /csi
57+
resources:
58+
limits:
59+
cpu: 1
60+
memory: 1Gi
61+
requests:
62+
cpu: 10m
63+
memory: 20Mi
64+
- name: smb
65+
image: mcr.microsoft.com/k8s/csi/smb-csi:latest
66+
args:
67+
- "--v=5"
68+
- "--endpoint=$(CSI_ENDPOINT)"
69+
ports:
70+
- containerPort: 29632
71+
name: healthz
72+
protocol: TCP
73+
- containerPort: 29634
74+
name: metrics
75+
protocol: TCP
76+
livenessProbe:
77+
failureThreshold: 5
78+
httpGet:
79+
path: /healthz
80+
port: healthz
81+
initialDelaySeconds: 30
82+
timeoutSeconds: 10
83+
periodSeconds: 30
84+
env:
85+
- name: CSI_ENDPOINT
86+
value: unix:///csi/csi.sock
87+
volumeMounts:
88+
- mountPath: /csi
89+
name: socket-dir
90+
resources:
91+
limits:
92+
cpu: 1
93+
memory: 1Gi
94+
requests:
95+
cpu: 10m
96+
memory: 20Mi
97+
volumes:
98+
- name: socket-dir
99+
emptyDir: {}

deploy/install-driver.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ if [ $ver != "master" ]; then
3434
fi
3535

3636
echo "Installing SMB CSI driver, version: $ver ..."
37+
kubectl apply -f $repo/rbac-csi-smb-controller.yaml
3738
kubectl apply -f $repo/csi-smb-driver.yaml
39+
kubectl apply -f $repo/csi-smb-controller.yaml
3840
kubectl apply -f $repo/csi-smb-node.yaml
3941
kubectl apply -f $repo/csi-smb-node-windows.yaml
4042
echo 'SMB CSI driver installed successfully.'
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: csi-smb-controller-sa
6+
namespace: kube-system
7+
8+
---
9+
10+
kind: ClusterRole
11+
apiVersion: rbac.authorization.k8s.io/v1
12+
metadata:
13+
name: smb-external-provisioner-role
14+
rules:
15+
- apiGroups: [""]
16+
resources: ["persistentvolumes"]
17+
verbs: ["get", "list", "watch", "create", "delete"]
18+
- apiGroups: [""]
19+
resources: ["persistentvolumeclaims"]
20+
verbs: ["get", "list", "watch", "update"]
21+
- apiGroups: ["storage.k8s.io"]
22+
resources: ["storageclasses"]
23+
verbs: ["get", "list", "watch"]
24+
- apiGroups: [""]
25+
resources: ["events"]
26+
verbs: ["get", "list", "watch", "create", "update", "patch"]
27+
- apiGroups: ["storage.k8s.io"]
28+
resources: ["csinodes"]
29+
verbs: ["get", "list", "watch"]
30+
- apiGroups: [""]
31+
resources: ["nodes"]
32+
verbs: ["get", "list", "watch"]
33+
- apiGroups: ["coordination.k8s.io"]
34+
resources: ["leases"]
35+
verbs: ["get", "list", "watch", "create", "update", "patch"]
36+
---
37+
38+
kind: ClusterRoleBinding
39+
apiVersion: rbac.authorization.k8s.io/v1
40+
metadata:
41+
name: smb-csi-provisioner-binding
42+
subjects:
43+
- kind: ServiceAccount
44+
name: csi-smb-controller-sa
45+
namespace: kube-system
46+
roleRef:
47+
kind: ClusterRole
48+
name: smb-external-provisioner-role
49+
apiGroup: rbac.authorization.k8s.io

deploy/uninstall-driver.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if [[ "$#" -gt 0 ]]; then
2121
ver="$1"
2222
fi
2323

24-
repo="https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/master/deploy"
24+
repo="https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/$ver/deploy"
2525
if [[ "$#" -gt 1 ]]; then
2626
if [[ "$2" == *"local"* ]]; then
2727
echo "use local deploy"
@@ -34,7 +34,9 @@ if [ $ver != "master" ]; then
3434
fi
3535

3636
echo "Uninstalling SMB CSI driver, version: $ver ..."
37-
kubectl delete -f $repo/csi-smb-driver.yaml --ignore-not-found
37+
kubectl delete -f $repo/csi-smb-controller.yaml --ignore-not-found
3838
kubectl delete -f $repo/csi-smb-node.yaml --ignore-not-found
3939
kubectl delete -f $repo/csi-smb-node-windows.yaml --ignore-not-found
40+
kubectl delete -f $repo/csi-smb-driver.yaml --ignore-not-found
41+
kubectl delete -f $repo/rbac-csi-smb-controller.yaml --ignore-not-found
4042
echo 'Uninstalled SMB CSI driver successfully.'

docs/driver-parameters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ This driver only supports static provisioning
66
77
Name | Meaning | Available Value | Mandatory | Default value
88
--- | --- | --- | --- | ---
9-
volumeAttributes.source | SMB server address | `//IP/smb-server/directory`(for azure file, format is `//accountname.file.core.windows.net/filesharename`) | Yes |
10-
nodeStageSecretRef.name | secret name that stores `username`, `password` | existing secret name | Yes |
9+
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 |
10+
nodeStageSecretRef.name | secret name that stores `username`, `password`(`domain` is optional) | existing secret name | Yes |
1111
nodeStageSecretRef.namespace | namespace where the secret is | k8s namespace | No | `default`

pkg/smb/controllerserver.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,25 @@ import (
2525
"k8s.io/klog/v2"
2626
)
2727

28-
// CreateVolume not implemented, only for sanity test pass
28+
// CreateVolume only supports static provisioning, no create volume action
2929
func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
30+
klog.V(2).Infof("CreateVolume called with request %+v", *req)
3031
volumeCapabilities := req.GetVolumeCapabilities()
3132
if len(volumeCapabilities) == 0 {
3233
return nil, status.Error(codes.InvalidArgument, "CreateVolume Volume capabilities must be provided")
3334
}
3435
return &csi.CreateVolumeResponse{
3536
Volume: &csi.Volume{
36-
VolumeId: "volumeID",
37+
VolumeId: req.GetName(),
3738
CapacityBytes: req.GetCapacityRange().GetRequiredBytes(),
39+
VolumeContext: req.GetParameters(),
3840
},
3941
}, nil
4042
}
4143

42-
// DeleteVolume not implemented, only for sanity test pass
44+
// DeleteVolume only supports static provisioning, no delete volume action
4345
func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
46+
klog.V(2).Infof("DeleteVolume called with request %v", *req)
4447
if len(req.GetVolumeId()) == 0 {
4548
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
4649
}

pkg/smbplugin/dev.Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2020 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM mcr.microsoft.com/aks/fundamental/base-ubuntu:v0.0.5
16+
RUN apt-get update && apt-get install -y ca-certificates cifs-utils util-linux e2fsprogs mount udev xfsprogs
17+
LABEL maintainers="andyzhangx"
18+
LABEL description="SMB CSI Driver"
19+
20+
COPY ./_output/smbplugin /smbplugin
21+
ENTRYPOINT ["/smbplugin"]

0 commit comments

Comments
 (0)