Skip to content

Commit 26aa9d1

Browse files
authored
Merge pull request #47 from projectsyn/feat/use-helmchart
Use upstream csi-cloudscale Helm chart
2 parents 6682ca7 + 35ddf74 commit 26aa9d1

File tree

30 files changed

+1016
-350
lines changed

30 files changed

+1016
-350
lines changed

.cruft.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"name": "csi-cloudscale",
88
"slug": "csi-cloudscale",
99
"parameter_key": "csi_cloudscale",
10-
"test_cases": "defaults",
10+
"test_cases": "defaults openshift4",
1111
"add_lib": "n",
1212
"add_pp": "n",
1313
"add_golden": "y",
14-
"add_matrix": "n",
14+
"add_matrix": "y",
1515
"add_go_unit": "n",
1616
"copyright_holder": "VSHN AG <info@vshn.ch>",
1717
"copyright_year": "2021",

.github/workflows/test.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ jobs:
2929
args: 'check'
3030
test:
3131
runs-on: ubuntu-latest
32+
strategy:
33+
matrix:
34+
instance:
35+
- defaults
36+
- openshift4
3237
defaults:
3338
run:
3439
working-directory: ${{ env.COMPONENT_NAME }}
@@ -37,9 +42,14 @@ jobs:
3742
with:
3843
path: ${{ env.COMPONENT_NAME }}
3944
- name: Compile component
40-
run: make test
45+
run: make test -e instance=${{ matrix.instance }}
4146
golden:
4247
runs-on: ubuntu-latest
48+
strategy:
49+
matrix:
50+
instance:
51+
- defaults
52+
- openshift4
4353
defaults:
4454
run:
4555
working-directory: ${{ env.COMPONENT_NAME }}
@@ -48,4 +58,4 @@ jobs:
4858
with:
4959
path: ${{ env.COMPONENT_NAME }}
5060
- name: Golden diff
51-
run: make golden-diff
61+
run: make golden-diff -e instance=${{ matrix.instance }}

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ golden-diff: commodore_args += -f tests/$(instance).yml
7171
golden-diff: clean .compile ## Diff compile output against the reference version. Review output and run `make gen-golden golden-diff` if this target fails.
7272
@git diff --exit-code --minimal --no-index -- tests/golden/$(instance) compiled/
7373

74+
.PHONY: golden-diff-all
75+
golden-diff-all: recursive_target=golden-diff
76+
golden-diff-all: $(test_instances) ## Run golden-diff for all instances. Note: this doesn't work when running make with multiple parallel jobs (-j != 1).
77+
78+
.PHONY: gen-golden-all
79+
gen-golden-all: recursive_target=gen-golden
80+
gen-golden-all: $(test_instances) ## Run gen-golden for all instances. Note: this doesn't work when running make with multiple parallel jobs (-j != 1).
81+
82+
.PHONY: lint_kubent_all
83+
lint_kubent_all: recursive_target=lint_kubent
84+
lint_kubent_all: $(test_instances) ## Lint deprecated Kubernetes API versions for all golden test instances. Will exit on first error. Note: this doesn't work when running make with multiple parallel jobs (-j != 1).
85+
86+
.PHONY: $(test_instances)
87+
$(test_instances):
88+
$(MAKE) $(recursive_target) -e instance=$(basename $(@F))
89+
7490
.PHONY: clean
7591
clean: ## Clean the project
7692
rm -rf .cache compiled dependencies vendor helmcharts jsonnetfile*.json || true

Makefile.vars.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ KUBENT_IMAGE ?= ghcr.io/doitintl/kube-no-trouble:latest
5757
KUBENT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --entrypoint=/app/kubent $(KUBENT_IMAGE)
5858

5959
instance ?= defaults
60+
test_instances = tests/defaults.yml tests/openshift4.yml

class/csi-cloudscale.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
parameters:
22
kapitan:
33
dependencies:
4-
- type: https
5-
source: https://raw.githubusercontent.com/cloudscale-ch/csi-cloudscale/master/deploy/kubernetes/releases/csi-cloudscale-${csi_cloudscale:version}.yaml
6-
output_path: dependencies/csi-cloudscale/manifests/${csi_cloudscale:version}/deploy.yaml
4+
- type: helm
5+
source: ${csi_cloudscale:charts:csi-cloudscale:source}
6+
chart_name: csi-cloudscale
7+
output_path: ${_base_directory}/helmcharts/csi-cloudscale/${csi_cloudscale:charts:csi-cloudscale:version}
78
compile:
89
- input_paths:
9-
- csi-cloudscale/component/app.jsonnet
10+
- ${_base_directory}/component/app.jsonnet
1011
input_type: jsonnet
1112
output_path: apps/
1213
- input_paths:
13-
- csi-cloudscale/component/main.jsonnet
14+
- ${_base_directory}/helmcharts/csi-cloudscale/${csi_cloudscale:charts:csi-cloudscale:version}
15+
input_type: helm
16+
helm_values: ${csi_cloudscale:helm_values}
17+
helm_params:
18+
name: csi-cloudscale
19+
namespace: ${csi_cloudscale:namespace}
20+
output_path: csi-cloudscale/01_helm_chart
21+
- input_paths:
22+
- ${_base_directory}/component/main.jsonnet
1423
input_type: jsonnet
1524
output_path: csi-cloudscale/
25+
commodore:
26+
postprocess:
27+
filters:
28+
- type: jsonnet
29+
filter: postprocess/driver_daemonset_tolerations.jsonnet
30+
path: csi-cloudscale/01_helm_chart/csi-cloudscale/templates

