From 4cac4589847184c4154e9d37072b94a1eb04d358 Mon Sep 17 00:00:00 2001 From: Jesper Svendsen <99078145+jesper7@users.noreply.github.com> Date: Thu, 18 May 2023 15:07:38 +0200 Subject: [PATCH] Add base path support (#96) * Add base path support * Remove trailing - * Add base path support to Studio Ingress * Remove trailing slash in the ingress rule for UI * Use template for base path * Split Ingress resources * Add regex groups to paths * Fix regex in paths * Fix borked installation when basePath is set to / * Fix UI health check endpoint * Don't strip path prefix in UI * Revert "Fix UI health check endpoint" This reverts commit d5599a772bf5ffd6513e75ec52ddf7aa5e1943d8. * Add BASE_PATH variable for Studio frontend * Revert "Add BASE_PATH variable for Studio frontend" This reverts commit 65b02373ee35ab5a410bc3b4116adf7811db4078. * Revert "Revert "Fix UI health check endpoint"" This reverts commit 67d95b812f73f2686c4aa706c76686efcfbb004c. * /api/health -> /fapi/health * Set BASE_PATH automatically * Update charts/studio/templates/ingress-studio-webhook.yaml Co-authored-by: Marcin Jasion <5058132+mjasion@users.noreply.github.com> * Update charts/studio/templates/ingress-studio-ui.yaml Co-authored-by: Marcin Jasion <5058132+mjasion@users.noreply.github.com> * Update charts/studio/templates/ingress-studio-api.yaml Co-authored-by: Marcin Jasion <5058132+mjasion@users.noreply.github.com> * Update charts/studio/templates/deployment-studio-ui.yaml Co-authored-by: Marcin Jasion <5058132+mjasion@users.noreply.github.com> * Fix version * Fix version again * Upgrade appVersion in chart --------- Co-authored-by: Marcin Jasion <5058132+mjasion@users.noreply.github.com> --- charts/studio/Chart.yaml | 4 +- charts/studio/templates/_helpers.tpl | 5 ++ charts/studio/templates/configmap-studio.yaml | 13 ++-- .../templates/deployment-studio-ui.yaml | 6 +- .../studio/templates/ingress-blobvault.yaml | 4 ++ .../studio/templates/ingress-studio-api.yaml | 60 +++++++++++++++++++ .../studio/templates/ingress-studio-ui.yaml | 57 ++++++++++++++++++ ...tudio.yaml => ingress-studio-webhook.yaml} | 39 +++--------- charts/studio/values.yaml | 2 + 9 files changed, 152 insertions(+), 38 deletions(-) create mode 100644 charts/studio/templates/ingress-studio-api.yaml create mode 100644 charts/studio/templates/ingress-studio-ui.yaml rename charts/studio/templates/{ingress-studio.yaml => ingress-studio-webhook.yaml} (63%) diff --git a/charts/studio/Chart.yaml b/charts/studio/Chart.yaml index e3543d7e..07dde6df 100644 --- a/charts/studio/Chart.yaml +++ b/charts/studio/Chart.yaml @@ -15,13 +15,13 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.26 +version: 0.1.27 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "v1.59.0" +appVersion: "v1.78.0" dependencies: - name: nginx diff --git a/charts/studio/templates/_helpers.tpl b/charts/studio/templates/_helpers.tpl index 6f60e3c7..08b23348 100644 --- a/charts/studio/templates/_helpers.tpl +++ b/charts/studio/templates/_helpers.tpl @@ -124,3 +124,8 @@ checksum/configmap-studio: {{ include (print $.Template.BasePath "/configmap-stu checksum/configmap-ca-cert: {{ include (print $.Template.BasePath "/configmap-ca-cert.yaml") . | sha256sum }} checksum/secret-studio: {{ include (print $.Template.BasePath "/secret-studio.yaml") . | sha256sum }} {{- end }} + + +{{- define "studio.basePath" -}} +{{- printf "%s" .Values.global.basePath | trimPrefix "/" | trimSuffix "/" }} +{{- end }} diff --git a/charts/studio/templates/configmap-studio.yaml b/charts/studio/templates/configmap-studio.yaml index 5ce44a93..91795139 100644 --- a/charts/studio/templates/configmap-studio.yaml +++ b/charts/studio/templates/configmap-studio.yaml @@ -8,8 +8,12 @@ data: {{- end }} ALLOWED_HOSTS: "*" - API_URL: "http{{ if $.Values.global.ingress.tlsEnabled }}s{{ end }}://{{.Values.global.host }}/api" - UI_URL: "http{{ if $.Values.global.ingress.tlsEnabled }}s{{ end }}://{{.Values.global.host }}/" + API_URL: "http{{ if $.Values.global.ingress.tlsEnabled }}s{{ end }}://{{.Values.global.host }}{{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }}/{{ include "studio.basePath" . }}{{- end }}/api" + UI_URL: "http{{ if $.Values.global.ingress.tlsEnabled }}s{{ end }}://{{.Values.global.host }}/{{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }}{{ include "studio.basePath" . }}{{- end }}" + + {{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }} + BASE_PATH: /{{ include "studio.basePath" . }} + {{- end }} {{- if .Values.global.scmProviders.bitbucket.url }} BITBUCKET_URL: {{.Values.global.scmProviders.bitbucket.url | quote }} @@ -35,8 +39,8 @@ data: {{- else }} BLOBVAULT_LOCAL_ENABLED: "True" BLOBVAULT_LOCAL_PATH: "/blobvault" - BLOBVAULT_ENDPOINT_URL: "http{{ if $.Values.global.ingress.tlsEnabled }}s{{ end }}://{{.Values.global.host }}/blobvault" - BLOBVAULT_ENDPOINT_URL_FE: "http{{ if $.Values.global.ingress.tlsEnabled }}s{{ end }}://{{.Values.global.host }}/blobvault" + BLOBVAULT_ENDPOINT_URL: "http{{ if $.Values.global.ingress.tlsEnabled }}s{{ end }}://{{.Values.global.host }}{{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }}/{{ include "studio.basePath" . }}{{- end }}/blobvault" + BLOBVAULT_ENDPOINT_URL_FE: "http{{ if $.Values.global.ingress.tlsEnabled }}s{{ end }}://{{.Values.global.host }}{{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }}/{{ include "studio.basePath" . }}{{- end }}/blobvault" {{- end }} {{- if .Values.global.celery.brokerUrl }} @@ -109,4 +113,3 @@ data: {{- else }} SOCIAL_AUTH_ALLOWED_REDIRECT_HOSTS: "studio-ui.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.studioUi.service.port }},studio-backend.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.studioBackend.service.port }}" {{- end }} - diff --git a/charts/studio/templates/deployment-studio-ui.yaml b/charts/studio/templates/deployment-studio-ui.yaml index bbbfc6d6..2fed6cf5 100644 --- a/charts/studio/templates/deployment-studio-ui.yaml +++ b/charts/studio/templates/deployment-studio-ui.yaml @@ -45,7 +45,11 @@ spec: periodSeconds: 10 readinessProbe: httpGet: - path: /api/health + {{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }} + path: /{{ include "studio.basePath" . }}/{{- if semverCompare ">=1.78.0" (.Values.studioUi.image.tag | default .Chart.AppVersion) }}f{{end}}api/health + {{- else }} + path: /{{- if semverCompare ">=1.78.0" (.Values.studioUi.image.tag | default .Chart.AppVersion) }}f{{end}}api/health + {{- end }} port: 3000 initialDelaySeconds: 5 periodSeconds: 25 diff --git a/charts/studio/templates/ingress-blobvault.yaml b/charts/studio/templates/ingress-blobvault.yaml index 1f574273..f4355a46 100644 --- a/charts/studio/templates/ingress-blobvault.yaml +++ b/charts/studio/templates/ingress-blobvault.yaml @@ -32,7 +32,11 @@ spec: rules: - http: paths: + {{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }} + - path: /{{ include "studio.basePath" . }}/blobvault(/|$)(.*) + {{- else }} - path: /blobvault(/|$)(.*) + {{- end }} {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }} pathType: ImplementationSpecific {{- end }} diff --git a/charts/studio/templates/ingress-studio-api.yaml b/charts/studio/templates/ingress-studio-api.yaml new file mode 100644 index 00000000..f6f67a5f --- /dev/null +++ b/charts/studio/templates/ingress-studio-api.yaml @@ -0,0 +1,60 @@ +{{- if .Values.global.ingress.enabled -}} +{{- if and .Values.global.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.global.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.global.ingress.annotations "kubernetes.io/ingress.class" .Values.global.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ .Release.Name }}-studio-api + labels: + {{- include "studio-ui.labels" . | nindent 4 }} + annotations: + {{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }} + nginx.ingress.kubernetes.io/rewrite-target: /$1 + {{- end }} + {{- with .Values.global.ingress.annotations }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.global.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.global.ingress.className }} + {{- end }} + {{- if and .Values.global.ingress.tlsEnabled .Values.global.ingress.hostnameEnabled }} + tls: + - hosts: + - {{ .Values.global.host }} + secretName: {{ .Values.global.ingress.tlsSecretName }} + {{- end }} + rules: + - http: + paths: + {{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }} + - path: /{{ include "studio.basePath" . }}/(api(?:/|$).*) + {{- else }} + - path: /api + {{- end }} + {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }} + pathType: ImplementationSpecific + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: studio-backend + port: + number: {{ .Values.studioBackend.service.port }} + {{- else }} + serviceName: studio-backend + servicePort: {{ .Values.studioBackend.service.port }} + {{- end }} + {{- if .Values.global.ingress.hostnameEnabled }} + host: {{ .Values.global.host }} + {{- end }} +{{- end }} diff --git a/charts/studio/templates/ingress-studio-ui.yaml b/charts/studio/templates/ingress-studio-ui.yaml new file mode 100644 index 00000000..c59b4d31 --- /dev/null +++ b/charts/studio/templates/ingress-studio-ui.yaml @@ -0,0 +1,57 @@ +{{- if .Values.global.ingress.enabled -}} +{{- if and .Values.global.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.global.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.global.ingress.annotations "kubernetes.io/ingress.class" .Values.global.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ .Release.Name }}-studio-ui + labels: + {{- include "studio-ui.labels" . | nindent 4 }} + annotations: + {{- with .Values.global.ingress.annotations }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.global.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.global.ingress.className }} + {{- end }} + {{- if and .Values.global.ingress.tlsEnabled .Values.global.ingress.hostnameEnabled }} + tls: + - hosts: + - {{ .Values.global.host }} + secretName: {{ .Values.global.ingress.tlsSecretName }} + {{- end }} + rules: + - http: + paths: + {{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }} + - path: /{{ include "studio.basePath" . }}((?:/|$).*) + {{- else }} + - path: / + {{- end }} + {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }} + pathType: ImplementationSpecific + {{- end }} + backend: + {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: studio-ui + port: + number: {{ .Values.studioUi.service.port }} + {{- else }} + serviceName: studio-ui + servicePort: {{ .Values.studioUi.service.port }} + {{- end }} + {{- if .Values.global.ingress.hostnameEnabled }} + host: {{ .Values.global.host }} + {{- end }} +{{- end }} diff --git a/charts/studio/templates/ingress-studio.yaml b/charts/studio/templates/ingress-studio-webhook.yaml similarity index 63% rename from charts/studio/templates/ingress-studio.yaml rename to charts/studio/templates/ingress-studio-webhook.yaml index e056ff0a..77ef2070 100644 --- a/charts/studio/templates/ingress-studio.yaml +++ b/charts/studio/templates/ingress-studio-webhook.yaml @@ -13,11 +13,14 @@ apiVersion: extensions/v1beta1 {{- end }} kind: Ingress metadata: - name: app + name: {{ .Release.Name }}-studio-webhook labels: {{- include "studio-ui.labels" . | nindent 4 }} - {{- with .Values.global.ingress.annotations }} annotations: + {{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }} + nginx.ingress.kubernetes.io/rewrite-target: /$1 + {{- end }} + {{- with .Values.global.ingress.annotations }} {{- toYaml . | nindent 4 }} {{- end }} spec: @@ -33,35 +36,11 @@ spec: rules: - http: paths: - - path: / - {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }} - pathType: ImplementationSpecific - {{- end }} - backend: - {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }} - service: - name: studio-ui - port: - number: {{ .Values.studioUi.service.port }} - {{- else }} - serviceName: studio-ui - servicePort: {{ .Values.studioUi.service.port }} - {{- end }} - - path: /api - {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }} - pathType: ImplementationSpecific - {{- end }} - backend: - {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} - service: - name: studio-backend - port: - number: {{ .Values.studioBackend.service.port }} - {{- else }} - serviceName: studio-backend - servicePort: {{ .Values.studioBackend.service.port }} - {{- end }} + {{- if and .Values.global.basePath (not (eq .Values.global.basePath "/")) }} + - path: /{{ include "studio.basePath" . }}/(webhook(?:/|$).*) + {{- else }} - path: /webhook + {{- end }} {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }} pathType: ImplementationSpecific {{- end }} diff --git a/charts/studio/values.yaml b/charts/studio/values.yaml index d40276ec..d6806927 100644 --- a/charts/studio/values.yaml +++ b/charts/studio/values.yaml @@ -8,6 +8,8 @@ imagePullSecrets: [] global: # -- Studio: Hostname for accessing Studio (no http(s) scheme) host: "studio.example.com" + # -- Studio: Base path (prefix) + basePath: "" # -- Studio: Maximum number of views maxViews: "100" # -- Studio: Maximum number of teams