Skip to content

Commit c9d07e6

Browse files
committed
common: add build related works for webhook
Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
1 parent 8c3dea8 commit c9d07e6

File tree

11 files changed

+256
-13
lines changed

11 files changed

+256
-13
lines changed

.github/workflows/factory.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
repo: "rancher"
1313
provisionerImageName: "harvester-lvm-provisioner"
1414
pluginImageName: "harvester-lvm-csi-plugin"
15+
webhookImageName: "harvester-lvm-csi-driver-webhook"
1516

1617
jobs:
1718
dapper-build:
@@ -65,3 +66,13 @@ jobs:
6566
file: package/Dockerfile.provisioner
6667
push: ${{ inputs.push }}
6768
tags: ${{ env.repo }}/${{ env.provisionerImageName }}:${{ inputs.tag }}
69+
70+
- name: Docker Build (LVM Webhook)
71+
uses: docker/build-push-action@v5
72+
with:
73+
provenance: false
74+
context: .
75+
platforms: linux/amd64,linux/arm64
76+
file: package/Dockerfile.webhook
77+
push: ${{ inputs.push }}
78+
tags: ${{ env.repo }}/${{ env.webhookImageName }}:${{ inputs.tag }}

deploy/charts/templates/_helpers.tpl

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,83 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "harvester-csi-driver-lvm.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create chart name and version as used by the chart label.
10+
*/}}
11+
{{- define "harvester-csi-driver-lvm.chart" -}}
12+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
13+
{{- end }}
14+
15+
{{/*
16+
CSI-plugin labels
17+
*/}}
18+
{{- define "harvester-csi-driver-lvm.labels" -}}
19+
helm.sh/chart: {{ include "harvester-csi-driver-lvm.chart" . }}
20+
{{ include "harvester-csi-driver-lvm.selectorLabels" . }}
21+
{{- if .Chart.AppVersion }}
22+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
23+
{{- end }}
24+
app.kubernetes.io/managed-by: {{ .Release.Service }}
25+
app.kubernetes.io/component: storage
26+
{{- end }}
27+
28+
{{/*
29+
CSI-plugin Selector labels
30+
*/}}
31+
{{- define "harvester-csi-driver-lvm.selectorLabels" -}}
32+
app.kubernetes.io/name: {{ include "harvester-csi-driver-lvm.name" . }}
33+
app.kubernetes.io/instance: {{ .Release.Name }}
34+
{{- end }}
35+
36+
{{/*
37+
CSI-controller labels
38+
*/}}
39+
{{- define "harvester-csi-driver-lvm-controller.labels" -}}
40+
helm.sh/chart: {{ include "harvester-csi-driver-lvm.chart" . }}
41+
{{ include "harvester-csi-driver-lvm-controller.selectorLabels" . }}
42+
{{- if .Chart.AppVersion }}
43+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
44+
{{- end }}
45+
app.kubernetes.io/managed-by: {{ .Release.Service }}
46+
app.kubernetes.io/component: storage
47+
{{- end }}
48+
49+
{{/*
50+
CSI-controller Selector labels
51+
*/}}
52+
{{- define "harvester-csi-driver-lvm-controller.selectorLabels" -}}
53+
app.kubernetes.io/name: {{ include "harvester-csi-driver-lvm.name" . }}-controller
54+
app.kubernetes.io/instance: {{ .Release.Name }}
55+
{{- end }}
56+
57+
{{/*
58+
CSI-webhook labels
59+
*/}}
60+
{{- define "harvester-csi-driver-lvm-webhook.labels" -}}
61+
helm.sh/chart: {{ include "harvester-csi-driver-lvm.chart" . }}
62+
{{ include "harvester-csi-driver-lvm-webhook.selectorLabels" . }}
63+
{{- if .Chart.AppVersion }}
64+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
65+
{{- end }}
66+
app.kubernetes.io/managed-by: {{ .Release.Service }}
67+
app.kubernetes.io/component: webhook
68+
{{- end }}
69+
70+
{{/*
71+
CSI-webhook Selector labels
72+
*/}}
73+
{{- define "harvester-csi-driver-lvm-webhook.selectorLabels" -}}
74+
app.kubernetes.io/name: {{ include "harvester-csi-driver-lvm.name" . }}-webhook
75+
app.kubernetes.io/instance: {{ .Release.Name }}
76+
{{- end }}
77+
78+
{{/*
79+
CSI components
80+
*/}}
181
{{- define "externalImages.csiAttacher" -}}
282
{{- if .Values.customCSISidecars.enabled -}}
383
{{- print .Values.customCSISidecars.attacher -}}

