Skip to content

Commit 7f3346c

Browse files
authored
fix: high availability mode, limits and requests, tolerations, affinities (#30)
* fix: high availability mode, limits and requests * fix: tolerations, selectors, affinities
1 parent c1862df commit 7f3346c

File tree

10 files changed

+117
-72
lines changed

10 files changed

+117
-72
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ Universal Broker provides an Ingress template, compatible with any Kubernetes In
106106

107107
It may be [extended with additional hosts, paths, annotations as required](#broker-ingress).
108108

109+
### High Availability Mode
110+
111+
Universal Broker will run with [High Availability Mode](https://docs.snyk.io/enterprise-configuration/snyk-broker/high-availability-mode) enabled by default. Optionally increase the number of replicas from 2 up to 4 to suit fault tolerance.
112+
113+
High Availability Mode may be disabled by setting `highAvailabilityMode.enabled: false`.
114+
109115
## Advanced Configuration
110116

111117
### Certificate Trust
@@ -234,10 +240,12 @@ helm install ... --set credentialReferences.MY_GITHUB_TOKEN=<gh-pat>
234240
| `ingress.secrets` | A list of TLS secrets to create, each with `name`, `key` and `certificate` | `[]` |
235241
| `ingress.tls.enabled` | Set to true to enable TLS on the in-built ingress | `false` |
236242
| `ingress.tls.existingSecret` | Specify an existing TLS secret to use with this ingress | `""` |
237-
| `resources.requests.cpu` | Set CPU requests | `2` |
243+
| `resources.requests.cpu` | Set CPU requests | `1` |
238244
| `resources.requests.memory` | Set memory requests | `512Mi` |
239-
| `resources.limits.cpu` | Set CPU limits | `3` |
245+
| `resources.limits.cpu` | Set CPU limits | `2` |
240246
| `resources.limits.memory` | Set memory limits | `1024Mi` |
247+
| `highAvailabilityMode.enabled` | snyk [default: true] Set to false to disable High Availability Mode for Broker | `true` |
248+
| `highAvailabilityMode.replicaCount` | Number of Broker pods when running in HA mode (min 2, max 4) | `2` |
241249
| `commonLabels` | Labels to add to all deployed objects (sub-charts are not considered) | `{}` |
242250
| `commonAnnotations` | Annotations to add to all deployed objects (sub-charts are not considered) | `{}` |
243251
| `podLabels` | Pod labels | `{}` |
@@ -253,8 +261,6 @@ helm install ... --set credentialReferences.MY_GITHUB_TOKEN=<gh-pat>
253261
| `readinessProbe.config.periodSeconds` | Period seconds for readinessProbe | `10` |
254262
| `readinessProbe.config.timeoutSeconds` | Timeout seconds for readinessProbe | `1` |
255263
| `readinessProbe.config.failureThreshold` | Failure threshold for readinessProbe | `3` |
256-
| `highAvailabilityMode.enabled` | snyk broker HA mode | `false` |
257-
| `replicaCount` | number for snyk broker when running in HA mode (min 2, max 4) | `1` |
258264
| `logLevel` | defines Log Level for broker client pod. Can be set to "debug" for more information | `info` |
259265
| `logEnableBody` | adds additional logging by setting to true | `false` |
260266
| `enableBrokerLocalWebserverOverHttps` | enables Broker client to run a HTTPS server instead of the default HTTP server | `false` |

snyk-universal-broker/templates/_helpers.tpl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ Return the correct broker dispatcher URL based on the region value.
3131
{{- end -}}
3232
{{- end }}
3333

34+
{{/*
35+
Return replica count based on HA mode
36+
*/}}
3437
{{- define "snyk-broker.replicas" -}}
3538
{{- if .Values.highAvailabilityMode.enabled -}}
36-
{{- if gt (int .Values.replicaCount) 4 -}}
39+
{{- if gt (int .Values.highAvailabilityMode.replicaCount) 4 -}}
3740
{{- fail "Cannot have more than 4 replicas in High Availability mode." -}}
3841
{{- else -}}
39-
{{- print (int .Values.replicaCount) -}}
42+
{{- print (int .Values.highAvailabilityMode.replicaCount) -}}
4043
{{- end -}}
4144
{{- else -}}
4245
{{- print 1 -}}

snyk-universal-broker/templates/statefulset.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ spec:
4040
{{- if .Values.hostAliases }}
4141
hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.hostAliases "context" $) | nindent 8 }}
4242
{{- end }}
43+
{{- if .Values.affinity }}
44+
affinity: {{- include "common.tplvalues.render" (dict "value" .Values.affinity "context" $) | nindent 8 }}
45+
{{- end }}
4346
{{- if .Values.nodeSelector }}
4447
nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
4548
{{- end }}
@@ -116,7 +119,7 @@ spec:
116119
- name: BROKER_CLIENT_URL
117120
value: {{ .Values.brokerClientUrl }}
118121
- name: BROKER_HA_MODE_ENABLED
119-
value: {{ if and (.Values.highAvailabilityMode.enabled) (gt (int .Values.replicaCount) 1) }} "true" {{ else }} "false" {{ end }}
122+
value: {{ if and (.Values.highAvailabilityMode.enabled) (gt (int .Values.highAvailabilityMode.replicaCount) 1) }} "true" {{ else }} "false" {{ end }}
120123
# Logging
121124
- name: LOG_LEVEL
122125
value: {{ .Values.logLevel }}

