-
Notifications
You must be signed in to change notification settings - Fork 0
/
_spec_for_high_availability.tpl
138 lines (135 loc) · 4.63 KB
/
_spec_for_high_availability.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
{{- /* Usage: {{ include "helm_lib_pod_anti_affinity_for_ha" (list . (dict "app" "test")) }} */ -}}
{{- /* returns pod affinity spec */ -}}
{{- define "helm_lib_pod_anti_affinity_for_ha" }}
{{- $context := index . 0 -}} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- $labels := index . 1 }} {{- /* Match labels for podAntiAffinity label selector */ -}}
{{- if (include "helm_lib_ha_enabled" $context) }}
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
{{- range $key, $value := $labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
topologyKey: kubernetes.io/hostname
{{- end }}
{{- end }}
{{- /* Usage: {{ include "helm_lib_deployment_on_master_strategy_and_replicas_for_ha" }} */ -}}
{{- /* returns deployment strategy and replicas for ha components running on master nodes */ -}}
{{- define "helm_lib_deployment_on_master_strategy_and_replicas_for_ha" }}
{{- /* Template context with .Values, .Chart, etc */ -}}
{{- if (include "helm_lib_ha_enabled" .) }}
{{- if gt (index .Values.global.discovery "clusterMasterCount" | int) 0 }}
replicas: {{ index .Values.global.discovery "clusterMasterCount" }}
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 0
{{- if gt (index .Values.global.discovery "clusterMasterCount" | int) 2 }}
maxUnavailable: 2
{{- else }}
maxUnavailable: 1
{{- end }}
{{- else if gt (index .Values.global.discovery.d8SpecificNodeCountByRole "master" | int) 0 }}
replicas: {{ index .Values.global.discovery.d8SpecificNodeCountByRole "master" }}
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 0
{{- if gt (index .Values.global.discovery.d8SpecificNodeCountByRole "master" | int) 2 }}
maxUnavailable: 2
{{- else }}
maxUnavailable: 1
{{- end }}
{{- else }}
replicas: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
{{- end }}
{{- else }}
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
{{- end }}
{{- end }}
{{- /* Usage: {{ include "helm_lib_deployment_on_master_custom_strategy_and_replicas_for_ha" (list . (dict "strategy" "strategy_type")) }} */ -}}
{{- /* returns deployment with custom strategy and replicas for ha components running on master nodes */ -}}
{{- define "helm_lib_deployment_on_master_custom_strategy_and_replicas_for_ha" }}
{{- $context := index . 0 }}
{{- $optionalArgs := dict }}
{{- $strategy := "RollingUpdate" }}
{{- if ge (len .) 2 }}
{{- $optionalArgs = index . 1 }}
{{- end }}
{{- if hasKey $optionalArgs "strategy" }}
{{- $strategy = $optionalArgs.strategy }}
{{- end }}
{{- /* Template context with .Values, .Chart, etc */ -}}
{{- if (include "helm_lib_ha_enabled" $context) }}
{{- if gt (index $context.Values.global.discovery "clusterMasterCount" | int) 0 }}
replicas: {{ index $context.Values.global.discovery "clusterMasterCount" }}
strategy:
type: {{ $strategy }}
{{- if eq $strategy "RollingUpdate" }}
rollingUpdate:
maxSurge: 0
{{- if gt (index $context.Values.global.discovery "clusterMasterCount" | int) 2 }}
maxUnavailable: 2
{{- else }}
maxUnavailable: 1
{{- end }}
{{- end }}
{{- else if gt (index $context.Values.global.discovery.d8SpecificNodeCountByRole "master" | int) 0 }}
replicas: {{ index $context.Values.global.discovery.d8SpecificNodeCountByRole "master" }}
strategy:
type: {{ $strategy }}
{{- if eq $strategy "RollingUpdate" }}
rollingUpdate:
maxSurge: 0
{{- if gt (index $context.Values.global.discovery.d8SpecificNodeCountByRole "master" | int) 2 }}
maxUnavailable: 2
{{- else }}
maxUnavailable: 1
{{- end }}
{{- end }}
{{- else }}
replicas: 2
strategy:
type: {{ $strategy }}
{{- if eq $strategy "RollingUpdate" }}
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
{{- end }}
{{- end }}
{{- else }}
replicas: 1
strategy:
type: {{ $strategy }}
{{- if eq $strategy "RollingUpdate" }}
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
{{- end }}
{{- end }}
{{- end }}
{{- /* Usage: {{ include "helm_lib_deployment_strategy_and_replicas_for_ha" }} */ -}}
{{- /* returns deployment strategy and replicas for ha components running not on master nodes */ -}}
{{- define "helm_lib_deployment_strategy_and_replicas_for_ha" }}
{{- /* Template context with .Values, .Chart, etc */ -}}
replicas: {{ include "helm_lib_is_ha_to_value" (list . 2 1) }}
{{- if (include "helm_lib_ha_enabled" .) }}
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
{{- end }}
{{- end }}