Skip to content

Commit

Permalink
Add "vector.portsOverrides" named template.
Browse files Browse the repository at this point in the history
This template is meant for those users that want the automatically
generated port definitions in the Service manifests but also needs to
make some overrides, or additions, to those definitions.
  • Loading branch information
bderrly committed Dec 6, 2024
1 parent 08506fd commit 933288b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
20 changes: 20 additions & 0 deletions charts/vector/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ Generate an array of ServicePorts based on `.Values.customConfig`.
{{- end }}
{{- end }}

{{/*
Returns a list of ports merged from services.portsOverrides and customConfigs.
*/}}
{{- define "vector.portsOverrides" -}}
{{- $mergedPorts := dict }}
{{- range $_, $svcPort := .Values.service.portsOverrides }}
{{- if not (hasKey $mergedPorts $svcPort.name) }}
{{- $_ := set $mergedPorts $svcPort.name $svcPort }}
{{- end }}
{{- end }}
{{- range $_, $customPort := (include "vector.ports" . | fromYamlArray) }}
{{- if (hasKey $mergedPorts $customPort.name) }}
{{- $_ := set $mergedPorts $customPort.name (get $mergedPorts $customPort.name | mergeOverwrite $customPort)}}
{{- else }}
{{- $_ := set $mergedPorts $customPort.name $customPort }}
{{- end }}
{{- end }}
{{- values $mergedPorts | toYaml }}
{{- end }}

{{/*
Iterate over the components defined in `.Values.customConfig`.
*/}}
Expand Down
6 changes: 5 additions & 1 deletion charts/vector/templates/service-headless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ spec:
{{- if or .Values.service.ports .Values.existingConfigMaps }}
{{- toYaml .Values.service.ports | nindent 4 }}
{{- else if .Values.customConfig }}
{{- include "vector.ports" . | indent 4 }}
{{- if .Values.service.portsOverrides }}
{{- include "vector.portsOverrides" . | nindent 4 }}
{{- else }}
{{- include "vector.ports" . | indent 4 }}
{{- end }}
{{- else }}
- name: datadog-agent
port: 8282
Expand Down
6 changes: 5 additions & 1 deletion charts/vector/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ spec:
{{- if or .Values.service.ports .Values.existingConfigMaps }}
{{- toYaml .Values.service.ports | nindent 4 }}
{{- else if .Values.customConfig }}
{{- include "vector.ports" . | indent 4 }}
{{- if .Values.service.portsOverrides }}
{{- include "vector.portsOverrides" . | nindent 4}}
{{- else }}
{{- include "vector.ports" . | indent 4 }}
{{- end }}
{{- else if or (eq .Values.role "Aggregator") (eq .Values.role "Stateless-Aggregator") }}
- name: datadog-agent
port: 8282
Expand Down
5 changes: 5 additions & 0 deletions charts/vector/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ service:
# - "*"
# service.ports -- Manually set the Service ports, overriding automated generation of Service ports.
ports: []
# service.portsOverrides -- Override auto-generated Service ports.
# You must define the name field for each dictionary for proper merging.
portsOverrides: []
# - name: vector
# appProtocol: grpc
# service.externalTrafficPolicy -- Specify the [externalTrafficPolicy](https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip).
externalTrafficPolicy: ""
# service.internalTrafficPolicy -- Specify the [internalTrafficPolicy]https://kubernetes.io/docs/concepts/services-networking/service-traffic-policy).
Expand Down

0 comments on commit 933288b

Please sign in to comment.