Skip to content

Commit 5f14951

Browse files
committed
Rework contextPath|apiBasePath|servletContextPath management in Helm Chart
1 parent e225162 commit 5f14951

File tree

5 files changed

+25
-27
lines changed

5 files changed

+25
-27
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
1. Get the application URL by running these commands:
22
{{- if .Values.ingress.enabled }}
3-
{{- $apiBasePath := include "cosmotech-api.apiBasePath" . -}}
3+
{{- $contexPath := include "cosmotech-api.contexPath" . -}}
44
{{- range $host := .Values.ingress.hosts }}
5-
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ $apiBasePath }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ $contexPath }}
66
{{- range .paths }}
77
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
88
{{- end }}
99
{{- end }}
1010
{{- else if contains "NodePort" .Values.service.type }}
1111
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "cosmotech-api.fullname" . }})
1212
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
13-
echo http://$NODE_IP:$NODE_PORT{{ include "cosmotech-api.apiBasePath" . }}
13+
echo http://$NODE_IP:$NODE_PORT{{ include "cosmotech-api.contexPath" . }}
1414
{{- else if contains "LoadBalancer" .Values.service.type }}
1515
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
1616
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "cosmotech-api.fullname" . }}'
1717
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "cosmotech-api.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
18-
echo http://$SERVICE_IP:{{ .Values.service.port }}{{ include "cosmotech-api.apiBasePath" . }}
18+
echo http://$SERVICE_IP:{{ .Values.service.port }}{{ include "cosmotech-api.contexPath" . }}
1919
{{- else if contains "ClusterIP" .Values.service.type }}
2020
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "cosmotech-api.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
2121
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
22-
echo "Visit http://127.0.0.1:8080{{ include "cosmotech-api.apiBasePath" . }} to use your application"
22+
echo "Visit http://127.0.0.1:8080{{ include "cosmotech-api.contexPath" . }} to use your application"
2323
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
2424
{{- end }}

api/kubernetes/helm-chart/templates/_helpers.tpl

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,17 @@ Create Docker secrets so Argo Workflows can pull images from a private container
7777
{{- end }}
7878

7979
{{/*
80-
Default Ingress path
80+
Context path:
81+
This path will follow the pattern /{rootName}/{namespace|tenantId}/{apiVersion}
82+
E.g:
83+
- /cosmotech-api/myTenant/v1
84+
- /cosmotech-api/myTenant/ if apiVersion is set to "latest"
8185
*/}}
82-
{{- define "cosmotech-api.ingressTenantPath" -}}
83-
{{- printf "%s" (printf "%s" .Values.api.servletContextPath | trimSuffix "/" ) }}
84-
{{- end }}
85-
86-
{{/*
87-
API Base path with servlet context, namespace, version
88-
*/}}
89-
{{- define "cosmotech-api.apiBasePath" -}}
86+
{{- define "cosmotech-api.contexPath" -}}
9087
{{- if eq .Values.api.version "latest" }}
91-
{{- printf "%s" (include "cosmotech-api.ingressTenantPath" . | trimSuffix "/" ) }}
88+
{{- printf "%s/%s" (printf "%s" .Values.api.servletContextPath | trimSuffix "/" ) .Release.Namespace }}
9289
{{- else }}
93-
{{- printf "%s/%s" (include "cosmotech-api.ingressTenantPath" . | trimSuffix "/" ) (printf "%s" .Values.api.version | trimSuffix "/" ) }}
90+
{{- printf "%s/%s/%s" (printf "%s" .Values.api.servletContextPath | trimSuffix "/" ) .Release.Namespace (printf "%s" .Values.api.version | trimSuffix "/" ) }}
9491
{{- end }}
9592
{{- end }}
9693

@@ -104,11 +101,12 @@ spring:
104101

105102
api:
106103
version: "{{ .Values.api.version }}"
107-
servletContextPath: {{ include "cosmotech-api.apiBasePath" . }}
104+
multiTenant: {{ default true .Values.api.multiTenant }}
105+
servletContextPath: {{ include "cosmotech-api.contexPath" . }}
108106