deploy/charts/templates/controller.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,27 @@ apiVersion: apps/v1
44
metadata:
55
name: harvester-csi-driver-lvm-controller
66
labels:
7-
heritage: {{ .Release.Service }}
8-
release: {{ .Release.Name }}
7+
{{- include "harvester-csi-driver-lvm-controller.labels" . | nindent 4 }}
98
spec:
109
serviceName: harvester-csi-driver-lvm-controller
1110
replicas: 1
1211
selector:
1312
matchLabels:
14-
app: harvester-csi-driver-lvm-controller
13+
{{- include "harvester-csi-driver-lvm-controller.selectorLabels" . | nindent 6 }}
1514
template:
1615
metadata:
1716
labels:
18-
app: harvester-csi-driver-lvm-controller
17+
{{- include "harvester-csi-driver-lvm-controller.labels" . | nindent 8 }}
1918
spec:
2019
affinity:
2120
podAffinity:
2221
requiredDuringSchedulingIgnoredDuringExecution:
2322
- labelSelector:
2423
matchExpressions:
25-
- key: app
24+
- key: app.kubernetes.io/name
2625
operator: In
2726
values:
28-
- harvester-csi-driver-lvm-plugin
27+
- harvester-csi-driver-lvm
2928
topologyKey: kubernetes.io/hostname
3029
{{- if .Values.nodeSelector.provisioner }}
3130
nodeSelector:

deploy/charts/templates/csi.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ kind: DaemonSet
44
metadata:
55
name: harvester-csi-driver-lvm-plugin
66
labels:
7-
heritage: {{ .Release.Service }}
8-
release: {{ .Release.Name }}
7+
{{- include "harvester-csi-driver-lvm.labels" . | nindent 4 }}
98
spec:
109
revisionHistoryLimit: 10
1110
selector:
1211
matchLabels:
13-
app: harvester-csi-driver-lvm-plugin
12+
{{- include "harvester-csi-driver-lvm.selectorLabels" . | nindent 6 }}
1413
template:
1514
metadata:
1615
labels:
17-
app: harvester-csi-driver-lvm-plugin
16+
{{- include "harvester-csi-driver-lvm.labels" . | nindent 8 }}
1817
spec:
1918
serviceAccountName: harvester-csi-driver-lvm
2019
{{- if .Values.tolerations.plugin }}

deploy/charts/templates/rbac.yaml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,46 @@ roleRef:
4949
kind: ClusterRole
5050
name: harvester-csi-driver-lvm
5151
apiGroup: rbac.authorization.k8s.io
52-
---
52+
---
53+
apiVersion: v1
54+
kind: ServiceAccount
55+
metadata:
56+
name: harvester-csi-driver-lvm-webhook
57+
namespace: {{ .Release.Namespace }}
58+
---
59+
apiVersion: rbac.authorization.k8s.io/v1
60+
kind: ClusterRole
61+
metadata:
62+
name: harvester-csi-driver-lvm-webhook
63+
rules:
64+
- apiGroups: [ "" ]
65+
resources: [ "secrets", "configmaps" ]
66+
verbs: [ "*" ]
67+
- apiGroups: [ "" ]
68+
resources: [ "nodes" ]
69+
verbs: [ "get", "list" ]
70+
- apiGroups: [ "storage.k8s.io" ]
71+
resources: [ "storageclasses" ]
72+
verbs: [ "*" ]
73+
- apiGroups: [ "apiregistration.k8s.io" ]
74+
resources: [ "apiservices" ]
75+
verbs: [ "get", "watch", "list" ]
76+
- apiGroups: [ "apiextensions.k8s.io" ]
77+
resources: [ "customresourcedefinitions" ]
78+
verbs: [ "get", "watch", "list" ]
79+
- apiGroups: [ "admissionregistration.k8s.io" ]
80+
resources: [ "validatingwebhookconfigurations", "mutatingwebhookconfigurations" ]
81+
verbs: [ "*" ]
82+
---
83+
apiVersion: rbac.authorization.k8s.io/v1
84+
kind: ClusterRoleBinding
85+
metadata:
86+
name: harvester-csi-driver-lvm-webhook
87+
roleRef:
88+
apiGroup: rbac.authorization.k8s.io
89+
kind: ClusterRole
90+
name: harvester-csi-driver-lvm-webhook
91+
subjects:
92+
- kind: ServiceAccount
93+
name: harvester-csi-driver-lvm-webhook
94+
namespace: {{ .Release.Namespace }}

