Skip to content

Commit

Permalink
feat: bring own serviceAccount in helm install
Browse files Browse the repository at this point in the history
fix test

fix test failure

fix external test
  • Loading branch information
andyzhangx committed Jul 10, 2021
1 parent ec146b5 commit 7797b88
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 54 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -30,6 +30,7 @@ IMAGE_TAG_LATEST = $(REGISTRY)/$(IMAGE_NAME):latest
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS ?= "-X ${PKG}/pkg/smb.driverVersion=${IMAGE_VERSION} -X ${PKG}/pkg/smb.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/smb.buildDate=${BUILD_DATE} -s -w -extldflags '-static'"
E2E_HELM_OPTIONS ?= --set image.smb.repository=$(REGISTRY)/$(IMAGE_NAME) --set image.smb.tag=$(IMAGE_VERSION)
E2E_HELM_OPTIONS += ${EXTRA_HELM_OPTIONS}
GINKGO_FLAGS = -ginkgo.v
GO111MODULE = on
GOPATH ?= $(shell go env GOPATH)
Expand Down
9 changes: 8 additions & 1 deletion charts/README.md
Expand Up @@ -46,14 +46,19 @@ The following table lists the configurable parameters of the latest SMB CSI Driv
| `imagePullSecrets` | Specify docker-registry secret names as an array | [] (does not add image pull secrets to deployed pods) |
| `serviceAccount.create` | whether create service account of csi-smb-controller | true |
| `rbac.create` | whether create rbac of csi-smb-controller | true |
| `rbac.name` | driver name in rbac role | true |
| `controller.name` | name of driver deployment | `csi-smb-controller`
| `controller.replicas` | the replicas of csi-smb-controller | 2 |
| `controller.metricsPort` | metrics port of csi-smb-controller |29644 |
| `controller.livenessProbe.healthPort ` | health check port for liveness probe | `29642` |
| `controller.logLevel` | controller driver log level |`5` |
| `node.metricsPort` | metrics port of csi-smb-node |29645
| `node.logLevel` | node driver log level |`5` |
| `linux.enabled` | whether enable linux feature | true |
| `linux.dsName` | name of driver daemonset on linux |`csi-smb-node` |
| `linux.kubelet` | configure kubelet directory path on Linux agent node node | `/var/lib/kubelet` |
| `windows.enabled` | whether enable windows feature | false |
| `windows.dsName` | name of driver daemonset on windows |`csi-smb-node-win` |
| `windows.kubelet` | configure kubelet directory path on Windows agent node | `'C:\var\lib\kubelet'` |
| `windows.image.livenessProbe.repository` | windows liveness-probe docker image | mcr.microsoft.com/oss/kubernetes-csi/livenessprobe |
| `windows.image.livenessProbe.tag` | windows liveness-probe docker image tag | v2.3.0 |
Expand All @@ -62,7 +67,7 @@ The following table lists the configurable parameters of the latest SMB CSI Driv
| `windows.image.nodeDriverRegistrar.tag` | windows csi-node-driver-registrar docker image tag | v2.2.0 |
| `windows.image.nodeDriverRegistrar.pullPolicy` | windows csi-node-driver-registrar image pull policy | IfNotPresent |
| `controller.runOnMaster` | run controller on master node | false |
| `node.livenessProbe.healthPort ` | the health check port for liveness probe | `29643` |
| `node.livenessProbe.healthPort ` | health check port for liveness probe | `29643` |
| `controller.resources.csiProvisioner.limits.cpu` | csi-provisioner cpu limits | 100m |
| `controller.resources.csiProvisioner.limits.memory` | csi-provisioner memory limits | 100Mi |
| `controller.resources.csiProvisioner.requests.cpu` | csi-provisioner cpu requests limits | 10m |
Expand All @@ -82,6 +87,8 @@ The following table lists the configurable parameters of the latest SMB CSI Driv
| `controller.affinity` | controller pod affinity | {} |
| `controller.nodeSelector` | controller pod node selector | {} |
| `controller.tolerations` | controller pod tolerations | [] |
| `node.metricsPort` | metrics port of csi-smb-node |`29645` |
| `node.livenessProbe.healthPort ` | health check port for liveness probe | `29643` |
| `node.resources.livenessProbe.limits.cpu` | liveness-probe cpu limits | 100m |
| `node.resources.livenessProbe.limits.memory` | liveness-probe memory limits | 100Mi |
| `node.resources.livenessProbe.requests.cpu` | liveness-probe cpu requests limits | 10m |
Expand Down
Binary file modified charts/latest/csi-driver-smb-v1.2.0.tgz
Binary file not shown.
12 changes: 6 additions & 6 deletions charts/latest/csi-driver-smb/templates/csi-smb-controller.yaml
Expand Up @@ -2,18 +2,18 @@
kind: Deployment
apiVersion: apps/v1
metadata:
name: csi-smb-controller
name: {{ .Values.controller.name }}
namespace: {{ .Release.Namespace }}
{{ include "smb.labels" . | indent 2 }}
spec:
replicas: {{ .Values.controller.replicas }}
selector:
matchLabels:
app: csi-smb-controller
app: {{ .Values.controller.name }}
template:
metadata:
{{ include "smb.labels" . | indent 6 }}
app: csi-smb-controller
app: {{ .Values.controller.name }}
{{- if .Values.podLabels }}
{{- toYaml .Values.podLabels | nindent 8 }}
{{- end }}
Expand All @@ -27,7 +27,7 @@ spec:
{{ toYaml . | indent 8 }}
{{- end }}
dnsPolicy: ClusterFirstWithHostNet
serviceAccountName: csi-smb-controller-sa
serviceAccountName: {{ .Values.serviceAccount.controller }}
nodeSelector:
{{- with .Values.controller.nodeSelector }}
{{ toYaml . | indent 8 }}
Expand Down Expand Up @@ -62,7 +62,7 @@ spec:
args:
- --csi-address=/csi/csi.sock
- --probe-timeout=3s
- --health-port=29642
- --health-port={{ .Values.controller.livenessProbe.healthPort }}
- --v=2
imagePullPolicy: {{ .Values.image.livenessProbe.pullPolicy }}
volumeMounts:
Expand All @@ -78,7 +78,7 @@ spec:
- "--metrics-address=0.0.0.0:{{ .Values.controller.metricsPort }}"
- "--drivername={{ .Values.driver.name }}"
ports:
- containerPort: 29642
- containerPort: {{ .Values.controller.livenessProbe.healthPort }}
name: healthz
protocol: TCP
- containerPort: {{ .Values.controller.metricsPort }}
Expand Down
10 changes: 5 additions & 5 deletions charts/latest/csi-driver-smb/templates/csi-smb-node-windows.yaml
Expand Up @@ -2,17 +2,17 @@
kind: DaemonSet
apiVersion: apps/v1
metadata:
name: csi-smb-node-win
name: {{ .Values.windows.dsName }}
namespace: {{ .Release.Namespace }}
{{ include "smb.labels" . | indent 2 }}
spec:
selector:
matchLabels:
app: csi-smb-node-win
app: {{ .Values.windows.dsName }}
template:
metadata:
{{ include "smb.labels" . | indent 6 }}
app: csi-smb-node-win
app: {{ .Values.windows.dsName }}
spec:
{{- with .Values.windows.tolerations }}
tolerations:
Expand All @@ -31,7 +31,7 @@ spec:
args:
- --csi-address=$(CSI_ENDPOINT)
- --probe-timeout=3s
- --health-port=29643
- --health-port={{ .Values.node.livenessProbe.healthPort }}
- --v=2
env:
- name: CSI_ENDPOINT
Expand Down Expand Up @@ -80,7 +80,7 @@ spec:
- --nodeid=$(KUBE_NODE_NAME)
- "--metrics-address=0.0.0.0:{{ .Values.node.metricsPort }}"
ports:
- containerPort: 29643
- containerPort: {{ .Values.node.livenessProbe.healthPort }}
name: healthz
protocol: TCP
livenessProbe:
Expand Down
8 changes: 4 additions & 4 deletions charts/latest/csi-driver-smb/templates/csi-smb-node.yaml
Expand Up @@ -2,17 +2,17 @@
kind: DaemonSet
apiVersion: apps/v1
metadata:
name: csi-smb-node
name: {{ .Values.linux.dsName }}
namespace: {{ .Release.Namespace }}
{{ include "smb.labels" . | indent 2 }}
spec:
selector:
matchLabels:
app: csi-smb-node
app: {{ .Values.linux.dsName }}
template:
metadata:
{{ include "smb.labels" . | indent 6 }}
app: csi-smb-node
app: {{ .Values.linux.dsName }}
{{- if .Values.podLabels }}
{{- toYaml .Values.podLabels | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -82,7 +82,7 @@ spec:
- "--nodeid=$(KUBE_NODE_NAME)"
- "--metrics-address=0.0.0.0:{{ .Values.node.metricsPort }}"
ports:
- containerPort: 29643
- containerPort: {{ .Values.node.livenessProbe.healthPort }}
name: healthz
protocol: TCP
livenessProbe:
Expand Down
Expand Up @@ -3,7 +3,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: csi-smb-controller-sa
name: {{ .Values.serviceAccount.controller }}
namespace: {{ .Release.Namespace }}
{{ include "smb.labels" . | indent 2 }}
---
Expand All @@ -13,7 +13,7 @@ metadata:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: smb-external-provisioner-role
name: {{ .Values.rbac.name }}-external-provisioner-role
{{ include "smb.labels" . | indent 2 }}
rules:
- apiGroups: [""]
Expand Down Expand Up @@ -45,14 +45,14 @@ rules:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: smb-csi-provisioner-binding
name: {{ .Values.rbac.name }}-csi-provisioner-binding
{{ include "smb.labels" . | indent 2 }}
subjects:
- kind: ServiceAccount
name: csi-smb-controller-sa
name: {{ .Values.serviceAccount.controller }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: smb-external-provisioner-role
name: {{ .Values.rbac.name }}-external-provisioner-role
apiGroup: rbac.authorization.k8s.io
{{- end -}}
15 changes: 10 additions & 5 deletions charts/latest/csi-driver-smb/values.yaml
Expand Up @@ -17,17 +17,22 @@ image:
pullPolicy: IfNotPresent

serviceAccount:
create: true
create: true # When true, service accounts will be created for you. Set to false if you want to use your own.
controller: csi-smb-controller-sa # Name of Service Account to be created or used

rbac:
create: true
name: smb

driver:
name: smb.csi.k8s.io

controller:
name: csi-smb-controller
replicas: 2
metricsPort: 29644
livenessProbe:
healthPort: 29642
runOnMaster: false
logLevel: 5
resources:
Expand Down Expand Up @@ -56,12 +61,10 @@ controller:
nodeSelector: {}
tolerations:
- key: "node-role.kubernetes.io/master"
operator: "Equal"
value: "true"
operator: "Exists"
effect: "NoSchedule"
- key: "node-role.kubernetes.io/controlplane"
operator: "Equal"
value: "true"
operator: "Exists"
effect: "NoSchedule"

node:
Expand Down Expand Up @@ -96,12 +99,14 @@ node:

linux:
enabled: true
dsName: csi-smb-node # daemonset name
kubelet: /var/lib/kubelet
tolerations:
- operator: "Exists"

windows:
enabled: false
dsName: csi-smb-node-win # daemonset name
kubelet: 'C:\var\lib\kubelet'
image:
livenessProbe:
Expand Down
6 changes: 2 additions & 4 deletions deploy/csi-smb-controller.yaml
Expand Up @@ -21,12 +21,10 @@ spec:
priorityClassName: system-cluster-critical
tolerations:
- key: "node-role.kubernetes.io/master"
operator: "Equal"
value: "true"
operator: "Exists"
effect: "NoSchedule"
- key: "node-role.kubernetes.io/controlplane"
operator: "Equal"
value: "true"
operator: "Exists"
effect: "NoSchedule"
containers:
- name: csi-provisioner
Expand Down
12 changes: 12 additions & 0 deletions deploy/example/deployment.yaml
@@ -1,4 +1,16 @@
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pvc-smb
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
storageClassName: smb
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
32 changes: 20 additions & 12 deletions hack/verify-examples.sh
Expand Up @@ -15,21 +15,29 @@

set -euo pipefail

rollout_and_wait() {
echo "Applying config \"$1\""
trap "echo \"Failed to apply config \\\"$1\\\"\" >&2" err

APPNAME=$(kubectl apply -f $1 | grep -E "^(:?daemonset|deployment|statefulset|pod)" | awk '{printf $1}')
if [[ -n $(expr "${APPNAME}" : "\(daemonset\|deployment\|statefulset\)" || true) ]]; then
kubectl rollout status $APPNAME --watch --timeout=5m
else
kubectl wait "${APPNAME}" --for condition=ready --timeout=5m
fi
}

echo "begin to create deployment examples ..."
kubectl apply -f deploy/example/storageclass-smb.yaml
kubectl apply -f deploy/example/pvc-smb.yaml
kubectl apply -f deploy/example/deployment.yaml
kubectl apply -f deploy/example/statefulset.yaml
kubectl apply -f deploy/example/statefulset-nonroot.yaml

echo "sleep 60s ..."
sleep 60

echo "begin to check pod status ..."
kubectl get pods -o wide
EXAMPLES=(\
deploy/example/deployment.yaml \
deploy/example/statefulset.yaml \
deploy/example/statefulset-nonroot.yaml \
)

kubectl get pods --field-selector status.phase=Running | grep deployment-smb
kubectl get pods --field-selector status.phase=Running | grep statefulset-smb-0
kubectl get pods --field-selector status.phase=Running | grep statefulset-smb-nonroot-0
for EXAMPLE in "${EXAMPLES[@]}"; do
rollout_and_wait $EXAMPLE
done

echo "deployment examples running completed."
13 changes: 9 additions & 4 deletions test/external-e2e/run.sh
Expand Up @@ -17,6 +17,7 @@
set -xe

PROJECT_ROOT=$(git rev-parse --show-toplevel)
DRIVER="test"

install_ginkgo () {
apt update -y
Expand All @@ -28,22 +29,26 @@ setup_e2e_binaries() {
curl -sL https://storage.googleapis.com/kubernetes-release/release/v1.21.0/kubernetes-test-linux-amd64.tar.gz --output e2e-tests.tar.gz
tar -xvf e2e-tests.tar.gz && rm e2e-tests.tar.gz

# install csi driver
mkdir -p /tmp/csi && cp deploy/example/storageclass-smb.yaml /tmp/csi/storageclass.yaml
# test on alternative driver name
export EXTRA_HELM_OPTIONS=" --set driver.name=$DRIVER.csi.k8s.io --set controller.name=csi-$DRIVER-controller --set linux.dsName=csi-$DRIVER-node --set windows.dsName=csi-$DRIVER-node-win"
sed -i "s/smb.csi.k8s.io/$DRIVER.csi.k8s.io/g" deploy/example/storageclass-smb.yaml
make e2e-bootstrap
make install-smb-provisioner
sed -i "s/csi-smb-controller/csi-$DRIVER-controller/g" deploy/example/metrics/csi-smb-controller-svc.yaml
make create-metrics-svc
}

print_logs() {
bash ./hack/verify-examples.sh
echo "print out driver logs ..."
bash ./test/utils/smb_log.sh
bash ./test/utils/smb_log.sh $DRIVER
}

install_ginkgo
setup_e2e_binaries
trap print_logs EXIT

mkdir -p /tmp/csi
cp deploy/example/storageclass-smb.yaml /tmp/csi/storageclass.yaml
ginkgo -p --progress --v -focus='External.Storage' \
-skip='\[Disruptive\]|\[Slow\]|unmount after the subpath directory is deleted|support two pods which share the same volume' kubernetes/test/bin/e2e.test -- \
-storage.testdriver=$PROJECT_ROOT/test/external-e2e/testdriver.yaml \
Expand Down
2 changes: 1 addition & 1 deletion test/external-e2e/testdriver.yaml
Expand Up @@ -5,7 +5,7 @@ ShortName: smb
StorageClass:
FromFile: /tmp/csi/storageclass.yaml
DriverInfo:
Name: smb.csi.k8s.io
Name: test.csi.k8s.io
Capabilities:
persistence: true
exec: true
Expand Down

0 comments on commit 7797b88

Please sign in to comment.