|
| 1 | +{{/* |
| 2 | +Return the ingress class name |
| 3 | +*/}} |
| 4 | +{{- define "theiacloud.ingress.className" -}} |
| 5 | +{{- if .Values.ingress.ingressClassName -}} |
| 6 | +{{ .Values.ingress.ingressClassName }} |
| 7 | +{{- else if eq .Values.ingress.controller "nginx" -}} |
| 8 | +nginx |
| 9 | +{{- else -}} |
| 10 | +{{ .Values.ingress.controller }} |
| 11 | +{{- end -}} |
| 12 | +{{- end -}} |
| 13 | + |
| 14 | +{{/* |
| 15 | +Return the annotations for the instances ingress |
| 16 | +*/}} |
| 17 | +{{- define "theiacloud.ingress.instances.annotations" -}} |
| 18 | +{{- $annotations := dict -}} |
| 19 | +{{- if .Values.ingress.instances.annotations -}} |
| 20 | +{{- $annotations = .Values.ingress.instances.annotations -}} |
| 21 | +{{- else -}} |
| 22 | +{{- if eq .Values.ingress.controller "nginx" -}} |
| 23 | +{{- $annotations = include "theiacloud.ingress.nginx.instances.defaultAnnotations" . | fromYaml | default (dict) -}} |
| 24 | +{{- end -}} |
| 25 | +{{- end -}} |
| 26 | +{{- $certAnnotations := include "theiacloud.ingress.certManagerAnnotations" . | fromYaml | default (dict) -}} |
| 27 | +{{- $annotations = merge $annotations $certAnnotations -}} |
| 28 | +{{- $annotations | toYaml -}} |
| 29 | +{{- end -}} |
| 30 | + |
| 31 | +{{/* |
| 32 | +Return the annotations for the landing page ingress |
| 33 | +*/}} |
| 34 | +{{- define "theiacloud.ingress.landingPage.annotations" -}} |
| 35 | +{{- $annotations := dict -}} |
| 36 | +{{- if .Values.ingress.landingPage.annotations -}} |
| 37 | +{{- $annotations = .Values.ingress.landingPage.annotations -}} |
| 38 | +{{- else -}} |
| 39 | +{{- if eq .Values.ingress.controller "nginx" -}} |
| 40 | +{{- $annotations = include "theiacloud.ingress.nginx.landingPage.defaultAnnotations" . | fromYaml | default (dict) -}} |
| 41 | +{{- end -}} |
| 42 | +{{- end -}} |
| 43 | +{{- $certAnnotations := include "theiacloud.ingress.certManagerAnnotations" (dict "root" . "includeHttp01" false) | fromYaml | default (dict) -}} |
| 44 | +{{- $annotations = merge $annotations $certAnnotations -}} |
| 45 | +{{- $annotations | toYaml -}} |
| 46 | +{{- end -}} |
| 47 | + |
| 48 | +{{/* |
| 49 | +Return the annotations for the service ingress |
| 50 | +*/}} |
| 51 | +{{- define "theiacloud.ingress.service.annotations" -}} |
| 52 | +{{- $annotations := dict -}} |
| 53 | +{{- if .Values.ingress.service.annotations -}} |
| 54 | +{{- $annotations = .Values.ingress.service.annotations -}} |
| 55 | +{{- else -}} |
| 56 | +{{- if eq .Values.ingress.controller "nginx" -}} |
| 57 | +{{- $annotations = include "theiacloud.ingress.nginx.service.defaultAnnotations" . | fromYaml | default (dict) -}} |
| 58 | +{{- end -}} |
| 59 | +{{- end -}} |
| 60 | +{{- $certAnnotations := include "theiacloud.ingress.certManagerAnnotations" . | fromYaml | default (dict) -}} |
| 61 | +{{- $annotations = merge $annotations $certAnnotations -}} |
| 62 | +{{- $annotations | toYaml -}} |
| 63 | +{{- end -}} |
| 64 | + |
| 65 | +{{/* |
| 66 | +Return default nginx annotations for instances ingress |
| 67 | +*/}} |
| 68 | +{{- define "theiacloud.ingress.nginx.instances.defaultAnnotations" -}} |
| 69 | +{{- if not .Values.ingress.tls }} |
| 70 | +nginx.ingress.kubernetes.io/ssl-redirect: "false" |
| 71 | +{{- end }} |
| 72 | +nginx.ingress.kubernetes.io/proxy-buffer-size: "128k" |
| 73 | +nginx.ingress.kubernetes.io/rewrite-target: /$2 |
| 74 | +{{- if .Values.ingress.instances.configurationSnippets }} |
| 75 | +nginx.ingress.kubernetes.io/configuration-snippet: | |
| 76 | + {{- range .Values.ingress.instances.configurationSnippets }} |
| 77 | + {{ . }}; |
| 78 | + {{- end }} |
| 79 | +{{- else }} |
| 80 | +nginx.ingress.kubernetes.io/configuration-snippet: | |
| 81 | + proxy_set_header 'X-Forwarded-Uri' $request_uri; |
| 82 | +{{- end }} |
| 83 | +nginx.ingress.kubernetes.io/proxy-body-size: {{ tpl (.Values.ingress.instances.proxyBodySize | toString) . }} |
| 84 | +{{- end -}} |
| 85 | + |
| 86 | +{{/* |
| 87 | +Return default nginx annotations for landing page ingress (path-based) |
| 88 | +*/}} |
| 89 | +{{- define "theiacloud.ingress.nginx.landingPage.defaultAnnotations" -}} |
| 90 | +{{- if not .Values.ingress.tls }} |
| 91 | +nginx.ingress.kubernetes.io/ssl-redirect: "false" |
| 92 | +{{- end }} |
| 93 | +{{- if .Values.hosts.usePaths }} |
| 94 | +{{- if .Values.hosts.configuration.landing }} |
| 95 | +nginx.ingress.kubernetes.io/rewrite-target: /$2 |
| 96 | +{{- end }} |
| 97 | +nginx.ingress.kubernetes.io/configuration-snippet: | |
| 98 | + rewrite ^([^.?]*[^/])$ $1/ redirect; |
| 99 | +{{- end }} |
| 100 | +{{- end -}} |
| 101 | + |
| 102 | +{{/* |
| 103 | +Return default nginx annotations for service ingress |
| 104 | +*/}} |
| 105 | +{{- define "theiacloud.ingress.nginx.service.defaultAnnotations" -}} |
| 106 | +{{- if not .Values.ingress.tls }} |
| 107 | +nginx.ingress.kubernetes.io/ssl-redirect: "false" |
| 108 | +{{- end }} |
| 109 | +nginx.ingress.kubernetes.io/rewrite-target: /service$1 |
| 110 | +{{- end -}} |
| 111 | + |
| 112 | +{{/* |
| 113 | +Return cert-manager annotations if enabled |
| 114 | +Params: |
| 115 | + . - root context |
| 116 | + includeHttp01 - (optional) whether to include HTTP-01 specific annotations |
| 117 | +*/}} |
| 118 | +{{- define "theiacloud.ingress.certManagerAnnotations" -}} |
| 119 | +{{- $includeHttp01 := true -}} |
| 120 | +{{- if hasKey . "includeHttp01" -}} |
| 121 | +{{- $includeHttp01 = .includeHttp01 -}} |
| 122 | +{{- end -}} |
| 123 | +{{- $root := . -}} |
| 124 | +{{- if hasKey . "root" -}} |
| 125 | +{{- $root = .root -}} |
| 126 | +{{- end -}} |
| 127 | +{{- if $root.Values.ingress.addTLSSecretName }} |
| 128 | +{{- if $root.Values.ingress.certManagerAnnotations }} |
| 129 | +cert-manager.io/cluster-issuer: {{ tpl ($root.Values.ingress.clusterIssuer | toString) $root }} |
| 130 | +{{- if and $includeHttp01 $root.Values.ingress.theiaCloudCommonName }} |
| 131 | +cert-manager.io/common-name: "Theia Cloud" |
| 132 | +{{- end }} |
| 133 | +{{- if $includeHttp01 }} |
| 134 | +acme.cert-manager.io/http01-ingress-class: {{ include "theiacloud.ingress.className" $root }} |
| 135 | +{{- end }} |
| 136 | +{{- end }} |
| 137 | +{{- end }} |
| 138 | +{{- end -}} |
0 commit comments