109107
server:
110108
servlet:
111-
context-path: {{ include "cosmotech-api.apiBasePath" . }}
109+
context-path: {{ include "cosmotech-api.contexPath" . }}
112110
jetty:
113111
accesslog:
114112
ignore-paths:
@@ -137,7 +135,7 @@ management:
137135
csm:
138136
platform:
139137
api:
140-
base-url: "http://{{ include "cosmotech-api.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.port }}{{ include "cosmotech-api.apiBasePath" . | trimSuffix "/" }}"
138+
base-url: "http://{{ include "cosmotech-api.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.port }}{{ include "cosmotech-api.contexPath" . | trimSuffix "/" }}"
141139
# API Base Path for OpenAPI-generated controllers.
142140
# Might conflict with the SpringBoot context path, hence leaving it at the root
143141
base-path: /

api/kubernetes/helm-chart/templates/ingress.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{- $kubeVersion := .Capabilities.KubeVersion.GitVersion -}}
33
{{- $fullName := include "cosmotech-api.fullname" . -}}
44
{{- $svcPort := .Values.service.port -}}
5-
{{- $apiBasePath := include "cosmotech-api.apiBasePath" . -}}
5+
{{- $contexPath := include "cosmotech-api.contexPath" . -}}
66
{{- if semverCompare ">=1.19-0" $kubeVersion -}}
77
apiVersion: networking.k8s.io/v1
88
{{- else if semverCompare ">=1.14-0" $kubeVersion -}}
@@ -37,7 +37,7 @@ spec:
3737
- host: {{ .host | quote }}
3838
http:
3939
paths:
40-
- path: {{ $apiBasePath }}
40+
- path: {{ $contexPath }}
4141
pathType: Prefix
4242
backend:
4343
{{- if semverCompare ">=1.19-0" $kubeVersion }}

api/kubernetes/helm-chart/templates/tests/test-access-openapi.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- $apiBasePath := include "cosmotech-api.apiBasePath" . -}}
1+
{{- $contexPath := include "cosmotech-api.contexPath" . -}}
22
apiVersion: v1
33
kind: Pod
44
metadata:
@@ -38,9 +38,9 @@ spec:
3838
- '-S'
3939
- '-O'
4040
- '-'
41-
- 'http://{{ include "cosmotech-api.fullname" . }}:{{ .Values.service.port }}{{ $apiBasePath | trimSuffix "/" }}/openapi'
42-
- 'http://{{ include "cosmotech-api.fullname" . }}:{{ .Values.service.port }}{{ $apiBasePath | trimSuffix "/" }}/openapi.json'
43-
- 'http://{{ include "cosmotech-api.fullname" . }}:{{ .Values.service.port }}{{ $apiBasePath | trimSuffix "/" }}/openapi.yaml'
41+
- 'http://{{ include "cosmotech-api.fullname" . }}:{{ .Values.service.port }}{{ $contexPath | trimSuffix "/" }}/openapi'
42+
- 'http://{{ include "cosmotech-api.fullname" . }}:{{ .Values.service.port }}{{ $contexPath | trimSuffix "/" }}/openapi.json'
43+
- 'http://{{ include "cosmotech-api.fullname" . }}:{{ .Values.service.port }}{{ $contexPath | trimSuffix "/" }}/openapi.yaml'
4444
securityContext:
4545
readOnlyRootFilesystem: true
4646
resources:

api/kubernetes/helm-chart/templates/tests/test-access-swaggerui.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- $apiBasePath := include "cosmotech-api.apiBasePath" . -}}
1+
{{- $contexPath := include "cosmotech-api.contexPath" . -}}
22
apiVersion: v1
33
kind: Pod
44
metadata:
@@ -38,7 +38,7 @@ spec:
3838
- '-S'
3939
- '-O'
4040
- '-'
41-
- 'http://{{ include "cosmotech-api.fullname" . }}:{{ .Values.service.port }}{{ $apiBasePath | trimSuffix "/" }}/swagger-ui/index.html'
41+
- 'http://{{ include "cosmotech-api.fullname" . }}:{{ .Values.service.port }}{{ $contexPath | trimSuffix "/" }}/swagger-ui/index.html'
4242
securityContext:
4343
readOnlyRootFilesystem: true
4444
resources:

0 commit comments

Comments
 (0)