Skip to content

Commit e86b310

Browse files
committed
feat: support windows host-process deployment
fix
1 parent 9c7e069 commit e86b310

16 files changed

+794
-6
lines changed

Makefile

+23
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,16 @@ e2e-test:
102102

103103
.PHONY: e2e-bootstrap
104104
e2e-bootstrap: install-helm
105+
ifdef WINDOWS_USE_HOST_PROCESS_CONTAINERS
106+
(docker pull $(IMAGE_TAG) && docker pull $(IMAGE_TAG)-windows-hp) || make container-all push-manifest
107+
else
105108
docker pull $(IMAGE_TAG) || make container-all push-manifest
109+
endif
106110
ifdef TEST_WINDOWS
107111
helm upgrade csi-driver-smb charts/$(VERSION)/csi-driver-smb --namespace kube-system --wait --timeout=15m -v=5 --debug --install \
108112
${E2E_HELM_OPTIONS} \
109113
--set windows.enabled=true \
114+
--set windows.useHostProcessContainers=${WINDOWS_USE_HOST_PROCESS_CONTAINERS} \
110115
--set linux.enabled=false \
111116
--set controller.replicas=1 \
112117
--set controller.logLevel=6 \
@@ -162,6 +167,24 @@ container-windows:
162167
-t $(IMAGE_TAG)-windows-$(OSVERSION)-$(ARCH) --build-arg OSVERSION=$(OSVERSION) \
163168
--provenance=false --sbom=false \
164169
--build-arg ARCH=$(ARCH) -f ./cmd/smbplugin/Dockerfile.Windows .
170+
# workaround: only build hostprocess image once
171+
ifdef WINDOWS_USE_HOST_PROCESS_CONTAINERS
172+
ifeq ($(OSVERSION),ltsc2022)
173+
$(MAKE) container-windows-hostprocess
174+
$(MAKE) container-windows-hostprocess-latest
175+
endif
176+
endif
177+
178+
# Set --provenance=false to not generate the provenance (which is what causes the multi-platform index to be generated, even for a single platform).
179+
.PHONY: container-windows-hostprocess
180+
container-windows-hostprocess:
181+
docker buildx build --pull --output=type=$(OUTPUT_TYPE) --platform="windows/$(ARCH)" --provenance=false --sbom=false \
182+
-t $(IMAGE_TAG)-windows-hp -f ./cmd/smbplugin/Dockerfile.WindowsHostProcess .
183+
184+
.PHONY: container-windows-hostprocess-latest
185+
container-windows-hostprocess-latest:
186+
docker buildx build --pull --output=type=$(OUTPUT_TYPE) --platform="windows/$(ARCH)" --provenance=false --sbom=false \
187+
-t $(IMAGE_TAG_LATEST)-windows-hp -f ./cmd/smbplugin/Dockerfile.WindowsHostProcess .
165188

