The Unified and Autonomous Development Platform
feat: Add Traefik ingress support in helmchart
christofferscf590a068d2a
diff --git a/server-product/helm/templates/certificate.yaml b/server-product/helm/templates/certificate.yamlnew file mode 100644index 0000000000..24af17b697--- /dev/null+++ b/server-product/helm/templates/certificate.yaml@@ -0,0 +1,25 @@+{{- $ingress := get .Values "ingress" | default dict -}}+{{- $traefik := get $ingress "traefik" | default dict -}}+{{- $traefikEnabled := get $traefik "enabled" | default false -}}++{{- if $traefikEnabled }}+{{- if and $.Values.ingress.tls.enabled $.Values.ingress.tls.acme.enabled }}+apiVersion: cert-manager.io/v1+kind: Certificate+metadata:+ name: {{ include "ods.fullname" . }}+spec:+ secretName: {{ .Values.ingress.tls.secretName }}+ issuerRef:+ name: {{ include "ods.fullname" . }}+ kind: Issuer+ dnsNames:+ {{- if .Values.ingress.traefik.hosts }}+ {{- range .Values.ingress.traefik.hosts }}+ - {{ . | quote }}+ {{- end }}+ {{- else }}+ - {{ .Values.ingress.host | quote }}+ {{- end }}+{{- end }}+{{- end }}diff --git a/server-product/helm/templates/ingress.yaml b/server-product/helm/templates/ingress.yamlindex 412f645728..6b45575b9d 100644--- a/server-product/helm/templates/ingress.yaml+++ b/server-product/helm/templates/ingress.yaml@@ -1,7 +1,18 @@+{{- $ingress := get .Values "ingress" | default dict -}}+{{- $traefik := get $ingress "traefik" | default dict -}}+{{- $traefikEnabled := get $traefik "enabled" | default false -}}+{{- if .Values.ingress.enabled -}}+{{- if not $traefikEnabled }}++{{- /* Default .Values.ingress.annotations to dict if nil AND reassign it */}}+{{- if not .Values.ingress.annotations -}}+ {{- $_ := set .Values.ingress "annotations" dict -}}+{{- end -}}+{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}- {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}+ {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className -}}{{- end }}{{- end }}{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}@@ -18,11 +29,21 @@ metadata:labels:{{ include "ods.labels" . | indent 4 }}annotations:- {{- if $.Values.ingress.tls.acme.enabled }}- cert-manager.io/issuer: "{{ include "ods.fullname" . }}"+ {{- $mergedAnnotations := dict }}+ {{- if and $.Values.ingress.tls.enabled $.Values.ingress.tls.acme.enabled }}+ {{- $_ := set $mergedAnnotations "cert-manager.io/issuer" (include "ods.fullname" .) }}{{- end }}{{- if .Values.ingress.annotations }}-{{ toYaml .Values.ingress.annotations | indent 4 }}+ {{- $mergedAnnotations = merge $mergedAnnotations (default dict .Values.ingress.annotations) }}+ {{- end }}+ {{- if get .Values.ingress "nginx" | default dict }}+ {{- $nginx := get .Values.ingress "nginx" | default dict }}+ {{- if $nginx.annotations }}+ {{- $mergedAnnotations = merge $mergedAnnotations (default dict $nginx.annotations) }}+ {{- end }}+ {{- end }}+ {{- if $mergedAnnotations }}+ {{- toYaml $mergedAnnotations | nindent 4 }}{{- end }}spec:{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}@@ -53,3 +74,72 @@ spec:servicePort: {{ default "80" .Values.service.ports.http }}{{- end }}{{- end }}+{{- if $traefikEnabled }}+apiVersion: traefik.io/v1alpha1+kind: IngressRouteTCP+metadata:+ name: {{ include "ods.fullname" . }}-ssh+ namespace: {{ .Release.Namespace }}+ labels:+{{ include "ods.labels" . | indent 4 }}+spec:+ entryPoints:+ - {{ .Values.ingress.traefik.sshEntryPoint }}+ routes:+ - match: HostSNI(`*`)+ services:+ - name: {{ include "ods.fullname" . }}{{- if .Values.service.separateSSH.enabled }}-ssh{{- end }}+ {{- if .Values.service.separateSSH.enabled }}+ port: {{ default .Values.service.ports.ssh .Values.service.separateSSH.port | default "22" }}+ {{- else }}+ port: {{ default "22" .Values.service.ports.ssh }}+ {{- end }}+---+apiVersion: traefik.io/v1alpha1+kind: IngressRoute+metadata:+ name: {{ include "ods.fullname" . }}+ namespace: {{ .Release.Namespace }}+ labels:+{{ include "ods.labels" . | indent 4 }}+spec:+ entryPoints:+ - {{ .Values.ingress.traefik.entryPoint }}+ routes:+ {{- if .Values.ingress.traefik.hosts }}+ {{- $hosts := list }}+ {{- range .Values.ingress.traefik.hosts }}+ {{- $hosts = append $hosts (regexReplaceAll "\\." . "\\.") }}+ {{- end }}+ - match: HostRegexp(`^({{ join "|" $hosts }})$`)+ {{- else }}+ - match: Host(`{{ .Values.ingress.host }}`)+ {{- end }}+ kind: Rule+ middlewares:+ - name: {{ include "ods.fullname" . }}-{{ .Values.ingress.traefik.middleware.name }}+ namespace: {{ .Release.Namespace }}+ services:+ - name: {{ include "ods.fullname" . }}+ port: {{ default "80" .Values.service.ports.http }}+ sticky:+ cookie:+ httpOnly: true+{{- if .Values.ingress.tls.enabled }}+ tls:+ secretName: {{ .Values.ingress.tls.secretName }}+{{- end }}+---+apiVersion: traefik.io/v1alpha1+kind: Middleware+metadata:+ name: {{ include "ods.fullname" . }}-{{ .Values.ingress.traefik.middleware.name }}+ namespace: {{ .Release.Namespace }}+ labels:+{{ include "ods.labels" . | indent 4 }}+spec:+ buffering:+ maxRequestBodyBytes: {{ int .Values.ingress.traefik.middleware.maxRequestBodyBytes }}+ memRequestBodyBytes: {{ int .Values.ingress.traefik.middleware.memRequestBodyBytes }}+{{- end }}+{{- end }}diff --git a/server-product/helm/templates/issuer.yaml b/server-product/helm/templates/issuer.yamlindex 1694daeb27..5550c5946b 100644--- a/server-product/helm/templates/issuer.yaml+++ b/server-product/helm/templates/issuer.yaml@@ -1,4 +1,4 @@-{{- if .Values.ingress.tls.acme.enabled -}}+{{- if and $.Values.ingress.tls.enabled $.Values.ingress.tls.acme.enabled -}}apiVersion: cert-manager.io/v1kind: Issuermetadata:diff --git a/server-product/helm/values.yaml b/server-product/helm/values.yamlindex 4c8f1fa6b8..e137f5c984 100644--- a/server-product/helm/values.yaml+++ b/server-product/helm/values.yaml@@ -20,7 +20,7 @@ onedev:trustCerts:# onedev.trustCerts.secretName -- Name of an existing secret containing trusted certificates. You may create the# secret with "kubectl create secret generic onedev-trustcerts -n onedev --from-file=/path/to/trust-certs",- # where /path/to/trust-certs is a local directory contains all certificates to be trusted. Certificate should be+ # where /path/to/trust-certs is a local directory contains all certificates to be trusted. Certificate should be# of base64 encoded PEM format beginning with "-----BEGIN CERTIFICATE-----" and ending with "-----END CERTIFICATE-----"secretName: "onedev-trustcerts"jvm:@@ -57,7 +57,7 @@ database:name: "onedev"# database.user -- User with access to databaseuser: "root"- # database.password -- Database password+ # database.password -- Database passwordpassword: "changeit"# database.maximumPoolSize -- Database maximum pool sizemaximumPoolSize: "25"@@ -179,11 +179,11 @@ service:http: ""ssh: ""# service.nodePort -- Specify a nodePort for servcie- nodePort: ""+ nodePort: ""# service.externalTrafficPolicy -- Specify the# [externalTrafficPolicy](https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip).externalTrafficPolicy: ""- # service.loadBalancerIP -- Required: If service type is loadbalancer+ # service.loadBalancerIP -- Required: If service type is loadbalancer# [loadBalancerIP](https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer).loadBalancerIP: ""# service.ipFamilyPolicy -- Configure@@ -217,14 +217,6 @@ ingress:# ingress.className -- Specify ingress class name. Requires Kubernetes >= 1.18.# Refer to https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/#specifying-the-class-of-an-ingress for detailsclassName: ""- # ingress.annotations -- Specify annotations for the Ingress.- annotations:- nginx.ingress.kubernetes.io/affinity: "cookie"- nginx.ingress.kubernetes.io/affinity-mode: "persistent"- nginx.ingress.kubernetes.io/session-cookie-name: "session-sticky"- nginx.ingress.kubernetes.io/session-cookie-expires: "172800"- nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"- nginx.ingress.kubernetes.io/proxy-body-size: "0"# ingress.host -- Set the host namehost: onedev.example.com@@ -244,6 +236,28 @@ ingress:# rate limit while you are testing your setupproduction: false+ # Nginx configuration+ nginx:+ annotations:+ nginx.ingress.kubernetes.io/affinity: "cookie"+ nginx.ingress.kubernetes.io/affinity-mode: "persistent"+ nginx.ingress.kubernetes.io/session-cookie-name: "session-sticky"+ nginx.ingress.kubernetes.io/session-cookie-expires: "172800"+ nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"+ nginx.ingress.kubernetes.io/proxy-body-size: "0"+ traefik:+ enabled: false+ entryPoint: websecure+ sshEntryPoint: gitssh+ # Used hostPattern if Regex matching is needed for multiple hostnames. If not set host is used.+ #hosts:+ # - code.example.com+ # - code.int.example.com+ # ingress.middleware -- Specify middleware for the Ingress.+ middleware:+ name: "buffering"+ maxRequestBodyBytes: 1073741824+ memRequestBodyBytes: 1073741824# extraVolumes -- Specify additional Volumes to use.extraVolumes: []