snyk-universal-broker/tests/fixtures/default_values.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ brokerClientUrl: "http://brokerclient"
55
preflightChecks:
66
enabled: true
77

8-
highAvailabilityMode:
9-
enabled: false
10-
118
##### Snyk Platform Server Auth #####
129
deploymentId: 8b338a3b-424a-497e-836e-5e0f9486605a
1310
clientId: 8b338a3b-424a-497e-836e-5e0f9486605a

snyk-universal-broker/tests/ha_test.yaml

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1-
values:
2-
- ../values.yaml
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
32
suite: HA Mode
43
templates:
5-
- templates/statefulset.yaml
6-
tests:
7-
- it: deploys one replica by default
8-
set:
9-
highAvailabilityMode.enabled: false
10-
asserts:
11-
- equal:
12-
path: spec.replicas
13-
value: 1
14-
- contains:
15-
path: spec.template.spec.containers[0].env
16-
content:
17-
name: BROKER_HA_MODE_ENABLED
18-
value: "false"
4+
- statefulset.yaml
5+
values:
6+
- ../values.yaml
7+
- fixtures/default_values.yaml
198

20-
- it: configures multiple replicas
9+
tests:
10+
- it: configures multiple replicas by default
2111
set:
22-
replicaCount: 2
23-
highAvailabilityMode.enabled: true
12+
highAvailabilityMode.replicaCount: 2
2413
asserts:
2514
- equal:
2615
path: spec.replicas
@@ -33,16 +22,19 @@ tests:
3322

3423
- it: does not allow more than 4 replicas
3524
set:
36-
replicaCount: 5
37-
highAvailabilityMode.enabled: true
25+
highAvailabilityMode.replicaCount: 5
3826
asserts:
39-
- failedTemplate:
40-
errorMessage: "Cannot have more than 4 replicas in High Availability mode."
27+
- failedTemplate: {}
4128

42-
- it: does not set HA mode with only 1 replica
29+
- it: does not allow setting 1 replica in HA mode
4330
set:
44-
replicaCount: 1
45-
highAvailabilityMode.enabled: true
31+
highAvailabilityMode.replicaCount: 1
32+
asserts:
33+
- failedTemplate: {}
34+
35+
- it: disables HA mode
36+
set:
37+
highAvailabilityMode.enabled: false
4638
asserts:
4739
- equal:
4840
path: spec.replicas

snyk-universal-broker/tests/pod_runtimes_test.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
suite: Pod runtime tests
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
2+
suite: Pod Runtime
23
values:
34
- ../values.yaml
5+
- fixtures/default_values.yaml
46
templates:
5-
- templates/statefulset.yaml
7+
- statefulset.yaml
68

79
tests:
810
- it: should set pod security context when enabled
@@ -67,7 +69,7 @@ tests:
6769
- equal:
6870
path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem
6971
value: true
70-
72+
7173
- it: can add tolerations
7274
set:
7375
tolerations:
@@ -108,4 +110,4 @@ tests:
108110
- "example.com"
109111
- equal:
110112
path: spec.template.spec.hostAliases[0].ip
111-
value: "127.0.0.1"
113+
value: "127.0.0.1"

snyk-universal-broker/tests/resources_and_limits_test.yaml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ suite: Resources and Limits
44
templates:
55
- statefulset.yaml
66
values:
7+
- ../values.yaml
78
- fixtures/default_values.yaml
89

