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

Add tolerations to init job templates #3433

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,12 @@ spec:
limits:
memory: "50Mi"
cpu: "50m"
{{- if .Values.global.gossipEncryption.tolerations }}
tolerations:
{{ tpl .Values.global.gossipEncryption.tolerations . | indent 8 | trim }}
{{- end }}
{{- if .Values.global.gossipEncryption.nodeSelector }}
nodeSelector:
{{ tpl .Values.global.gossipEncryption.nodeSelector . | indent 8 | trim }}
{{- end }}
{{- end }}
8 changes: 8 additions & 0 deletions charts/consul/templates/tls-init-cleanup-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ spec:
limits:
memory: "50Mi"
cpu: "50m"
{{- if .Values.global.tls.tolerations }}
tolerations:
{{ tpl .Values.global.tls.tolerations . | indent 8 | trim }}
{{- end }}
{{- if .Values.global.tls.nodeSelector }}
nodeSelector:
{{ tpl .Values.global.tls.nodeSelector . | indent 8 | trim }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
8 changes: 8 additions & 0 deletions charts/consul/templates/tls-init-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ spec:
limits:
memory: "50Mi"
cpu: "50m"
{{- if .Values.global.tls.tolerations }}
tolerations:
{{ tpl .Values.global.tls.tolerations . | indent 8 | trim }}
{{- end }}
{{- if .Values.global.tls.nodeSelector }}
nodeSelector:
{{ tpl .Values.global.tls.nodeSelector . | indent 8 | trim }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
45 changes: 45 additions & 0 deletions charts/consul/test/unit/gossip-encryption-autogenerate-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,48 @@ load _helpers
yq 'any(contains("-log-level=debug"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# global.gossipEncryption.tolerations and global.gossipEncryption.nodeSelector

@test "gossipEncryptionAutogenerate/Job: tolerations not set by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/gossip-encryption-autogenerate-job.yaml \
--set 'global.gossipEncryption.autoGenerate=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.tolerations' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "gossipEncryptionAutogenerate/Job: tolerations can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/gossip-encryption-autogenerate-job.yaml \
--set 'global.gossipEncryption.autoGenerate=true' \
--set 'global.gossipEncryption.tolerations=- key: value' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.tolerations[0].key' | tee /dev/stderr)
[ "${actual}" = "value" ]
}

@test "gossipEncryptionAutogenerate/Job: nodeSelector not set by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/gossip-encryption-autogenerate-job.yaml \
--set 'global.gossipEncryption.autoGenerate=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.nodeSelector' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "gossipEncryptionAutogenerate/Job: nodeSelector can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/gossip-encryption-autogenerate-job.yaml \
--set 'global.gossipEncryption.autoGenerate=true' \
--set 'global.gossipEncryption.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/tls-init-cleanup-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,48 @@ load _helpers
yq -r '.spec.template.metadata.annotations.foo' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}

#--------------------------------------------------------------------
# global.tls.tolerations and global.tls.nodeSelector

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

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

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

@test "tlsInitCleanup/Job: nodeSelector can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/tls-init-cleanup-job.yaml \
--set 'global.tls.enabled=true' \
--set 'global.tls.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/tls-init-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,48 @@ load _helpers
yq -r '.spec.template.metadata.annotations.foo' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}

#--------------------------------------------------------------------
# global.tls.tolerations and global.tls.nodeSelector

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

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

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

@test "tlsInit/Job: nodeSelector can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/tls-init-job.yaml \
--set 'global.tls.enabled=true' \
--set 'global.tls.nodeSelector=- key: value' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.nodeSelector[0].key' | tee /dev/stderr)
[ "${actual}" = "value" ]
}
36 changes: 36 additions & 0 deletions charts/consul/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,24 @@ global:
# @type: string
logLevel: ""

# tolerations configures the taints and tolerations for the gossip-encryption-autogenerate job.
# 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 gossip-encryption-autogenerate job pod assignment, formatted as a multi-line string.
#
# Example:
#
# ```yaml
# nodeSelector: |
# beta.kubernetes.io/arch: amd64
# ```
#
# @type: string
nodeSelector: null

# A list of addresses of upstream DNS servers that are used to recursively resolve DNS queries.
# These values are given as `-recursor` flags to Consul servers and clients.
# Refer to [`-recursor`](https://developer.hashicorp.com/consul/docs/agent/config/cli-flags#_recursor) for more details.
Expand Down Expand Up @@ -402,6 +420,24 @@ global:
# @type: string
annotations: null

# tolerations configures the taints and tolerations for the tls-init
# and tls-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 tls-init and tls-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] `enableConsulNamespaces` indicates that you are running
# Consul Enterprise v1.7+ with a valid Consul Enterprise license and would
# like to make use of configuration beyond registering everything into
Expand Down