Skip to content

Commit

Permalink
Merge pull request #183 from kenmoini/182-patch
Browse files Browse the repository at this point in the history
Patch for Issue #182
  • Loading branch information
bdalpe authored Dec 13, 2023
2 parents 7a4a29a + 619fe5a commit 74712c8
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 5 deletions.
14 changes: 14 additions & 0 deletions helm-chart-sources/logstream-leader/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,17 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Join annotations passed in from values.yaml for Services
*/}}
{{- define "logstream-leader.service.annotations" -}}
{{- if eq .templateType "internal" }}
{{- $intAnnotations := (merge .Values.service.annotations .Values.service.internalAnnotations) -}}
{{ toYaml $intAnnotations }}
{{- end }}
{{- if eq .templateType "external" }}
{{- $extAnnotations := (merge .Values.service.annotations .Values.service.externalAnnotations) -}}
{{ toYaml $extAnnotations }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ metadata:
labels:
{{- include "logstream-leader.labels" . | nindent 4 }}
annotations:
{{- toYaml .Values.service.annotations | nindent 4 }}

{{- include "logstream-leader.service.annotations" (merge (dict "templateType" "internal") .) | nindent 4 }}
spec:
type: {{ .Values.service.internalType }}
ports:
Expand Down
3 changes: 1 addition & 2 deletions helm-chart-sources/logstream-leader/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ metadata:
labels:
{{- include "logstream-leader.labels" . | nindent 4 }}
annotations:
{{- toYaml .Values.service.annotations | nindent 4 }}

{{- include "logstream-leader.service.annotations" (merge (dict "templateType" "external") .) | nindent 4 }}
spec:
type: {{- if (eq $.Values.ingress.enable true) }} NodePort {{- else }} {{ .Values.service.externalType }} {{- end }}
ports:
Expand Down
94 changes: 94 additions & 0 deletions helm-chart-sources/logstream-leader/tests/service_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
suite: Service
templates:
- service.yaml
- service-internal.yaml
tests:
- it: Should not set annotations by default to the external service
template: service.yaml
asserts:
- equal:
path: metadata.annotations
value: {}

- it: Should not set annotations to the internal service
template: service-internal.yaml
asserts:
- equal:
path: metadata.annotations
value: {}

- it: Applies an annotation to the internal service that would be shared with the external service
template: service-internal.yaml
set:
service:
annotations:
foo: bar
asserts:
- equal:
path: metadata.annotations.foo
value: "bar"

- it: Applies an annotation to the external service that would be shared with the internal service
template: service.yaml
set:
service:
annotations:
foo: bar
asserts:
- equal:
path: metadata.annotations.foo
value: "bar"

- it: Applies an annotation to the internal service only
template: service-internal.yaml
set:
service:
internalAnnotations:
fizz: buzz
asserts:
- equal:
path: metadata.annotations.fizz
value: "buzz"

- it: Applies an annotation to the external service only
template: service.yaml
set:
service:
externalAnnotations:
fizz: buzz
asserts:
- equal:
path: metadata.annotations.fizz
value: "buzz"

- it: Applies an annotation to the external service only and also a shared annotation
template: service.yaml
set:
service:
annotations:
foo: 'bar'
externalAnnotations:
fizz: 'buzz'
asserts:
- equal:
path: metadata.annotations.foo
value: "bar"
- equal:
path: metadata.annotations.fizz
value: "buzz"

- it: Applies an annotation to the external service only and also a shared annotation
template: service-internal.yaml
set:
service:
annotations:
bar: 'foo'
internalAnnotations:
buzz: 'fizz'
asserts:
- equal:
path: metadata.annotations.bar
value: "foo"
- equal:
path: metadata.annotations.buzz
value: "fizz"
7 changes: 6 additions & 1 deletion helm-chart-sources/logstream-leader/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ env: {}
service:
internalType: ClusterIP
externalType: LoadBalancer
# annotations are shared between both the internal and external Service
annotations: {}
# internalAnnotations are only applied to the internal Service
internalAnnotations: {}
# externalAnnotations are only applied to the external Service
externalAnnotations: {}
ports:
- name: api
port: 9000
Expand Down Expand Up @@ -106,4 +111,4 @@ extraObjects: {}
# Applies extra labels to all resources deployed with this chart
extraLabels: {}
# key: value
# key2: value2
# key2: value2

0 comments on commit 74712c8

Please sign in to comment.