svc.yaml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. {{- /*
  2. Copyright VMware, Inc.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. apiVersion: v1
  6. kind: Service
  7. metadata:
  8. name: {{ include "postgresql.v1.primary.fullname" . }}
  9. namespace: {{ .Release.Namespace | quote }}
  10. labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  11. app.kubernetes.io/component: primary
  12. {{- if or .Values.commonAnnotations .Values.primary.service.annotations }}
  13. {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.primary.service.annotations .Values.commonAnnotations ) "context" . ) }}
  14. annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  15. {{- end }}
  16. spec:
  17. type: {{ .Values.primary.service.type }}
  18. {{- if or (eq .Values.primary.service.type "LoadBalancer") (eq .Values.primary.service.type "NodePort") }}
  19. externalTrafficPolicy: {{ .Values.primary.service.externalTrafficPolicy | quote }}
  20. {{- end }}
  21. {{- if and (eq .Values.primary.service.type "LoadBalancer") (not (empty .Values.primary.service.loadBalancerSourceRanges)) }}
  22. loadBalancerSourceRanges: {{ .Values.primary.service.loadBalancerSourceRanges | toJson}}
  23. {{- end }}
  24. {{- if and (eq .Values.primary.service.type "LoadBalancer") (not (empty .Values.primary.service.loadBalancerIP)) }}
  25. loadBalancerIP: {{ .Values.primary.service.loadBalancerIP }}
  26. {{- end }}
  27. {{- if and .Values.primary.service.clusterIP (eq .Values.primary.service.type "ClusterIP") }}
  28. clusterIP: {{ .Values.primary.service.clusterIP }}
  29. {{- end }}
  30. {{- if .Values.primary.service.sessionAffinity }}
  31. sessionAffinity: {{ .Values.primary.service.sessionAffinity }}
  32. {{- end }}
  33. {{- if .Values.primary.service.sessionAffinityConfig }}
  34. sessionAffinityConfig: {{- include "common.tplvalues.render" (dict "value" .Values.primary.service.sessionAffinityConfig "context" $) | nindent 4 }}
  35. {{- end }}
  36. ports:
  37. - name: tcp-postgresql
  38. port: {{ template "postgresql.v1.service.port" . }}
  39. targetPort: tcp-postgresql
  40. {{- if and (or (eq .Values.primary.service.type "NodePort") (eq .Values.primary.service.type "LoadBalancer")) (not (empty .Values.primary.service.nodePorts.postgresql)) }}
  41. nodePort: {{ .Values.primary.service.nodePorts.postgresql }}
  42. {{- else if eq .Values.primary.service.type "ClusterIP" }}
  43. nodePort: null
  44. {{- end }}
  45. {{- if .Values.primary.service.extraPorts }}
  46. {{- include "common.tplvalues.render" (dict "value" .Values.primary.service.extraPorts "context" $) | nindent 4 }}
  47. {{- end }}
  48. {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.primary.podLabels .Values.commonLabels ) "context" . ) }}
  49. selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
  50. app.kubernetes.io/component: primary