AlexRogalskiy/java-patterns

View on GitHub
charts/templates/service.yaml

Summary

Maintainability
Test Coverage
{{- if .Values.service.enabled }}
{{- $fullName := include "backend-java-patterns.fullname" . -}}
apiVersion: v1
kind: Service
metadata:
  name: {{ $fullName }}
  namespace: {{ .Release.Namespace | quote }}
  labels:
    {{ include "backend-java-patterns.labels" . | nindent 4 }}
  {{- if .Values.service.labels }}
  {{- with .Values.service.labels }}
    {{- toYaml . | nindent 4 }}
  {{- end }}
  {{- end }}
  {{- if .Values.service.annotations }}
  {{- with .Values.service.annotations }}
  annotations:
    {{- toYaml . | indent 4 }}
  {{- end }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  {{- if (or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort")) }}
  externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy | quote }}
  {{- end }}
  {{- if eq .Values.service.type "ClusterIP" }}
  {{- if eq .Values.general.architecture "high-availability" }}
  clusterIP: None
  {{- else if not (empty .Values.service.clusterIp) }}
  clusterIP: {{ .Values.service.clusterIp }}
  {{- end }}
  {{- end }}
  {{- if and (not (empty .Values.service.loadBalancerIP)) (eq .Values.service.type "LoadBalancer") }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{- end }}
  {{- if .Values.service.externalIPs }}
  externalIPs: {{ toYaml .Values.service.externalIPs | nindent 4 }}
  {{- end }}
  {{- if .Values.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges: {{- toYaml .Values.service.loadBalancerSourceRanges | nindent 4 }}
  {{- end }}
  ports:
    {{- if .Values.service.ports.http }}
    - port: {{ .Values.service.ports.http | int64 }}
      targetPort: http
      protocol: TCP
      name: http
      {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.http)) }}
      nodePort: {{ .Values.service.nodePorts.http }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- end }}
    {{- if .Values.service.ports.grpc }}
    - port: {{ .Values.service.ports.grpc | int64 }}
      targetPort: grpc
      protocol: TCP
      name: grpc
      {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.grpc)) }}
      nodePort: {{ .Values.service.nodePorts.grpc }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- end }}
    {{- if .Values.tls.enabled }}
    - port: {{ .Values.tls.httpPort | default 8000 | int64 }}
      targetPort: https
      protocol: TCP
      name: https
      {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.https)) }}
      nodePort: {{ .Values.service.nodePorts.https }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- end }}
  selector:
    {{- include "backend-java-patterns.selectorLabels" . | nindent 4 }}
{{- end }}