910
tests:
@@ -14,13 +15,6 @@ tests:
1415
- exists:
1516
path: spec.template.spec.containers[0].resources.limits
1617

17-
- it: Defines requests and limits by default
18-
asserts:
19-
- exists:
20-
path: spec.template.spec.containers[0].resources.requests
21-
- exists:
22-
path: spec.template.spec.containers[0].resources.limits
23-
2418
- it: Respects custom requests
2519
set:
2620
resources:
@@ -34,17 +28,3 @@ tests:
3428
- equal:
3529
path: spec.template.spec.containers[0].resources.requests.memory
3630
value: "5Gi"
37-
38-
- it: Respects custom limits
39-
set:
40-
resources:
41-
limits:
42-
cpu: 2
43-
memory: 5Gi
44-
asserts:
45-
- equal:
46-
path: spec.template.spec.containers[0].resources.limits.cpu
47-
value: 2
48-
- equal:
49-
path: spec.template.spec.containers[0].resources.limits.memory
50-
value: "5Gi"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
2+
3+
suite: Tolerations, Selectors and Affinities
4+
templates:
5+
- statefulset.yaml
6+
values:
7+
- ../values.yaml
8+
- fixtures/default_values.yaml
9+
10+
tests:
11+
- it: Accepts a toleration
12+
set:
13+
tolerations:
14+
- key: "key1"
15+
operator: "Equal"
16+
value: "value1"
17+
effect: "NoSchedule"
18+
asserts:
19+
- contains:
20+
path: spec.template.spec.tolerations
21+
content:
22+
key: "key1"
23+
operator: "Equal"
24+
value: "value1"
25+
effect: "NoSchedule"
26+
27+
- it: Accepts a selector
28+
set:
29+
nodeSelector:
30+
group: "prodsec"
31+
asserts:
32+
- equal:
33+
path: spec.template.spec.nodeSelector.group
34+
value: "prodsec"
35+
36+
- it: Accepts an affinity
37+
set:
38+
affinity:
39+
nodeAffinity:
40+
requiredDuringSchedulingIgnoredDuringExecution:
41+
nodeSelectorTerms:
42+
- matchExpressions:
43+
- key: topology.kubernetes.io/zone
44+
operator: In
45+
values:
46+
- antarctica-east1
47+
- antarctica-west1
48+
asserts:
49+
- exists:
50+
path: spec.template.spec.affinity.nodeAffinity

snyk-universal-broker/values.schema.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,20 @@
190190
}
191191
}
192192
}
193-
}
193+
},
194+
"highAvailabilityMode": {
195+
"properties":{
196+
"enabled": {
197+
"type": "boolean"
198+
},
199+
"replicaCount": {
200+
"type": "integer",
201+
"minimum": 2,
202+
"maximum": 4
203+
}
204+
}
205+
},
206+
"additionalProperties": false
194207
},
195208
"additionalProperties": true
196209
}

snyk-universal-broker/values.yaml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,19 @@ ingress:
133133
## @param resources.limits.memory Set memory limits
134134
resources:
135135
requests:
136-
cpu: 2
136+
cpu: 1
137137
memory: 512Mi
138138
limits:
139-
cpu: 3
139+
cpu: 2
140140
memory: 1024Mi
141141

142+
## @param highAvailabilityMode.enabled snyk [default: true] Set to false to disable High Availability Mode for Broker
143+
## @param highAvailabilityMode.replicaCount [default: 2] Number of Broker pods when running in HA mode (min 2, max 4)
144+
145+
highAvailabilityMode:
146+
enabled: true
147+
replicaCount: 2
148+
142149
## @param commonLabels Labels to add to all deployed objects (sub-charts are not considered)
143150
##
144151
commonLabels: {}
@@ -186,14 +193,6 @@ readinessProbe:
186193
timeoutSeconds: 1
187194
failureThreshold: 3
188195

189-
## HA MODE #####
190-
## @param highAvailabilityMode.enabled snyk broker HA mode
191-
## @param replicaCount number for snyk broker when running in HA mode (min 2, max 4)
192-
193-
highAvailabilityMode:
194-
enabled: false
195-
replicaCount: 1
196-
197196
## Logging #####
198197
## @param logLevel defines Log Level for broker client pod. Can be set to "debug" for more information
199198
## @param logEnableBody adds additional logging by setting to true

0 commit comments

Comments
 (0)