Skip to content

Commit

Permalink
Helm: add support for topologySpreadConstraints. (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
thylong committed Sep 1, 2021
1 parent 9f46e5a commit a90c756
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
4 changes: 4 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ spec:
serviceAccountName: {{ include "kube-httpcache.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- with .Values.topologySpreadConstraints }}
topologySpreadConstraints:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.initContainers }}
initContainers:
{{- with .Values.initContainers }}
Expand Down
4 changes: 4 additions & 0 deletions chart/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ spec:
serviceAccountName: {{ include "kube-httpcache.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- with .Values.topologySpreadConstraints }}
topologySpreadConstraints:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.initContainers }}
initContainers:
{{- with .Values.initContainers }}
Expand Down
38 changes: 26 additions & 12 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ lifecycle: {}
# - -c
# - touch /etc/varnish/fail_probes; sleep 25

topologySpreadConstraints: {}
# - topologyKey: topology.kubernetes.io/zone
# maxSkew: 1
# whenUnsatisfiable: ScheduleAnyway
# labelSelector:
# matchLabels:
# app.kubernetes.io/name: kube-httpcache
# - topologyKey: kubernetes.io/hostname
# maxSkew: 1
# whenUnsatisfiable: ScheduleAnyway
# labelSelector:
# matchLabels:
# app.kubernetes.io/name: kube-httpcache

initContainers: {}
# initContainers: |
# - args:
Expand Down Expand Up @@ -218,10 +232,10 @@ readinessProbe: {}

vclTemplate: |
vcl 4.0;
import std;
import directors;
// ".Frontends" is a slice that contains all known Varnish instances
// (as selected by the service specified by -frontend-service).
// The backend name needs to be the Pod name, since this value is compared
Expand All @@ -234,35 +248,35 @@ vclTemplate: |
.port = "{{ .Port }}";
}
{{- end }}
{{ range .Backends }}
backend be-{{ .Name }} {
.host = "{{ .Host }}";
.port = "{{ .Port }}";
}
{{- end }}
sub vcl_init {
new cluster = directors.hash();
{{ range .Frontends -}}
cluster.add_backend({{ .Name }}, 1);
{{ end }}
new lb = directors.round_robin();
{{ range .Backends -}}
lb.add_backend(be-{{ .Name }});
{{ end }}
}
sub vcl_recv
{
# Set backend hint for non cachable objects.
set req.backend_hint = lb.backend();
# ...
# Routing logic. Pass a request to an appropriate Varnish node.
# See https://info.varnish-software.com/blog/creating-self-routing-varnish-cluster for more info.
unset req.http.x-cache;
Expand All @@ -272,8 +286,8 @@ vclTemplate: |
return(pass);
}
set req.backend_hint = lb.backend();
# ...
return(hash);
}

0 comments on commit a90c756

Please sign in to comment.