service.yaml 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. {{- $ctx := dict "helm" . }}
  2. {{- range $name, $app := .Values }}
  3. {{- if and (kindIs "map" $app) $app.enabled ($app.service).enabled }}
  4. {{- $service := $app.service }}
  5. {{- $_ := set $ctx "extraLabels" $service.labels }}
  6. {{- $_ := set $ctx "appKey" $name }}
  7. {{- $fullname := include "vm.plain.fullname" $ctx }}
  8. ---
  9. apiVersion: v1
  10. kind: Service
  11. metadata:
  12. {{- with $service.annotations }}
  13. annotations: {{ toYaml . | nindent 4 }}
  14. {{- end }}
  15. labels: {{ include "vm.labels" $ctx | nindent 4 }}
  16. {{- $_ := unset $ctx "extraLabels" }}
  17. name: {{ $fullname }}
  18. namespace: {{ include "vm.namespace" $ }}
  19. spec:
  20. {{- $clusterIP := $service.clusterIP }}
  21. {{- if and (not $clusterIP) ($app.statefulSet).enabled }}
  22. {{- $clusterIP = "None" }}
  23. {{- end }}
  24. {{- with $clusterIP }}
  25. clusterIP: {{ . }}
  26. {{- end }}
  27. {{- with $service.externalIPs }}
  28. externalIPs: {{ toYaml . | nindent 4 }}
  29. {{- end }}
  30. {{- with $service.loadBalancerIP }}
  31. loadBalancerIP: {{ . }}
  32. {{- end }}
  33. {{- with $service.loadBalancerSourceRanges }}
  34. loadBalancerSourceRanges: {{ toYaml . | nindent 4 }}
  35. {{- end }}
  36. {{- $type := $service.type }}
  37. {{- if and (not $type) ($app.statefulSet).enabled }}
  38. {{- $type = "ClusterIP" }}
  39. {{- end }}
  40. type: {{ $type }}
  41. {{- with $service.healthCheckNodePort }}
  42. healthCheckNodePort: {{ . }}
  43. {{- end }}
  44. {{- with $service.externalTrafficPolicy }}
  45. externalTrafficPolicy: {{ . }}
  46. {{- end }}
  47. {{- with $service.ipFamilyPolicy }}
  48. ipFamilyPolicy: {{ . }}
  49. {{- end }}
  50. {{- with $service.ipFamilies }}
  51. ipFamilies: {{ toYaml . | nindent 4 }}
  52. {{- end }}
  53. {{- $portsTpl := printf "%s.ports" $name }}
  54. {{- with include $portsTpl $app }}
  55. ports: {{ . | nindent 4 }}
  56. {{- end }}
  57. selector: {{ include "vm.selectorLabels" $ctx | nindent 4 }}
  58. {{- end }}
  59. {{- end }}