_ingress.tpl 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 -}}
  39. {{/*
  40. Returns true if the ingressClassname field is supported
  41. Usage:
  42. {{ include "common.ingress.supportsIngressClassname" . }}
  43. */}}
  44. {{- define "common.ingress.supportsIngressClassname" -}}
  45. {{- if semverCompare "<1.18-0" (include "common.capabilities.kubeVersion" .) -}}
  46. {{- print "false" -}}
  47. {{- else -}}
  48. {{- print "true" -}}
  49. {{- end -}}
  50. {{- end -}}
  51. {{/*
  52. Return true if cert-manager required annotations for TLS signed
  53. certificates are set in the Ingress annotations
  54. Ref: https://cert-manager.io/docs/usage/ingress/#supported-annotations
  55. Usage:
  56. {{ include "common.ingress.certManagerRequest" ( dict "annotations" .Values.path.to.the.ingress.annotations ) }}
  57. */}}
  58. {{- define "common.ingress.certManagerRequest" -}}
  59. {{ if or (hasKey .annotations "cert-manager.io/cluster-issuer") (hasKey .annotations "cert-manager.io/issuer") (hasKey .annotations "kubernetes.io/tls-acme") }}
  60. {{- true -}}
  61. {{- end -}}
  62. {{- end -}}