class/defaults.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
parameters:
22
csi_cloudscale:
33
namespace: syn-csi-cloudscale
4-
version: v3.5.0
4+
5+
charts:
6+
csi-cloudscale:
7+
source: https://cloudscale-ch.github.io/csi-cloudscale
8+
version: 1.3.3
9+
10+
images:
11+
cloudscale-csi-plugin:
12+
registry: quay.io
13+
repository: cloudscalech/cloudscale-csi-plugin
14+
tag: v3.5.0
15+
516
api_token: ?{vaultkv:${cluster:tenant}/${cluster:name}/cloudscale/token}
17+
api_token_secret_name: cloudscale
618
fs_type: ext4
719
driver_daemonset_tolerations: {}
20+
821
resources:
922
controller:
1023
csi-provisioner:
@@ -32,3 +45,32 @@ parameters:
3245
requests:
3346
cpu: 20m
3447
memory: 32Mi
48+
49+
helm_values:
50+
# Set nameOverride to avoid resource names like
51+
# `csi-cloudscale-csi-cloudscale-controller-sa`.
52+
nameOverride: csi-cloudscale
53+
cloudscale:
54+
token:
55+
# Secret managed by the component in `main.jsonnet`
56+
existingSecret: ${csi_cloudscale:api_token_secret_name}
57+
csi:
58+
# Disable chart-managed storageclasses, we manage them directly in
59+
# the component
60+
storageClasses: []
61+
provisioner:
62+
resources: ${csi_cloudscale:resources:controller:csi-provisioner}
63+
attacher:
64+
resources: ${csi_cloudscale:resources:controller:csi-attacher}
65+
resizer:
66+
resources: ${csi_cloudscale:resources:controller:csi-resizer}
67+
controller:
68+
serviceAccountName: csi-cloudscale-controller-sa
69+
image: ${csi_cloudscale:images:cloudscale-csi-plugin}
70+
resources: ${csi_cloudscale:resources:controller:csi-cloudscale-plugin}
71+
node:
72+
serviceAccountName: csi-cloudscale-node-sa
73+
image: ${csi_cloudscale:images:cloudscale-csi-plugin}
74+
resources: ${csi_cloudscale:resources:csi_driver:csi-cloudscale-plugin}
75+
driverRegistrar:
76+
resources: ${csi_cloudscale:resources:csi_driver:csi-node-driver-registrar}

component/main.jsonnet

Lines changed: 11 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ local storageclasses = [ [
3232
} + config,
3333
] for type in [ 'ssd', 'bulk' ] ];
3434

