Skip to content

Commit

Permalink
feat: allow setting custom pod affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
project0 authored Apr 3, 2023
1 parent 4c0ebd0 commit 3d7c93e
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 68 deletions.
2 changes: 1 addition & 1 deletion traefikee/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: traefikee
version: 1.7.0
version: 1.8.0
appVersion: v2.9.1
# Because of https://github.com/helm/helm/issues/3810 the pre-release version suffix has to be define.
# This allows the installation on Kubernetes cluster with a pre-release version (e.g. v1.19.9-gke.1900)
Expand Down
24 changes: 4 additions & 20 deletions traefikee/templates/proxy/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
component: proxies
template:
metadata:
labels:
labels:
component: proxies
{{ include "common.labels" . | nindent 8 }}
{{- with .Values.proxy.podLabels }}
Expand All @@ -37,26 +37,10 @@ spec:
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.proxy.affinity }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: component
operator: In
values:
- proxies
topologyKey: "kubernetes.io/hostname"
{{- tpl (toYaml .Values.proxy.affinity) . | nindent 8 }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.proxy.terminationGracePeriodSeconds | default 30 }}
automountServiceAccountToken: false
initContainers:
Expand Down
48 changes: 8 additions & 40 deletions traefikee/templates/stateful-sets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
annotations:
"helm.sh/resource-policy": keep
type: Opaque
data:
data:
token: {{ $tokenStr }}
{{- end }}

Expand Down Expand Up @@ -44,7 +44,7 @@ spec:
{{- with (.Values.registry).podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
labels:
component: registry
{{ include "common.labels" . | nindent 8 }}
{{- with (.Values.registry).podLabels }}
Expand All @@ -55,26 +55,10 @@ spec:
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.registry.affinity }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: component
operator: In
values:
- registry
topologyKey: "kubernetes.io/hostname"
{{- tpl (toYaml .Values.registry.affinity) . | nindent 8 }}
{{- end }}
terminationGracePeriodSeconds: 30
automountServiceAccountToken: false
initContainers:
Expand Down Expand Up @@ -204,26 +188,10 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ .Values.cluster }}-svc-acc
{{- if .Values.controller.affinity }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: component
operator: In
values:
- controllers
topologyKey: "kubernetes.io/hostname"
{{- tpl (toYaml .Values.controller.affinity) . | nindent 8 }}
{{- end }}
terminationGracePeriodSeconds: 30
initContainers:
- name: wait-dns
Expand Down
89 changes: 83 additions & 6 deletions traefikee/tests/controller_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,61 @@ tests:
documentIndex: 2
- hasDocuments:
count: 3
- it: should override defaults
- documentIndex: 1
equal:
path: spec.template.spec.affinity
value:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: component
operator: In
values:
- registry
topologyKey: kubernetes.io/hostname
- documentIndex: 2
equal:
path: spec.template.spec.affinity
value:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: component
operator: In
values:
- controllers
topologyKey: kubernetes.io/hostname
- it: should override controller defaults
set:
cluster: "mysupertraefikee"
image.name: "mycustompublisher/myspecialimage"
image.tag: "myspecialversion"
image.pullPolicy: Never
controller:
replicas: 2
affinity: null
documentIndex: 2
asserts:
- isKind:
Expand All @@ -86,18 +133,48 @@ tests:
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
value: Never
- isNull:
path: spec.template.spec.affinity
- it: should override registry defaults
set:
cluster: "mysupertraefikee"
image.name: "mycustompublisher/myspecialimage"
image.tag: "myspecialversion"
image.pullPolicy: Never
registry:
affinity: null
documentIndex: 1
asserts:
- isKind:
of: StatefulSet
- isAPIVersion:
of: apps/v1
- equal:
path: metadata.name
value: mysupertraefikee-plugin-registry
- equal:
path: spec.template.spec.containers[0].image
value: "mycustompublisher/myspecialimage:myspecialversion"
- equal:
path: spec.serviceName
value: mysupertraefikee-plugin-registry-svc
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
value: Never
- isNull:
path: spec.template.spec.affinity
- it: should add labels and annotations
set:
cluster: "mysupertraefikee"
controller:
statefulSetLabels:
st-lb-foo: bar
st-lb-foo: bar
statefulSetAnnotations:
st-an-foo: bar
st-an-foo: bar
podLabels:
pod-lb-foo: bar
pod-lb-foo: bar
podAnnotations:
pod-an-foo: bar
pod-an-foo: bar
documentIndex: 2
asserts:
- isKind:
Expand All @@ -120,7 +197,7 @@ tests:
set:
controller:
additionalArguments:
- --foo=bar
- --foo=bar
documentIndex: 2
asserts:
- isKind:
Expand Down
25 changes: 25 additions & 0 deletions traefikee/tests/proxy_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ tests:
- equal:
path: spec.template.spec.containers[0].image
value: "traefik/traefikee:v2.9.1"
- equal:
path: spec.template.spec.affinity
value:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: component
operator: In
values:
- proxies
topologyKey: "kubernetes.io/hostname"
- it: should override defaults
set:
cluster: "mysupertraefikee"
Expand All @@ -22,6 +44,7 @@ tests:
image.pullPolicy: Never
proxy:
replicas: 2
affinity: null
asserts:
- isKind:
of: Deployment
Expand All @@ -41,6 +64,8 @@ tests:
value: Never
- hasDocuments:
count: 1
- isNull:
path: spec.template.spec.affinity
- it: default ports are set
asserts:
- isKind:
Expand Down
67 changes: 66 additions & 1 deletion traefikee/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,29 @@ image:
# format:
# file:

# registry:
registry:
# To disable affinity at all set this value to null
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: component
operator: In
values:
- registry
topologyKey: "kubernetes.io/hostname"

# serviceLabels:
# foo: bar
# serviceAnnotations:
Expand All @@ -35,6 +57,27 @@ image:

controller:
replicas: 1
# To disable affinity at all set this value to null
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: component
operator: In
values:
- controllers
topologyKey: "kubernetes.io/hostname"
# staticConfig:
# configMap:
# name: traefik-config
Expand Down Expand Up @@ -70,6 +113,28 @@ proxy:
port: 80
- name: https
port: 443

# To disable affinity at all set this value to null
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: component
operator: In
values:
- proxies
topologyKey: "kubernetes.io/hostname"
# readinessProbe:
# tcpSocket:
# port: http
Expand Down

0 comments on commit 3d7c93e

Please sign in to comment.