From 3e95d466ff55f59b8e77c78f7fb258e5051e4960 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Fri, 25 Aug 2023 14:54:07 +0200 Subject: [PATCH] Add postprocessing filter to keep supporting `driver_daemonset_tolerations` parameter We can't simply pass the parameter to the `node.tolerations` Helm value, since that value expects an array of regular tolerations while the component parameter is structured to allow users to overwrite tolerations. Note that the postprocessing filter will retain tolerations configured through the Helm value and will simply append any tolerations configured in `driver_daemonset_tolerations`. --- class/csi-cloudscale.yml | 6 ++++ .../driver_daemonset_tolerations.jsonnet | 29 +++++++++++++++++++ .../csi-cloudscale/templates/daemonset.yaml | 4 +++ tests/openshift4.yml | 6 ++++ 4 files changed, 45 insertions(+) create mode 100644 postprocess/driver_daemonset_tolerations.jsonnet diff --git a/class/csi-cloudscale.yml b/class/csi-cloudscale.yml index cea51c3..0f4b3a3 100644 --- a/class/csi-cloudscale.yml +++ b/class/csi-cloudscale.yml @@ -22,3 +22,9 @@ parameters: - ${_base_directory}/component/main.jsonnet input_type: jsonnet output_path: csi-cloudscale/ + commodore: + postprocess: + filters: + - type: jsonnet + filter: postprocess/driver_daemonset_tolerations.jsonnet + path: csi-cloudscale/01_helm_chart/csi-cloudscale/templates diff --git a/postprocess/driver_daemonset_tolerations.jsonnet b/postprocess/driver_daemonset_tolerations.jsonnet new file mode 100644 index 0000000..d892374 --- /dev/null +++ b/postprocess/driver_daemonset_tolerations.jsonnet @@ -0,0 +1,29 @@ +local com = import 'lib/commodore.libjsonnet'; + +local inv = com.inventory(); +local params = inv.parameters.csi_cloudscale; +local tolerations = params.driver_daemonset_tolerations; + +local chartDir = std.extVar('output_path'); + +com.fixupDir( + chartDir, + function(obj) + if obj.kind == 'DaemonSet' then + obj { + spec+: { + template+: { + spec+: { + [if std.length(tolerations) > 0 then 'tolerations']+: [ + tolerations[name] { + key: name, + } + for name in std.objectFields(tolerations) + ], + }, + }, + }, + } + else + obj +) diff --git a/tests/golden/openshift4/csi-cloudscale/csi-cloudscale/01_helm_chart/csi-cloudscale/templates/daemonset.yaml b/tests/golden/openshift4/csi-cloudscale/csi-cloudscale/01_helm_chart/csi-cloudscale/templates/daemonset.yaml index a30a2a6..07395df 100644 --- a/tests/golden/openshift4/csi-cloudscale/csi-cloudscale/01_helm_chart/csi-cloudscale/templates/daemonset.yaml +++ b/tests/golden/openshift4/csi-cloudscale/csi-cloudscale/01_helm_chart/csi-cloudscale/templates/daemonset.yaml @@ -86,6 +86,10 @@ spec: hostNetwork: true priorityClassName: system-node-critical serviceAccount: csi-cloudscale-node-sa + tolerations: + - effect: NoSchedule + key: storagenode + operator: Exists volumes: - hostPath: path: /var/lib/kubelet/plugins_registry/ diff --git a/tests/openshift4.yml b/tests/openshift4.yml index 1d1921c..9df4a9a 100644 --- a/tests/openshift4.yml +++ b/tests/openshift4.yml @@ -14,3 +14,9 @@ parameters: facts: distribution: openshift4 + + csi_cloudscale: + driver_daemonset_tolerations: + storagenode: + operator: Exists + effect: NoSchedule