deploy/charts/templates/webhook.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
namespace: {{ .Release.Namespace }}
6+
labels:
7+
{{- include "harvester-csi-driver-lvm-webhook.labels" . | nindent 4 }}
8+
{{- if .Values.webhook.replicas }}
9+
# The annotation does not support 0 replicas.
10+
annotations:
11+
management.cattle.io/scale-available: "{{ .Values.webhook.replicas }}"
12+
{{- end }}
13+
name: harvester-csi-driver-lvm-webhook
14+
spec:
15+
{{- if not .Values.webhook.replicas }}
16+
# Use this field instead of the scale-available annotation when it is 0 replicas.
17+
replicas: {{ .Values.webhook.replicas }}
18+
{{- end }}
19+
selector:
20+
matchLabels:
21+
{{- include "harvester-csi-driver-lvm-webhook.selectorLabels" . | nindent 6 }}
22+
template:
23+
metadata:
24+
labels:
25+
{{- include "harvester-csi-driver-lvm-webhook.labels" . | nindent 8 }}
26+
spec:
27+
serviceAccountName: harvester-csi-driver-lvm-webhook
28+
{{- if .Values.tolerations.webhook }}
29+
tolerations:
30+
{{ toYaml .Values.tolerations.webhook | indent 8 }}
31+
{{- end }}
32+
containers:
33+
- name: harvester-csi-driver-lvm-webhook
34+
image: "{{ .Values.webhook.image.repository }}:{{ .Values.webhook.image.tag | default .Chart.AppVersion }}"
35+
imagePullPolicy: {{ .Values.webhook.image.pullPolicy }}
36+
env:
37+
- name: NAMESPACE
38+
valueFrom:
39+
fieldRef:
40+
fieldPath: metadata.namespace
41+
command:
42+
- csi-driver-lvm-webhook
43+
---
44+
apiVersion: v1
45+
kind: Service
46+
metadata:
47+
name: harvester-csi-driver-lvm-webhook
48+
namespace: {{ .Release.Namespace }}
49+
spec:
50+
type: ClusterIP
51+
selector:
52+
{{- include "harvester-csi-driver-lvm-webhook.selectorLabels" . | nindent 4 }}
53+
ports:
54+
- name: https
55+
port: 443
56+
protocol: TCP
57+
targetPort: {{ .Values.webhook.httpsPort }}

deploy/charts/values.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@ provisionerImage:
1414
# Overrides the image tag whose default is the chart appVersion.
1515
tag: "main-head"
1616

17+
nameOverride: ""
18+
1719
lvm:
1820
# You will want to change this for read-only filesystems
1921
# For example, in Talos OS, set this to "/var/etc/lvm"
2022
hostWritePath: /etc/lvm
2123

2224
driverName: lvm.driver.harvesterhci.io
2325

26+
webhook:
27+
replicas: 1
28+
image:
29+
repository: rancher/harvester-lvm-csi-driver-webhook
30+
pullPolicy: IfNotPresent
31+
# Overrides the image tag whose default is the chart appVersion.
32+
tag: "main-head"
33+
httpsPort: 8443
34+
2435
rbac:
2536
create: true
2637

@@ -86,4 +97,12 @@ tolerations:
8697
# effect: NoSchedule
8798
# - key: node-role.kubernetes.io/control-plane
8899
# operator: Exists
89-
# effect: NoSchedule
100+
# effect: NoSchedule
101+
webhook:
102+
# - key: node-role.kubernetes.io/master
103+
# operator: Exists
104+
# effect: NoSchedule
105+
# - key: node-role.kubernetes.io/control-plane
106+
# operator: Exists
107+
# effect: NoSchedule
108+

package/Dockerfile.webhook

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# syntax=docker/dockerfile:1.7.0
2+
3+
FROM registry.suse.com/bci/bci-base:15.6
4+
5+
RUN zypper -n rm container-suseconnect && \
6+
zypper -n install util-linux-systemd lvm2 e2fsprogs nvme-cli device-mapper xfsprogs && \
7+
zypper -n clean -a && rm -rf /tmp/* /var/tmp/* /usr/share/doc/packages/*
8+
9+
ARG TARGETPLATFORM
10+
11+
RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \
12+
echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \
13+
exit 1; \
14+
fi
15+
16+
ENV ARCH=${TARGETPLATFORM#linux/}
17+
18+
COPY bin/csi-driver-lvm-webhook-${ARCH} /usr/bin/csi-driver-lvm-webhook
19+
ENTRYPOINT ["csi-driver-lvm-webhook"]

scripts/build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ for arch in "amd64" "arm64"; do
2424
fi
2525
GOARCH="$arch" CGO_ENABLED=1 CC=$CC CGO_CFLAGS=$CGO_CFLAGS CGO_LDFLAGS=$CGO_LDFLAGS go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/lvmplugin-"$arch"
2626
GOARCH="$arch" CGO_ENABLED=1 CC=$CC CGO_CFLAGS=$CGO_CFLAGS CGO_LDFLAGS=$CGO_LDFLAGS go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/csi-lvmplugin-provisioner-"$arch" cmd/provisioner/*.go
27+
GOARCH="$arch" CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/csi-driver-lvm-webhook-"$arch" cmd/webhook/*.go
2728
done

scripts/package

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
set -e
33

44
./package_lvmplugin
5-
./package_lvm_provisioner
5+
./package_lvm_provisioner
6+
./package_lvm_webhook

scripts/package_lvm_webhook

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -e
3+
4+
source $(dirname $0)/version
5+
6+
cd $(dirname $0)/..
7+
8+
IMAGE=${REPO}/harvester-lvm-csi-driver-webhook:${TAG}
9+
DOCKERFILE=package/Dockerfile.webhook
10+
if [ -e ${DOCKERFILE}.${ARCH} ]; then
11+
DOCKERFILE=${DOCKERFILE}.${ARCH}
12+
fi
13+
14+
buildx build --load -f ${DOCKERFILE} -t ${IMAGE} .
15+
echo Built ${IMAGE}

0 commit comments

Comments
 (0)