Skip to content

Commit 0f4b444

Browse files
nejeceshepelyuk
authored andcommitted
feat: add Service annotations and trafficDistribution
- adding helm chart functionality to specify Service annotations and `trafficDistribution` configuration to allow users to configure shortest path to the pods - adding unit and lint tests Signed-off-by: Jernej Porenta <jernej.porenta@3fs.si>
1 parent 6558985 commit 0f4b444

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-1
lines changed

charts/opa-kube-mgmt/templates/service.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ metadata:
44
name: {{ template "opa.fullname" . }}
55
labels:
66
{{ include "opa.labels.standard" . | indent 4 }}
7+
{{- with .Values.service.annotations }}
8+
annotations:
9+
{{- toYaml . | nindent 4 }}
10+
{{- end }}
711
spec:
812
selector:
913
app: {{ template "opa.fullname" . }}
@@ -19,3 +23,6 @@ spec:
1923
{{- if .Values.extraPorts }}
2024
{{ toYaml .Values.extraPorts | indent 2}}
2125
{{- end }}
26+
{{- if .Values.service.trafficDistribution }}
27+
trafficDistribution: {{ .Values.service.trafficDistribution }}
28+
{{- end }}

charts/opa-kube-mgmt/values.schema.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@
3131
"annotations": {"type": "object", "additionalProperties": {"type": "string"}, "default": {}},
3232
"name": {"type": ["string", "null"], "default": null}
3333
}
34+
},
35+
"service": {
36+
"type": "object",
37+
"properties": {
38+
"annotations": {
39+
"type": "object",
40+
"additionalProperties": {"type": "string"},
41+
"default": {}
42+
},
43+
"trafficDistribution": {
44+
"type": ["null","string"],
45+
"enum": ["PreferZone", "PreferSameNode", "PreferSameZone", null],
46+
"default": null
47+
}
48+
}
3449
}
3550
}
3651
}

charts/opa-kube-mgmt/values.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ serviceMonitor:
2626
## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#prometheusspec
2727
additionalLabels: {}
2828

29+
# Service configuration
30+
service:
31+
# Annotations to add to the service
32+
annotations: {}
33+
# Configure trafficDistribution if needed.
34+
# trafficDistribution: PreferSameZone
35+
2936
# Annotations in the deployment template
3037
annotations: {}
3138

@@ -293,4 +300,3 @@ extraPorts: []
293300
# protocol: TCP
294301
# name: http
295302
# targetPort: http
296-

test/lint/service.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
suite: lint service
2+
templates:
3+
- service.yaml
4+
tests:
5+
- it: service annotations must be a string for foo
6+
set:
7+
service:
8+
annotations:
9+
bar: true
10+
baz: ["invalid"]
11+
foo:
12+
bar: baz
13+
asserts:
14+
- failedTemplate:
15+
errorPattern: "Invalid type. Expected: string, given"
16+
- it: trafficDistribution invalid value
17+
set:
18+
service:
19+
trafficDistribution: "InvalidValue"
20+
asserts:
21+
- failedTemplate:
22+
errorMessage: |
23+
values don't meet the specifications of the schema(s) in the following chart(s):
24+
opa-kube-mgmt:
25+
- service.trafficDistribution: service.trafficDistribution must be one of the following: "PreferZone", "PreferSameNode", "PreferSameZone", null

test/unit/service.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
suite: test service definition
2+
templates:
3+
- service.yaml
4+
tests:
5+
- it: should omit service annotations when null
6+
set:
7+
service.annotations: null
8+
asserts:
9+
- notExists:
10+
path: metadata.annotations.foo
11+
- it: should set service annotations
12+
set:
13+
service.annotations:
14+
foo: bar
15+
asserts:
16+
- exists:
17+
path: metadata.annotations.foo
18+
- equal:
19+
path: metadata.annotations.foo
20+
value: bar
21+
- it: should omit trafficDistribution by default
22+
asserts:
23+
- notExists:
24+
path: spec.trafficDistribution
25+
- it: should omit trafficDistribution when null
26+
set:
27+
service.trafficDistribution: null
28+
asserts:
29+
- notExists:
30+
path: spec.trafficDistribution

0 commit comments

Comments
 (0)