_ports.tpl 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. {{/* Returns ports list */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.container.ports" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData: The object data to be used to render the container.
  6. */}}
  7. {{- define "ix.v1.common.lib.container.ports" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- range $serviceName, $serviceValues := $rootCtx.Values.service -}}
  11. {{- $podSelected := false -}}
  12. {{/* If service is enabled... */}}
  13. {{- if $serviceValues.enabled -}}
  14. {{/* If there is a selector */}}
  15. {{- if $serviceValues.targetSelector -}}
  16. {{/* And pod is selected */}}
  17. {{- if eq $serviceValues.targetSelector $objectData.podShortName -}}
  18. {{- $podSelected = true -}}
  19. {{- end -}}
  20. {{- else -}}
  21. {{/* If no selector is defined but pod is primary */}}
  22. {{- if $objectData.podPrimary -}}
  23. {{- $podSelected = true -}}
  24. {{- end -}}
  25. {{- end -}}
  26. {{- end -}}
  27. {{- if $podSelected -}}
  28. {{- range $portName, $portValues := $serviceValues.ports -}}
  29. {{- $containerSelected := false -}}
  30. {{/* If service is enabled... */}}
  31. {{- if $portValues.enabled -}}
  32. {{/* If there is a selector */}}
  33. {{- if $portValues.targetSelector -}}
  34. {{/* And container is selected */}}
  35. {{- if eq $portValues.targetSelector $objectData.shortName -}}
  36. {{- $containerSelected = true -}}
  37. {{- end -}}
  38. {{- else -}}
  39. {{/* If no selector is defined but contaienr is primary */}}
  40. {{- if $objectData.primary -}}
  41. {{- $containerSelected = true -}}
  42. {{- end -}}
  43. {{- end -}}
  44. {{- end -}}
  45. {{/* If the container is selected render port */}}
  46. {{- if $containerSelected -}}
  47. {{- $containerPort := $portValues.targetPort | default $portValues.port -}}
  48. {{- if kindIs "string" $containerPort -}}
  49. {{- $containerPort = (tpl $containerPort $rootCtx) -}}
  50. {{- end -}}
  51. {{- $tcpProtocols := (list "tcp" "http" "https") -}}
  52. {{- $protocol := tpl ($portValues.protocol | default $rootCtx.Values.fallbackDefaults.serviceProtocol) $rootCtx -}}
  53. {{- if mustHas $protocol $tcpProtocols -}}
  54. {{- $protocol = "tcp" -}}
  55. {{- end }}
  56. - name: {{ $portName }}
  57. containerPort: {{ $containerPort }}
  58. protocol: {{ $protocol | upper }}
  59. {{- with $portValues.hostPort }}
  60. hostPort: {{ . }}
  61. {{- end -}}
  62. {{- end -}}
  63. {{- end -}}
  64. {{- end -}}
  65. {{- end -}}
  66. {{- end -}}