_ports.tpl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. {{/* Service - Ports */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.service.ports" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
  4. rootCtx: The root context of the chart.
  5. objectData: The object data of the service
  6. */}}
  7. {{- define "ix.v1.common.lib.service.ports" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- $tcpProtocols := (list "tcp" "http" "https") -}}
  11. {{- range $name, $portValues := $objectData.ports -}}
  12. {{- if $portValues.enabled -}}
  13. {{- $protocol := $rootCtx.Values.fallbackDefaults.serviceProtocol -}} {{/* Default to fallback protocol, if no protocol is defined */}}
  14. {{- $port := $portValues.port -}}
  15. {{- $targetPort := $portValues.targetPort -}}
  16. {{- $nodePort := $portValues.nodePort -}}
  17. {{/* Expand port */}}
  18. {{- if (kindIs "string" $port) -}}
  19. {{- $port = (tpl $port $rootCtx) -}}
  20. {{- end -}}
  21. {{- $port = int $port -}}
  22. {{/* Expand targetPort */}}
  23. {{- if (kindIs "string" $targetPort) -}}
  24. {{- $targetPort = tpl $targetPort $rootCtx -}}
  25. {{- end -}}
  26. {{- $targetPort = int $targetPort -}}
  27. {{/* Expand nodePort */}}
  28. {{- if (kindIs "string" $nodePort) -}}
  29. {{- $nodePort = tpl $nodePort $rootCtx -}}
  30. {{- end -}}
  31. {{- $nodePort = int $nodePort -}}
  32. {{- with $portValues.protocol -}}
  33. {{- $protocol = tpl . $rootCtx -}}
  34. {{- if mustHas $protocol $tcpProtocols -}}
  35. {{- $protocol = "tcp" -}}
  36. {{- end -}}
  37. {{- end }}
  38. - name: {{ $name }}
  39. port: {{ $port }}
  40. protocol: {{ $protocol | upper }}
  41. targetPort: {{ $targetPort | default $port }} {{/* If no targetPort, default to port */}}
  42. {{- if (eq $objectData.type "NodePort") -}}
  43. {{- if not $nodePort -}}
  44. {{- fail "Service - Expected non-empty <nodePort> on NodePort service type" -}}
  45. {{- end -}}
  46. {{- $minNodePort := int $rootCtx.Values.global.minNodePort -}}
  47. {{- if (lt $nodePort $minNodePort) -}}
  48. {{- fail (printf "Service - Expected <nodePort> to be higher than [%v], but got [%v]" $minNodePort $nodePort) -}}
  49. {{- end }}
  50. nodePort: {{ $nodePort }}
  51. {{- end -}}
  52. {{- end -}}
  53. {{- end -}}
  54. {{- end -}}