_service.tpl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. {{/*
  2. This template serves as a blueprint for all Service objects that are created
  3. within the common library.
  4. */}}
  5. {{- define "common.classes.service" -}}
  6. {{- $values := .service -}}
  7. {{- $serviceName := include "common.names.fullname" . -}}
  8. {{- if hasKey $values "nameSuffix" -}}
  9. {{- $serviceName = printf "%v-%v" $serviceName $values.nameSuffix -}}
  10. {{ end -}}
  11. {{- $svcType := $values.type | default "" -}}
  12. apiVersion: v1
  13. kind: Service
  14. metadata:
  15. name: {{ $serviceName }}
  16. labels:
  17. {{- include "common.labels" . | nindent 4 }}
  18. {{- if $values.labels }}
  19. {{ toYaml $values.labels | nindent 4 }}
  20. {{- end }}
  21. {{- if $values.annotations }}
  22. {{- with $values.annotations }}
  23. annotations:
  24. {{ toYaml . | nindent 4 }}
  25. {{- end }}
  26. {{- end }}
  27. spec:
  28. {{- if (or (eq $svcType "ClusterIP") (empty $svcType)) }}
  29. type: ClusterIP
  30. {{- if $values.clusterIP }}
  31. clusterIP: {{ $values.clusterIP }}
  32. {{end}}
  33. {{- else if eq $svcType "NodePort" }}
  34. type: {{ $svcType }}
  35. {{- else }}
  36. {{- fail "Only ClusterIP and NodePort services are supported in common chart" }}
  37. {{- end }}
  38. {{- include "common.classes.service.ports" (dict "svcType" $svcType "values" $values ) | trim | nindent 2 }}
  39. selector:
  40. {{- include "common.labels.selectorLabels" . | nindent 4 }}
  41. {{- end }}