blob: 3bc99005973d7524328cadad292e141ad735246d [file] [log] [blame]
Andreas Geisslercde4a782024-02-28 16:08:06 +01001{{- /*
2Copyright VMware, Inc.
3SPDX-License-Identifier: APACHE-2.0
4*/}}
5
6{{- if and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled (not (eq .Values.externalAccess.service.type "ClusterIP")) }}
7{{- $fullName := include "mongodb.fullname" . }}
8{{- $replicaCount := .Values.replicaCount | int }}
9{{- $root := . }}
10
11{{- range $i, $e := until $replicaCount }}
12{{- $targetPod := printf "%s-%d" (printf "%s" $fullName) $i }}
13{{- $_ := set $ "targetPod" $targetPod }}
14apiVersion: v1
15kind: Service
16metadata:
17 name: {{ printf "%s-%d-external" $fullName $i }}
18 namespace: {{ include "mongodb.namespace" $ }}
19 labels: {{- include "common.labels.standard" ( dict "customLabels" $root.Values.commonLabels "context" $ ) | nindent 4 }}
20 app.kubernetes.io/component: mongodb
21 pod: {{ $targetPod }}
22 {{- if or $root.Values.externalAccess.service.annotations $root.Values.commonAnnotations }}
23 {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list $root.Values.externalAccess.service.annotations $root.Values.commonAnnotations ) "context" $ ) }}
24 annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
25 {{- end }}
26spec:
27 type: {{ $root.Values.externalAccess.service.type }}
28 {{- if eq $root.Values.externalAccess.service.type "LoadBalancer" }}
29 {{- if not (empty $root.Values.externalAccess.service.loadBalancerIPs) }}
30 loadBalancerIP: {{ index $root.Values.externalAccess.service.loadBalancerIPs $i }}
31 {{- end }}
32 {{- if and (eq $root.Values.externalAccess.service.type "LoadBalancer") $root.Values.externalAccess.service.loadBalancerClass }}
33 loadBalancerClass: {{ $root.Values.externalAccess.service.loadBalancerClass }}
34 {{- end }}
35 {{- if $root.Values.externalAccess.service.loadBalancerSourceRanges }}
36 loadBalancerSourceRanges: {{- toYaml $root.Values.externalAccess.service.loadBalancerSourceRanges | nindent 4 }}
37 {{- end }}
38 allocateLoadBalancerNodePorts: {{ $root.Values.externalAccess.service.allocateLoadBalancerNodePorts }}
39 {{- end }}
40 {{- if (or (eq $root.Values.externalAccess.service.type "LoadBalancer") (eq $root.Values.externalAccess.service.type "NodePort")) }}
41 externalTrafficPolicy: {{ $root.Values.externalAccess.service.externalTrafficPolicy | quote }}
42 {{- end }}
43 {{- if $root.Values.externalAccess.service.sessionAffinity }}
44 sessionAffinity: {{ $root.Values.externalAccess.service.sessionAffinity }}
45 {{- end }}
46 {{- if $root.Values.externalAccess.service.sessionAffinityConfig }}
47 sessionAffinityConfig: {{- include "common.tplvalues.render" (dict "value" $root.Values.externalAccess.service.sessionAffinityConfig "context" $) | nindent 4 }}
48 {{- end }}
49 publishNotReadyAddresses: true
50 ports:
51 - name: {{ $root.Values.externalAccess.service.portName | quote }}
52 port: {{ $root.Values.externalAccess.service.ports.mongodb }}
53 {{- if not (empty $root.Values.externalAccess.service.nodePorts) }}
54 {{- $nodePort := index $root.Values.externalAccess.service.nodePorts $i }}
55 nodePort: {{ $nodePort }}
56 {{- else }}
57 nodePort: null
58 {{- end }}
59 targetPort: mongodb
60 {{- if $root.Values.externalAccess.service.extraPorts }}
61 {{- include "common.tplvalues.render" (dict "value" $root.Values.externalAccess.service.extraPorts "context" $) | nindent 4 }}
62 {{- end }}
63 {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list $root.Values.podLabels $root.Values.commonLabels ) "context" $ ) }}
64 selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
65 app.kubernetes.io/component: mongodb
66 statefulset.kubernetes.io/pod-name: {{ $targetPod }}
67---
68{{- end }}
69{{- end }}