Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #18 from s3than/master
Browse files Browse the repository at this point in the history
Configure affinity to be a variable to allow overriding
  • Loading branch information
Rebecca Zanzig authored Nov 8, 2018
2 parents 6f0e412 + 4124373 commit 2cc56fc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
11 changes: 3 additions & 8 deletions templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,10 @@ spec:
annotations:
"consul.hashicorp.com/connect-inject": "false"
spec:
{{- if .Values.server.affinity }}
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: {{ template "consul.name" . }}
release: "{{ .Release.Name }}"
component: server
topologyKey: kubernetes.io/hostname
{{ tpl .Values.server.affinity . | nindent 8 | trim }}
{{- end }}
terminationGracePeriodSeconds: 10
securityContext:
fsGroup: 1000
Expand Down
22 changes: 22 additions & 0 deletions test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ load _helpers
[ "${actual}" = "2" ]
}

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

@test "server/StatefulSet: affinity not set with server.affinity" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-statefulset.yaml \
--set 'server.affinity=null' \
. | tee /dev/stderr |
yq '.spec.template.spec | .affinity? == null' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "server/StatefulSet: affinity set by default" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-statefulset.yaml \
. | tee /dev/stderr |
yq '.spec.template.spec.affinity | .podAntiAffinity? != null' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# extraVolumes

Expand Down
13 changes: 13 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ server:
# name: my-secret
# load: false # if true, will add to `-config-dir` to load by Consul

# Affinity Settings
# Commenting out or setting as empty the affinity variable, will allow
# deployment to single node services such as Minikube
affinity: |
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: {{ template "consul.name" . }}
release: "{{ .Release.Name }}"
component: server
topologyKey: kubernetes.io/hostname
# Client, when enabled, configures Consul clients to run on every node
# within the Kube cluster. The current deployment model follows a traditional
# DC where a single agent is deployed per node.
Expand Down

0 comments on commit 2cc56fc

Please sign in to comment.