Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSI nodeSelector, affinity #862

Merged
merged 4 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Features:
* server: New `extraPorts` option for adding ports to the Vault server statefulset [GH-841](https://github.com/hashicorp/vault-helm/pull/841)
* server: Add configurable Port Number in readinessProbe and livenessProbe for the server-statefulset [GH-831](https://github.com/hashicorp/vault-helm/pull/831)
* injector: Make livenessProbe and readinessProbe configurable and add configurable startupProbe [GH-852](https://github.com/hashicorp/vault-helm/pull/852)
* CSI: Make `nodeSelector` and `affinity` configurable for CSI daemonset's pods [GH-862](https://github.com/hashicorp/vault-helm/pull/862)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you add a new Features heading in the Unreleased section for this?

* csi: Add an Agent sidecar to Vault CSI Provider pods to provide lease caching and renewals [GH-749](https://github.com/hashicorp/vault-helm/pull/749)

## 0.23.0 (November 28th, 2022)
Expand Down
28 changes: 28 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,34 @@ Sets the injector toleration for pod placement
{{- end }}
{{- end -}}

{{/*
Sets the CSI provider nodeSelector for pod placement
*/}}
{{- define "csi.pod.nodeselector" -}}
{{- if .Values.csi.pod.nodeSelector }}
nodeSelector:
{{- $tp := typeOf .Values.csi.pod.nodeSelector }}
{{- if eq $tp "string" }}
{{ tpl .Values.csi.pod.nodeSelector . | nindent 8 | trim }}
{{- else }}
{{- toYaml .Values.csi.pod.nodeSelector | nindent 8 }}
{{- end }}
{{- end }}
{{- end -}}
{{/*
Sets the CSI provider affinity for pod placement.
*/}}
{{- define "csi.pod.affinity" -}}
{{- if .Values.csi.pod.affinity }}
affinity:
{{ $tp := typeOf .Values.csi.pod.affinity }}
{{- if eq $tp "string" }}
{{- tpl .Values.csi.pod.affinity . | nindent 8 | trim }}
{{- else }}
{{- toYaml .Values.csi.pod.affinity | nindent 8 }}
{{- end }}
{{ end }}
{{- end -}}
{{/*
Sets extra CSI provider pod annotations
*/}}
Expand Down
2 changes: 2 additions & 0 deletions templates/csi-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ spec:
{{- end }}
serviceAccountName: {{ template "vault.fullname" . }}-csi-provider
{{- template "csi.pod.tolerations" . }}
{{- template "csi.pod.nodeselector" . }}
{{- template "csi.pod.affinity" . }}
containers:
- name: {{ include "vault.name" . }}-csi-provider
{{ template "csi.resources" . }}
Expand Down
68 changes: 68 additions & 0 deletions test/unit/csi-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,74 @@ load _helpers
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# nodeSelector
@test "csi/daemonset: nodeSelector not set by default" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec | .nodeSelector? == null' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "csi/daemonset: nodeSelector can be set as string" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
--set 'csi.pod.nodeSelector=foobar' \
. | tee /dev/stderr |
yq '.spec.template.spec.nodeSelector == "foobar"' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "csi/daemonset: nodeSelector can be set as YAML" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
--set "csi.pod.nodeSelector[0].foo=bar,csi.pod.nodeSelector[1].baz=qux" \
. | tee /dev/stderr |
yq '.spec.template.spec.nodeSelector[0].foo == "bar" and .spec.template.spec.nodeSelector[1].baz == "qux"' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# affinity
@test "csi/daemonset: affinity not set by default" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec | .affinity? == null' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "csi/daemonset: affinity can be set as string" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
--set 'csi.pod.affinity=foobar' \
. | tee /dev/stderr |
yq '.spec.template.spec.affinity == "foobar"' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "csi/daemonset: affinity can be set as YAML" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
--set "csi.pod.affinity.podAntiAffinity=foobar" \
. | tee /dev/stderr |
yq '.spec.template.spec.affinity.podAntiAffinity == "foobar"' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# Extra Labels

Expand Down
14 changes: 14 additions & 0 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@
"pod": {
"type": "object",
"properties": {
"affinity": {
"type": [
"null",
"array",
"string"
]
},
"annotations": {
"type": [
"object",
Expand All @@ -145,6 +152,13 @@
"extraLabels": {
"type": "object"
},
"nodeSelector": {
"type": [
"null",
"array",
"string"
]
},
"tolerations": {
"type": [
"null",
Expand Down
13 changes: 13 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,19 @@ csi:
# in a PodSpec.
tolerations: []

# nodeSelector labels for csi pod assignment, formatted as a multi-line string or YAML map.
# ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector
# Example:
# nodeSelector:
# beta.kubernetes.io/arch: amd64
nodeSelector: []

# Affinity Settings
# Commenting out or setting as empty the affinity variable, will allow
# deployment to single node services such as Minikube
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem relevant, as the default is empty?

Suggested change
# Commenting out or setting as empty the affinity variable, will allow
# deployment to single node services such as Minikube

# This should be either a multi-line string or YAML matching the PodSpec's affinity field.
affinity: {}

# Extra labels to attach to the vault-csi-provider pod
# This should be a YAML map of the labels to apply to the csi provider pod
extraLabels: {}
Expand Down