Skip to content

Commit 5ce1a9f

Browse files
authored
Merge pull request #141 from Leaseweb/chart_refactor
Complete refactor of Helm chart
2 parents 461e295 + 6e7eda8 commit 5ce1a9f

23 files changed

+972
-514
lines changed

charts/cloudstack-csi/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apiVersion: v2
22
name: cloudstack-csi
3-
description: A Helm chart for Kubernetes
3+
description: A Helm chart for CloudStack CSI driver
44
type: application
5-
version: 1.2.0
5+
version: 2.0.0
66
appVersion: 0.6.0
77
sources:
88
- https://github.com/Leaseweb/cloudstack-csi-driver

charts/cloudstack-csi/templates/_helpers.tpl

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{/*
33
Expand the name of the chart.
44
*/}}
5-
{{- define "csi.name" -}}
5+
{{- define "cloudstack-csi-driver.name" -}}
66
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
77
{{- end -}}
88

@@ -11,7 +11,7 @@ Create a default fully qualified app name.
1111
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
1212
If release name contains chart name it will be used as a full name.
1313
*/}}
14-
{{- define "csi.fullname" -}}
14+
{{- define "cloudstack-csi-driver.fullname" -}}
1515
{{- if .Values.fullnameOverride -}}
1616
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
1717
{{- else -}}
@@ -27,73 +27,36 @@ If release name contains chart name it will be used as a full name.
2727
{{/*
2828
Create chart name and version as used by the chart label.
2929
*/}}
30-
{{- define "csi.chart" -}}
30+
{{- define "cloudstack-csi-driver.chart" -}}
3131
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
3232
{{- end -}}
3333

3434
{{/*
3535
Common labels
3636
*/}}
37-
{{- define "csi.labels" -}}
38-
app.kubernetes.io/name: {{ include "csi.name" . }}
39-
helm.sh/chart: {{ include "csi.chart" . }}
40-
app.kubernetes.io/instance: {{ .Release.Name }}
37+
{{- define "cloudstack-csi-driver.labels" -}}
38+
{{ include "cloudstack-csi-driver.selectorLabels" . }}
39+
helm.sh/chart: {{ include "cloudstack-csi-driver.chart" . }}
4140
{{- if .Chart.AppVersion }}
4241
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
4342
{{- end }}
43+
app.kubernetes.io/component: csi-driver
4444
app.kubernetes.io/managed-by: {{ .Release.Service }}
45-
{{- end -}}
46-
47-
48-
{{/*
49-
Create the name of the service account to use
50-
*/}}
51-
{{- define "csi.serviceAccountName" -}}
52-
{{- if .Values.serviceAccount.create -}}
53-
{{ default (include "csi.fullname" .) .Values.serviceAccount.name }}
54-
{{- else -}}
55-
{{ default "default" .Values.serviceAccount.name }}
56-
{{- end -}}
45+
{{- if .Values.customLabels }}
46+
{{ toYaml .Values.extraLabels }}
47+
{{- end }}
5748
{{- end -}}
5849

5950
{{/*
60-
Create unified labels for csi components
51+
Common selector labels
6152
*/}}
62-
{{- define "csi.common.matchLabels" -}}
63-
app: {{ template "csi.name" . }}
64-
release: {{ .Release.Name }}
65-
{{- end -}}
66-
67-
{{- define "csi.common.metaLabels" -}}
68-
chart: {{ template "csi.chart" . }}
69-
heritage: {{ .Release.Service }}
70-
{{- if .Values.extraLabels }}
71-
{{ toYaml .Values.extraLabels -}}
72-
{{- end }}
73-
{{- end -}}
74-
75-
{{- define "csi.controller.matchLabels" -}}
76-
component: controller
77-
{{ include "csi.common.matchLabels" . }}
78-
{{- end -}}
79-
80-
{{- define "csi.controller.labels" -}}
81-
{{ include "csi.controller.matchLabels" . }}
82-
{{ include "csi.common.metaLabels" . }}
83-
{{- end -}}
84-
85-
{{- define "csi.node.matchLabels" -}}
86-
component: node
87-
{{ include "csi.common.matchLabels" . }}
88-
{{- end -}}
89-
90-
{{- define "csi.node.labels" -}}
91-
{{ include "csi.node.matchLabels" . }}
92-
{{ include "csi.common.metaLabels" . }}
53+
{{- define "cloudstack-csi-driver.selectorLabels" -}}
54+
app.kubernetes.io/name: {{ include "cloudstack-csi-driver.name" . }}
55+
app.kubernetes.io/instance: {{ .Release.Name }}
9356
{{- end -}}
9457

9558
{{/*
96-
Create cloud-config makro.
59+
Create cloud-config macro.
9760
*/}}
9861
{{- define "cloudConfig" -}}
9962
[Global]