35-
local secret = kube.Secret('cloudscale') {
35+
local secret = kube.Secret(params.api_token_secret_name) {
3636
metadata+: {
3737
namespace: params.namespace,
3838
},
@@ -41,106 +41,33 @@ local secret = kube.Secret('cloudscale') {
4141
},
4242
};
4343

44-
local manifests = std.parseJson(
45-
kap.yaml_load_stream('csi-cloudscale/manifests/' + params.version + '/deploy.yaml')
46-
);
47-
4844
local customRBAC = if isOpenshift then [
4945
kube.RoleBinding('csi-hostnetwork') {
5046
roleRef_: kube.ClusterRole('system:openshift:scc:hostnetwork'),
5147
subjects: [ {
5248
kind: 'ServiceAccount',
53-
name: std.filter(
54-
function(obj) obj.kind == 'StatefulSet', manifests
55-
)[0].spec.template.spec.serviceAccount,
49+
name: params.helm_values.controller.serviceAccountName,
5650
namespace: params.namespace,
5751
} ],
5852
},
5953
kube.RoleBinding('csi-privileged') {
6054
roleRef_: kube.ClusterRole('system:openshift:scc:privileged'),
6155
subjects: [ {
6256
kind: 'ServiceAccount',
63-
name: std.filter(
64-
function(obj) obj.kind == 'DaemonSet', manifests
65-
)[0].spec.template.spec.serviceAccount,
57+
name: params.helm_values.node.serviceAccountName,
6658
namespace: params.namespace,
6759
} ],
6860
},
6961
] else [];
7062

71-
local patch_manifest(object) =
72-
local tolerations = params.driver_daemonset_tolerations;
73-
local resourcesInParams = if object.kind == 'DaemonSet' then
74-
params.resources.csi_driver
75-
else if object.kind == 'StatefulSet' then
76-
params.resources.controller
63+
local warnDeprecatedParam(o) =
64+
if std.objectHas(params, 'version') then
65+
std.trace(
66+
'Component parameter `version` is removed and its value is ignored. Please use parameters `charts` and `images` to override the csi-cloudscale version.',
67+
o
68+
)
7769
else
78-
null;
79-
local resources =
80-
if (
81-
resourcesInParams != null
82-
&& (
83-
std.length(object.spec.template.spec.containers) !=
84-
std.length(std.objectFields(resourcesInParams))
85-
)
86-
) then
87-
std.trace(
88-
(
89-
'The number of containers in the csi-cloudscale upstream manifest "%s" changed. '
90-
+ 'Please check the default resource requests and limits configured in the component.'
91-
) % (
92-
object.metadata.name
93-
),
94-
resourcesInParams
95-
)
96-
else
97-
resourcesInParams;
98-
if (
99-
object.kind == 'DaemonSet'
100-
&& object.metadata.name == 'csi-cloudscale-node'
101-
) then
102-
object {
103-
spec+: {
104-
template+: {
105-
spec+: {
106-
containers: [
107-
c {
108-
resources+: std.prune(
109-
com.getValueOrDefault(resources, c.name, {})
110-
),
111-
}
112-
for c in super.containers
113-
],
114-
tolerations+: [
115-
tolerations[t] {
116-
key: t,
117-
}
118-
for t in std.objectFields(tolerations)
119-
],
120-
},
121-
},
122-
},
123-
}
124-
else if (
125-
object.kind == 'StatefulSet'
126-
&& object.metadata.name == 'csi-cloudscale-controller'
127-
) then
128-
object {
129-
spec+: {
130-
template+: {
131-
spec+: {
132-
containers: [
133-
c {
134-
resources+: com.getValueOrDefault(resources, c.name, {}),
135-
}
136-
for c in super.containers
137-
],
138-
},
139-
},
140-
},
141-
}
142-
else
143-
object;
70+
o;
14471

14572
{
14673
[if params.namespace != 'kube-system' then '00_namespace']: kube.Namespace(params.namespace) + if isOpenshift then {
@@ -151,28 +78,6 @@ local patch_manifest(object) =
15178
},
15279
} else {},
15380
'01_storageclasses': std.flattenArrays(storageclasses),
154-
'02_secret': secret,
155-
'10_deployments': [
156-
patch_manifest(object) {
157-
metadata+: {
158-
namespace: params.namespace,
159-
},
160-
}
161-
for object in manifests
162-
if std.setMember(object.kind, std.set([ 'StatefulSet', 'ServiceAccount', 'DaemonSet' ]))
163-
],
164-
'20_rbac': [
165-
if std.objectHas(object, 'subjects') then object {
166-
subjects: [
167-
sub {
168-
namespace: params.namespace,
169-
}
170-
for sub in object.subjects
171-
],
172-
}
173-
else object
174-
for object in manifests
175-
if std.setMember(object.kind, std.set([ 'ClusterRole', 'ClusterRoleBinding' ]))
176-
],
81+
'02_secret': warnDeprecatedParam(secret),
17782
[if std.length(customRBAC) > 0 then '30_custom_rbac']: customRBAC,
17883
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
= Upgrade from 3.x to 4.x
2+
3+
This guide describes the steps to perform an upgrade of the component from version 3.x to 4.x.
4+
5+
== Migration guide
6+
7+
Parameter `version` has been removed in component version v4.0.0.
8+
If you use this parameter to deploy a specific version of the CSI driver, you should set parameter `images.cloudscale-csi-plugin.tag` to the desired version.
9+
10+
Alternatively, you may want to select a specific Helm chart version.
11+
See the https://github.com/cloudscale-ch/csi-cloudscale/releases?q=helm-csi&expanded=true[helm-csi-cloudscale GitHub releases] for available Helm chart versions.
12+
The chart version can be specified in parameter `charts.csi-cloudscale.version`.

docs/modules/ROOT/pages/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See https://github.com/cloudscale-ch/csi-cloudscale#kubernetes-compatibility["Ku
1313

1414
== StorageClasses
1515

16-
The following storage classess are set up by this component:
16+
The following storage classes are set up by this component:
1717

1818
[cols="2,2a,2"]
1919
|===

0 commit comments

Comments
 (0)