166189
.PHONY: container-all
167190
container-all: smb-windows
369 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{{- if and .Values.windows.enabled .Values.windows.useHostProcessContainers }}
2+
kind: DaemonSet
3+
apiVersion: apps/v1
4+
metadata:
5+
name: {{ .Values.windows.dsName }}
6+
namespace: {{ .Release.Namespace }}
7+
{{ include "smb.labels" . | indent 2 }}
8+
spec:
9+
updateStrategy:
10+
rollingUpdate:
11+
maxUnavailable: {{ .Values.node.maxUnavailable }}
12+
type: RollingUpdate
13+
selector:
14+
matchLabels:
15+
app: {{ .Values.windows.dsName }}
16+
template:
17+
metadata:
18+
{{ include "smb.labels" . | indent 6 }}
19+
app: {{ .Values.windows.dsName }}
20+
spec:
21+
{{- with .Values.windows.tolerations }}
22+
tolerations:
23+
{{ toYaml . | indent 8 }}
24+
{{- end }}
25+
nodeSelector:
26+
kubernetes.io/os: windows
27+
{{- with .Values.node.nodeSelector }}
28+
{{ toYaml . | indent 8 }}
29+
{{- end }}
30+
{{- with .Values.node.affinity }}
31+
affinity:
32+
{{ toYaml . | indent 8 }}
33+
{{- end }}
34+
priorityClassName: {{ .Values.priorityClassName | quote }}
35+
{{- if .Values.securityContext }}
36+
securityContext: {{- toYaml .Values.securityContext | nindent 8 }}
37+
{{- end }}
38+
serviceAccountName: {{ .Values.serviceAccount.node }}
39+
{{- include "smb.pullSecrets" . | indent 6 }}
40+
securityContext:
41+
seccompProfile:
42+
type: RuntimeDefault
43+
windowsOptions:
44+
hostProcess: true
45+
runAsUserName: "NT AUTHORITY\\SYSTEM"
46+
hostNetwork: true
47+
initContainers:
48+
- name: init
49+
{{- if hasPrefix "/" .Values.image.smb.repository }}
50+
image: "{{ .Values.image.baseRepo }}{{ .Values.image.smb.repository }}:{{ .Values.image.smb.tag }}-windows-hp"
51+
{{- else }}
52+
image: "{{ .Values.image.smb.repository }}:{{ .Values.image.smb.tag }}-windows-hp"
53+
{{- end }}
54+
imagePullPolicy: {{ .Values.image.pullPolicy }}
55+
command:
56+
- "powershell.exe"
57+
- "-c"
58+
- "New-Item -ItemType Directory -Path C:\\var\\lib\\kubelet\\plugins\\{{ .Values.driver.name }}\\ -Force"
59+
securityContext:
60+
capabilities:
61+
drop:
62+
- ALL
63+
containers:
64+
- name: node-driver-registrar
65+
{{- if hasPrefix "/" .Values.image.nodeDriverRegistrar.repository }}
66+
image: "{{ .Values.image.baseRepo }}{{ .Values.image.nodeDriverRegistrar.repository }}:{{ .Values.image.nodeDriverRegistrar.tag }}"
67+
{{- else }}
68+
image: "{{ .Values.image.nodeDriverRegistrar.repository }}:{{ .Values.image.nodeDriverRegistrar.tag }}"
69+
{{- end }}
70+
command:
71+
- "csi-node-driver-registrar.exe"
72+
args:
73+
- "--csi-address=$(CSI_ENDPOINT)"
74+
- "--kubelet-registration-path=$(DRIVER_REG_SOCK_PATH)"
75+
- "--plugin-registration-path=$(PLUGIN_REG_DIR)"
76+
- "--v=2"
77+
env:
78+
- name: CSI_ENDPOINT
79+
value: unix://{{ .Values.windows.kubelet }}\plugins\{{ .Values.driver.name }}\csi.sock
80+
- name: DRIVER_REG_SOCK_PATH
81+
value: C:\\var\\lib\\kubelet\\plugins\\{{ .Values.driver.name }}\\csi.sock
82+
- name: PLUGIN_REG_DIR
83+
value: C:\\var\\lib\\kubelet\\plugins_registry\\
84+
- name: KUBE_NODE_NAME
85+
valueFrom:
86+
fieldRef:
87+
fieldPath: spec.nodeName
88+
imagePullPolicy: {{ .Values.image.nodeDriverRegistrar.pullPolicy }}
89+
resources: {{- toYaml .Values.windows.resources.nodeDriverRegistrar | nindent 12 }}
90+
securityContext:
91+
capabilities:
92+
drop:
93+
- ALL
94+
- name: smb
95+
{{- if hasPrefix "/" .Values.image.smb.repository }}
96+
image: "{{ .Values.image.baseRepo }}{{ .Values.image.smb.repository }}:{{ .Values.image.smb.tag }}"
97+
{{- else }}
98+
image: "{{ .Values.image.smb.repository }}:{{ .Values.image.smb.tag }}"
99+
{{- end }}
100+
imagePullPolicy: {{ .Values.image.smb.pullPolicy }}
101+
command:
102+
- "azurefileplugin.exe"
103+
args:
104+
- "--v={{ .Values.node.logLevel }}"
105+
- "--drivername={{ .Values.driver.name }}"
106+
- --endpoint=$(CSI_ENDPOINT)
107+
- --nodeid=$(KUBE_NODE_NAME)
108+
- "--enable-get-volume-stats={{ .Values.feature.enableGetVolumeStats }}"
109+
- "--remove-smb-mapping-during-unmount={{ .Values.windows.removeSMBMappingDuringUnmount }}"
110+
env:
111+
- name: CSI_ENDPOINT
112+
value: unix://{{ .Values.windows.kubelet }}\plugins\{{ .Values.driver.name }}\csi.sock
113+
- name: KUBE_NODE_NAME
114+
valueFrom:
115+
fieldRef:
116+
apiVersion: v1
117+
fieldPath: spec.nodeName
118+
imagePullPolicy: {{ .Values.image.pullPolicy }}
119+
resources: {{- toYaml .Values.windows.resources.smb | nindent 12 }}
120+
securityContext:
121+
capabilities:
122+
drop:
123+
- ALL
124+
{{- end -}}

charts/latest/csi-driver-smb/values.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ linux:
131131

132132
windows:
133133
enabled: false # Unless you already had csi proxy installed, windows.csiproxy.enabled=true is required
134+
useHostProcessContainers: false
134135
dsName: csi-smb-node-win # daemonset name
135136
kubelet: 'C:\var\lib\kubelet'
136137
removeSMBMappingDuringUnmount: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2022 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+
# these arguments come from BUILD_PLATFORMS used in release-tools
16+
FROM mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0
17+
LABEL description="CSI SMB plugin"
18+
19+
ARG ARCH=amd64
20+
ARG binary=./_output/${ARCH}/smbplugin.exe
21+
COPY ${binary} /smbplugin.exe
22+
ENV PATH="C:\Windows\system32;C:\Windows;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;"
23+
USER ContainerAdministrator
24+
ENTRYPOINT ["/smbplugin.exe"]

cmd/smbplugin/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var (
4949
krb5Prefix = flag.String("krb5-prefix", smb.DefaultKrb5CCName, "The prefix for kerberos cache")
5050
defaultOnDeletePolicy = flag.String("default-ondelete-policy", "", "default policy for deleting subdirectory when deleting a volume")
5151
removeArchivedVolumePath = flag.Bool("remove-archived-volume-path", true, "remove archived volume path in DeleteVolume")
52+
enableWindowsHostProcess = flag.Bool("enable-windows-host-process", false, "enable windows host process")
5253
)
5354

5455
// exit is a separate function to handle program termination
@@ -87,6 +88,7 @@ func handle() {
8788
Krb5CacheDirectory: *krb5CacheDirectory,
8889
Krb5Prefix: *krb5Prefix,
8990
DefaultOnDeletePolicy: *defaultOnDeletePolicy,
91+
EnableWindowsHostProcess: *enableWindowsHostProcess,
9092
}
9193
driver := smb.NewDriver(&driverOptions)
9294
driver.Run(*endpoint, *kubeconfig, false)

0 commit comments

Comments
 (0)