charts/cloudstack-csi/templates/csi-clusterrole.yaml

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{{ if .Values.controller.enabled }}
22
{{ if .Values.rbac.create }}
3-
# This YAML file contains Cluster Role objects,
4-
# which are necessary to run cloudstack-csi-controller
5-
{{ $enableLeaderElection := gt (int .Values.controller.replicaCount) 1 }}
63
---
74
# external Attacher
85
kind: ClusterRole
96
apiVersion: rbac.authorization.k8s.io/v1
107
metadata:
118
name: csi-attacher-role
9+
labels:
10+
{{- include "cloudstack-csi-driver.labels" . | nindent 4 }}
11+
{{- with .Values.commonAnnotations }}
1212
annotations:
13-
{{- with .Values.commonAnnotations }}
1413
{{- toYaml . | nindent 4 }}
15-
{{- end }}
14+
{{- end }}
1615
rules:
1716
- apiGroups: [""]
1817
resources: ["persistentvolumes"]
@@ -26,22 +25,18 @@ rules:
2625
- apiGroups: ["storage.k8s.io"]
2726
resources: ["volumeattachments/status"]
2827
verbs: ["patch"]
29-
{{- if $enableLeaderElection}}
30-
# leader election
31-
- apiGroups: [coordination.k8s.io]
32-
resources: [leases]
33-
verbs: ["get", "watch", "list", "delete", "update", "create"]
34-
{{- end}}
3528
---
3629
# external Provisioner
3730
kind: ClusterRole
3831
apiVersion: rbac.authorization.k8s.io/v1
3932
metadata:
4033
name: csi-provisioner-role
34+
labels:
35+
{{- include "cloudstack-csi-driver.labels" . | nindent 4 }}
36+
{{- with .Values.commonAnnotations }}
4137
annotations:
42-
{{- with .Values.commonAnnotations }}
4338
{{- toYaml . | nindent 4 }}
44-
{{- end }}
39+
{{- end }}
4540
rules:
4641
- apiGroups: [""]
4742
resources: ["persistentvolumes"]
@@ -70,18 +65,18 @@ rules:
7065
- apiGroups: ["storage.k8s.io"]
7166
resources: ["volumeattachments"]
7267
verbs: ["get", "list", "watch"]
73-
{{- if $enableLeaderElection}}
74-
# leader election
75-
- apiGroups: [coordination.k8s.io]
76-
resources: [leases]
77-
verbs: ["get", "watch", "list", "delete", "update", "create"]
78-
{{- end}}
7968
---
8069
# external Resizer
8170
kind: ClusterRole
8271
apiVersion: rbac.authorization.k8s.io/v1
8372
metadata:
8473
name: csi-resizer-role
74+
labels:
75+
{{- include "cloudstack-csi-driver.labels" . | nindent 4 }}
76+
{{- with .Values.commonAnnotations }}
77+
annotations:
78+
{{- toYaml . | nindent 4 }}
79+
{{- end }}
8580
rules:
8681
# The following rule should be uncommented for plugins that require secrets
8782
# for provisioning.
@@ -103,11 +98,5 @@ rules:
10398
- apiGroups: [""]
10499
resources: ["events"]
105100
verbs: ["list", "watch", "create", "update", "patch"]
106-
{{- if $enableLeaderElection}}
107-
# leader election
108-
- apiGroups: [coordination.k8s.io]
109-
resources: [leases]
110-
verbs: ["get", "watch", "list", "delete", "update", "create"]
111-
{{- end}}
112101
{{- end}}
113102
{{- end}}

charts/cloudstack-csi/templates/csi-clusterrolebinding.yaml renamed to charts/cloudstack-csi/templates/csi-controller-clusterrolebinding.yaml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{{ if .Values.controller.enabled }}
22
{{ if .Values.rbac.create }}
3-
# This YAML file contains Cluster Role Binding objects,
4-
# which are necessary to run cloudstack-csi-controller
53
---
64
kind: ClusterRoleBinding
75
apiVersion: rbac.authorization.k8s.io/v1
86
metadata:
97
name: csi-attacher-binding
8+
labels:
9+
{{- include "cloudstack-csi-driver.labels" . | nindent 4 }}
10+
{{- with .Values.commonAnnotations }}
1011
annotations:
11-
{{- with .Values.commonAnnotations }}
1212
{{- toYaml . | nindent 4 }}
13-
{{- end }}
13+
{{- end }}
1414
subjects:
1515
- kind: ServiceAccount
16-
name: {{ .Values.serviceAccount.name }}
16+
name: {{ .Values.controller.serviceAccount.name }}
1717
namespace: {{ .Release.Namespace }}
1818
roleRef:
1919
kind: ClusterRole
@@ -24,13 +24,15 @@ kind: ClusterRoleBinding
2424
apiVersion: rbac.authorization.k8s.io/v1
2525
metadata:
2626
name: csi-provisioner-binding
27+
labels:
28+
{{- include "cloudstack-csi-driver.labels" . | nindent 4 }}
29+
{{- with .Values.commonAnnotations }}
2730
annotations:
28-
{{- with .Values.commonAnnotations }}
2931
{{- toYaml . | nindent 4 }}
30-
{{- end }}
32+
{{- end }}
3133
subjects:
3234
- kind: ServiceAccount
33-
name: {{ .Values.serviceAccount.name }}
35+
name: {{ .Values.controller.serviceAccount.name }}
3436
namespace: {{ .Release.Namespace }}
3537
roleRef:
3638
kind: ClusterRole
@@ -41,13 +43,15 @@ kind: ClusterRoleBinding
4143
apiVersion: rbac.authorization.k8s.io/v1
4244
metadata:
4345
name: csi-resizer-binding
46+
labels:
47+
{{- include "cloudstack-csi-driver.labels" . | nindent 4 }}
48+
{{- with .Values.commonAnnotations }}
4449
annotations:
45-
{{- with .Values.commonAnnotations }}
4650
{{- toYaml . | nindent 4 }}
47-
{{- end }}
51+
{{- end }}
4852
subjects:
4953
- kind: ServiceAccount
50-
name: {{ .Values.serviceAccount.name }}
54+
name: {{ .Values.controller.serviceAccount.name }}
5155
namespace: {{ .Release.Namespace }}
5256
roleRef:
5357
kind: ClusterRole

0 commit comments

Comments
 (0)