Skip to content

Commit

Permalink
Add Affinity and Tolerations to Inject and Sync (hashicorp#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawliet89 authored Jun 16, 2020
1 parent 9c34f8f commit 42b8065
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 2 deletions.
10 changes: 9 additions & 1 deletion templates/connect-inject-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,13 @@ spec:
{{- if .Values.connectInject.nodeSelector }}
nodeSelector:
{{ tpl .Values.connectInject.nodeSelector . | indent 8 | trim }}
{{- end }}
{{- end }}
{{- if .Values.connectInject.affinity }}
affinity:
{{ tpl .Values.connectInject.affinity . | indent 8 | trim }}
{{- end }}
{{- if .Values.connectInject.tolerations }}
tolerations:
{{ tpl .Values.connectInject.tolerations . | indent 8 | trim }}
{{- end }}
{{- end }}
10 changes: 9 additions & 1 deletion templates/sync-catalog-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,13 @@ spec:
{{- if .Values.syncCatalog.nodeSelector }}
nodeSelector:
{{ tpl .Values.syncCatalog.nodeSelector . | indent 8 | trim }}
{{- end }}
{{- end }}
{{- if .Values.syncCatalog.affinity }}
affinity:
{{ tpl .Values.syncCatalog.affinity . | indent 8 | trim }}
{{- end }}
{{- if .Values.syncCatalog.tolerations }}
tolerations:
{{ tpl .Values.syncCatalog.tolerations . | indent 8 | trim }}
{{- end }}
{{- end }}
48 changes: 48 additions & 0 deletions test/unit/connect-inject-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,30 @@ load _helpers
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# affinity

@test "connectInject/Deployment: affinity not set by default" {
cd `chart_dir`
local actual=$(helm template \
-x templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.affinity == null' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "connectInject/Deployment: affinity can be set" {
cd `chart_dir`
local actual=$(helm template \
-x templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set 'connectInject.affinity=foobar' \
. | tee /dev/stderr |
yq '.spec.template.spec | .affinity == "foobar"' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# nodeSelector

Expand Down Expand Up @@ -267,6 +291,30 @@ load _helpers
[ "${actual}" = "testing" ]
}

#--------------------------------------------------------------------
# tolerations

@test "connectInject/Deployment: tolerations not set by default" {
cd `chart_dir`
local actual=$(helm template \
-x templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.tolerations == null' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "connectInject/Deployment: tolerations can be set" {
cd `chart_dir`
local actual=$(helm template \
-x templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set 'connectInject.tolerations=foobar' \
. | tee /dev/stderr |
yq '.spec.template.spec | .tolerations == "foobar"' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# centralConfig

Expand Down
49 changes: 49 additions & 0 deletions test/unit/sync-catalog-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,30 @@ load _helpers
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# affinity

@test "syncCatalog/Deployment: affinity not set by default" {
cd `chart_dir`
local actual=$(helm template \
-x templates/sync-catalog-deployment.yaml \
--set 'syncCatalog.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.affinity == null' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "syncCatalog/Deployment: affinity can be set" {
cd `chart_dir`
local actual=$(helm template \
-x templates/sync-catalog-deployment.yaml \
--set 'syncCatalog.enabled=true' \
--set 'syncCatalog.affinity=foobar' \
. | tee /dev/stderr |
yq '.spec.template.spec | .affinity == "foobar"' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# nodeSelector

Expand Down Expand Up @@ -341,6 +365,31 @@ load _helpers
}

#--------------------------------------------------------------------
# tolerations

@test "syncCatalog/Deployment: tolerations not set by default" {
cd `chart_dir`
local actual=$(helm template \
-x templates/sync-catalog-deployment.yaml \
--set 'syncCatalog.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.tolerations == null' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "syncCatalog/Deployment: tolerations can be set" {
cd `chart_dir`
local actual=$(helm template \
-x templates/sync-catalog-deployment.yaml \
--set 'syncCatalog.enabled=true' \
--set 'syncCatalog.tolerations=foobar' \
. | tee /dev/stderr |
yq '.spec.template.spec | .tolerations == "foobar"' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# global.bootstrapACLs
# global.acls.manageSystemACLs

@test "syncCatalog/Deployment: CONSUL_HTTP_TOKEN env variable created when global.acls.manageSystemACLs=true" {
Expand Down
18 changes: 18 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,15 @@ syncCatalog:
# beta.kubernetes.io/arch: amd64
nodeSelector: null

# Affinity Settings
# This should be a multi-line string matching the affinity object
affinity: null

# Toleration Settings
# This should be a multi-line string matching the Toleration array
# in a PodSpec.
tolerations: null

# Resource settings for sync catalog pods.
resources:
requests:
Expand Down Expand Up @@ -858,6 +867,15 @@ connectInject:
# beta.kubernetes.io/arch: amd64
nodeSelector: null

# Affinity Settings
# This should be a multi-line string matching the affinity object
affinity: null

# Toleration Settings
# This should be a multi-line string matching the Toleration array
# in a PodSpec.
tolerations: null

# aclBindingRuleSelector accepts a query that defines which Service Accounts
# can authenticate to Consul and receive an ACL token during Connect injection.
# The default setting, i.e. serviceaccount.name!=default, prevents the
Expand Down

0 comments on commit 42b8065

Please sign in to comment.