_ingress.tpl 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {{/*
  2. Copyright Broadcom, Inc. All Rights Reserved.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{/* vim: set filetype=mustache: */}}
  6. {{/*
  7. Generate backend entry that is compatible with all Kubernetes API versions.
  8. Usage:
  9. {{ include "common.ingress.backend" (dict "serviceName" "backendName" "servicePort" "backendPort" "context" $) }}
  10. Params:
  11. - serviceName - String. Name of an existing service backend
  12. - 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.
  13. - context - Dict - Required. The context for the template evaluation.
  14. */}}
  15. {{- define "common.ingress.backend" -}}
  16. {{- $apiVersion := (include "common.capabilities.ingress.apiVersion" .context) -}}
  17. {{- if or (eq $apiVersion "extensions/v1beta1") (eq $apiVersion "networking.k8s.io/v1beta1") -}}
  18. serviceName: {{ .serviceName }}
  19. servicePort: {{ .servicePort }}
  20. {{- else -}}
  21. service:
  22. name: {{ .serviceName }}
  23. port:
  24. {{- if typeIs "string" .servicePort }}
  25. name: {{ .servicePort }}
  26. {{- else if or (typeIs "int" .servicePort) (typeIs "float64" .servicePort) }}
  27. number: {{ .servicePort | int }}
  28. {{- end }}
  29. {{- end -}}
  30. {{- end -}}
  31. {{/*
  32. Print "true" if the API pathType field is supported
  33. Usage:
  34. {{ include "common.ingress.supportsPathType" . }}
  35. */}}
  36. {{- define "common.ingress.supportsPathType" -}}
  37. {{- if (semverCompare "<1.18-0" (include "common.capabilities.kubeVersion" .)) -}}
  38. {{- print "false" -}}
  39. {{- else -}}
  40. {{- print "true" -}}
  41. {{- end -}}
  42. {{- end -}}
  43. {{/*
  44. Returns true if the ingressClassname field is supported
  45. Usage:
  46. {{ include "common.ingress.supportsIngressClassname" . }}
  47. */}}
  48. {{- define "common.ingress.supportsIngressClassname" -}}
  49. {{- if semverCompare "<1.18-0" (include "common.capabilities.kubeVersion" .) -}}
  50. {{- print "false" -}}
  51. {{- else -}}
  52. {{- print "true" -}}
  53. {{- end -}}
  54. {{- end -}}
  55. {{/*
  56. Return true if cert-manager required annotations for TLS signed
  57. certificates are set in the Ingress annotations
  58. Ref: https://cert-manager.io/docs/usage/ingress/#supported-annotations
  59. Usage:
  60. {{ include "common.ingress.certManagerRequest" ( dict "annotations" .Values.path.to.the.ingress.annotations ) }}
  61. */}}
  62. {{- define "common.ingress.certManagerRequest" -}}
  63. {{ if or (hasKey .annotations "cert-manager.io/cluster-issuer") (hasKey .annotations "cert-manager.io/issuer") (hasKey .annotations "kubernetes.io/tls-acme") }}
  64. {{- true -}}
  65. {{- end -}}
  66. {{- end -}}