_ingress.tpl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Generate backend entry that is compatible with all Kubernetes API versions.
  4. Usage:
  5. {{ include "common.ingress.backend" (dict "serviceName" "backendName" "servicePort" "backendPort" "context" $) }}
  6. Params:
  7. - serviceName - String. Name of an existing service backend
  8. - servicePort - String/Int. Port name (or number) of the service. It will be translated to different yaml depending if it is a string or an integer.
  9. - context - Dict - Required. The context for the template evaluation.
  10. */}}
  11. {{- define "common.ingress.backend" -}}
  12. {{- $apiVersion := (include "common.capabilities.ingress.apiVersion" .context) -}}
  13. {{- if or (eq $apiVersion "extensions/v1beta1") (eq $apiVersion "networking.k8s.io/v1beta1") -}}
  14. serviceName: {{ .serviceName }}
  15. servicePort: {{ .servicePort }}
  16. {{- else -}}
  17. service:
  18. name: {{ .serviceName }}
  19. port:
  20. {{- if typeIs "string" .servicePort }}
  21. name: {{ .servicePort }}
  22. {{- else if or (typeIs "int" .servicePort) (typeIs "float64" .servicePort) }}
  23. number: {{ .servicePort | int }}
  24. {{- end }}
  25. {{- end -}}
  26. {{- end -}}
  27. {{/*
  28. Print "true" if the API pathType field is supported
  29. Usage:
  30. {{ include "common.ingress.supportsPathType" . }}
  31. */}}
  32. {{- define "common.ingress.supportsPathType" -}}
  33. {{- if (semverCompare "<1.18-0" (include "common.capabilities.kubeVersion" .)) -}}
  34. {{- print "false" -}}
  35. {{- else -}}
  36. {{- print "true" -}}
  37. {{- end -}}
  38. {{- end -}}