Skip to content

Commit

Permalink
Add tolerations and nodeSelector to Server ACL init jobs and `nod…
Browse files Browse the repository at this point in the history
…eSelector` to Webhook cert manager (hashicorp#1581)

* Add tolerations and nodeSelector to server-acl-[init|cleanup] jobs
* Add nodeSelector to webhook cert manager
* Add nodeSelector to webhook-cert-manager-deployment with BATS tests
* Add tolerations and nodeSelector to server-acl-init template with BATS
* Add tolerations and nodeSelector to server-acl-init-cleanup template with BATS
* Fix indent of nodeSelector and tolerations
* Remove job stanza, bringing nodeSelector and tolerations up by one indent level
* Apply suggestions from code review
Co-authored-by: Iryna Shustava <ishustava@users.noreply.github.com>
* Fix indent and files targeted by bats
* Change indent in cleanup job from 12 to 8
Co-authored-by: Iryna Shustava <ishustava@users.noreply.github.com>
  • Loading branch information
Thomas Eckert authored Oct 18, 2022
1 parent e8b4d8b commit b7f4995
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 1 deletion.
8 changes: 8 additions & 0 deletions charts/consul/templates/server-acl-init-cleanup-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ spec:
limits:
memory: "50Mi"
cpu: "50m"
{{- if .Values.global.acls.tolerations }}
tolerations:
{{ tpl .Values.global.acls.tolerations . | indent 8 | trim }}
{{- end }}
{{- if .Values.global.acls.nodeSelector }}
nodeSelector:
{{ tpl .Values.global.acls.nodeSelector . | indent 8 | trim }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
8 changes: 8 additions & 0 deletions charts/consul/templates/server-acl-init-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ spec:
limits:
memory: "50Mi"
cpu: "50m"
{{- if .Values.global.acls.tolerations }}
tolerations:
{{ tpl .Values.global.acls.tolerations . | indent 8 | trim }}
{{- end }}
{{- if .Values.global.acls.nodeSelector }}
nodeSelector:
{{ tpl .Values.global.acls.nodeSelector . | indent 8 | trim }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
6 changes: 5 additions & 1 deletion charts/consul/templates/webhook-cert-manager-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ spec:
{{- if .Values.webhookCertManager.tolerations }}
tolerations:
{{ tpl .Values.webhookCertManager.tolerations . | indent 8 | trim }}
{{- end}}
{{- end }}
{{- if .Values.webhookCertManager.nodeSelector }}
nodeSelector:
{{ tpl .Values.webhookCertManager.nodeSelector . | indent 8 | trim }}
{{- end }}

{{- end }}
45 changes: 45 additions & 0 deletions charts/consul/test/unit/server-acl-init-cleanup-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,48 @@ load _helpers
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# global.acls.tolerations and global.acls.nodeSelector

@test "serverACLInitCleanup/Job: tolerations not set by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-cleanup-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.tolerations' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "serverACLInitCleanup/Job: tolerations can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-cleanup-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
--set 'global.acls.tolerations=- key: value' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.tolerations[0].key' | tee /dev/stderr)
[ "${actual}" = "value" ]
}

@test "serverACLInitCleanup/Job: nodeSelector not set by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-cleanup-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.nodeSelector' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "serverACLInitCleanup/Job: nodeSelector can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-cleanup-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
--set 'global.acls.nodeSelector=- key: value' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.nodeSelector[0].key' | tee /dev/stderr)
[ "${actual}" = "value" ]
}
45 changes: 45 additions & 0 deletions charts/consul/test/unit/server-acl-init-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,51 @@ load _helpers
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# global.acls.tolerations and global.acls.nodeSelector

@test "serverACLInit/Job: tolerations not set by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.tolerations' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "serverACLInit/Job: tolerations can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
--set 'global.acls.tolerations=- key: value' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.tolerations[0].key' | tee /dev/stderr)
[ "${actual}" = "value" ]
}

@test "serverACLInit/Job: nodeSelector not set by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.nodeSelector' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "serverACLInit/Job: nodeSelector can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
--set 'global.acls.nodeSelector=- key: value' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.nodeSelector[0].key' | tee /dev/stderr)
[ "${actual}" = "value" ]
}

#--------------------------------------------------------------------
# externalServers.enabled

Expand Down
23 changes: 23 additions & 0 deletions charts/consul/test/unit/webhook-cert-manager-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ load _helpers
[ "${actual}" = "value" ]
}

@test "webhookCertManager/Deployment: no nodeSelector by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/webhook-cert-manager-deployment.yaml \
--set 'controller.enabled=true' \
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.nodeSelector' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "webhookCertManager/Deployment: nodeSelector can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/webhook-cert-manager-deployment.yaml \
--set 'controller.enabled=true' \
--set 'connectInject.enabled=true' \
--set 'webhookCertManager.nodeSelector=- key: value' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.nodeSelector[0].key' | tee /dev/stderr)
[ "${actual}" = "value" ]
}

#--------------------------------------------------------------------
# Vault

Expand Down
30 changes: 30 additions & 0 deletions charts/consul/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,23 @@ global:
# @type: string
secretKey: null

# tolerations configures the taints and tolerations for the server-acl-init
# and server-acl-init-cleanup jobs. This should be a multi-line string matching the
# Tolerations (https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/) array in a Pod spec.
tolerations: ""

# This value defines `nodeSelector` (https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector)
# labels for the server-acl-init and server-acl-init-cleanup jobs pod assignment, formatted as a multi-line string.
#
# Example:
#
# ```yaml
# nodeSelector: |
# beta.kubernetes.io/arch: amd64
# ```
#
# @type: string
nodeSelector: null

# [Enterprise Only] This value refers to a Kubernetes or Vault secret that you have created
# that contains your enterprise license. It is required if you are using an
Expand Down Expand Up @@ -3072,6 +3089,19 @@ webhookCertManager:
# @type: string
tolerations: null

# This value defines `nodeSelector` (https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector)
# labels for the webhook-cert-manager pod assignment, formatted as a multi-line string.
#
# Example:
#
# ```yaml
# nodeSelector: |
# beta.kubernetes.io/arch: amd64
# ```
#
# @type: string
nodeSelector: null

# Configures a demo Prometheus installation.
prometheus:
# When true, the Helm chart will install a demo Prometheus server instance
Expand Down

0 comments on commit b7f4995

Please sign in to comment.