Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion charts/hoppscotch/templates/_admin.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ Admin base URL based on deployment mode and ingress configuration
{{- define "hoppscotch.admin.baseUrl" -}}
{{- if eq .Values.deploymentMode "aio" -}}
{{- $baseUrl := (include "hoppscotch.ingressBaseUrl" .Values.aio.ingress) -}}
{{- if not $baseUrl -}}{{- $baseUrl = (include "hoppscotch.httpRouteBaseUrl" .Values.aio.httpRoute) -}}{{- end -}}
{{- .Values.hoppscotch.frontend.enableSubpathBasedAccess | ternary (printf "%s/admin" $baseUrl) $baseUrl -}}
Comment on lines 5 to 8
{{- else if eq .Values.deploymentMode "distributed" -}}
{{- include "hoppscotch.ingressBaseUrl" .Values.admin.ingress -}}
{{- $url := (include "hoppscotch.ingressBaseUrl" .Values.admin.ingress) -}}
{{- if not $url -}}{{- $url = (include "hoppscotch.httpRouteBaseUrl" .Values.admin.httpRoute) -}}{{- end -}}
{{- $url -}}
{{- end -}}
{{- end -}}

Expand Down
5 changes: 4 additions & 1 deletion charts/hoppscotch/templates/_backend.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ Generate backend base URL based on deployment mode and ingress configuration
{{- define "hoppscotch.backend.baseUrl" -}}
{{- if eq .Values.deploymentMode "aio" -}}
{{- $baseUrl := (include "hoppscotch.ingressBaseUrl" .Values.aio.ingress) -}}
{{- if not $baseUrl -}}{{- $baseUrl = (include "hoppscotch.httpRouteBaseUrl" .Values.aio.httpRoute) -}}{{- end -}}
{{- .Values.hoppscotch.frontend.enableSubpathBasedAccess | ternary (printf "%s/backend" $baseUrl) $baseUrl -}}
Comment on lines 5 to 8
{{- else if eq .Values.deploymentMode "distributed" -}}
{{- include "hoppscotch.ingressBaseUrl" .Values.backend.ingress -}}
{{- $url := (include "hoppscotch.ingressBaseUrl" .Values.backend.ingress) -}}
{{- if not $url -}}{{- $url = (include "hoppscotch.httpRouteBaseUrl" .Values.backend.httpRoute) -}}{{- end -}}
{{- $url -}}
{{- end -}}
{{- end -}}

Expand Down
8 changes: 6 additions & 2 deletions charts/hoppscotch/templates/_frontend.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ Frontend base URL based on deployment mode and ingress configuration
{{- .Values.hoppscotch.frontend.baseUrl -}}
{{- else -}}
{{- if eq .Values.deploymentMode "aio" -}}
{{- include "hoppscotch.ingressBaseUrl" .Values.aio.ingress -}}
{{- $url := (include "hoppscotch.ingressBaseUrl" .Values.aio.ingress) -}}
{{- if not $url -}}{{- $url = (include "hoppscotch.httpRouteBaseUrl" .Values.aio.httpRoute) -}}{{- end -}}
{{- $url -}}
{{- else if eq .Values.deploymentMode "distributed" -}}
{{- include "hoppscotch.ingressBaseUrl" .Values.frontend.ingress -}}
{{- $url := (include "hoppscotch.ingressBaseUrl" .Values.frontend.ingress) -}}
{{- if not $url -}}{{- $url = (include "hoppscotch.httpRouteBaseUrl" .Values.frontend.httpRoute) -}}{{- end -}}
{{- $url -}}
{{- end -}}
{{- end -}}
{{- end -}}
Expand Down
10 changes: 10 additions & 0 deletions charts/hoppscotch/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ Usage: {{ include "hoppscotch.ingressBaseUrl" .Values.aio.ingress }}
{{- .enabled | ternary (urlJoin (dict "scheme" (.tls | ternary "https" "http") "host" .hostname "path" (.path | trimSuffix "/"))) "" -}}
{{- end -}}

{{/*
Generate base URL from HTTPRoute resource (uses the first hostname in the list)
Usage: {{ include "hoppscotch.httpRouteBaseUrl" .Values.aio.httpRoute }}
*/}}
{{- define "hoppscotch.httpRouteBaseUrl" -}}
{{- if and .enabled .hostnames -}}
{{- urlJoin (dict "scheme" (.tls | ternary "https" "http") "host" (first .hostnames)) -}}
{{- end -}}
{{- end -}}

{{/*
Return common labels for all resources.
*/}}
Expand Down
40 changes: 40 additions & 0 deletions charts/hoppscotch/templates/admin/httproute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- if and (eq .Values.deploymentMode "distributed") .Values.admin.httpRoute.enabled }}
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: {{ include "hoppscotch.fullname" . }}-admin
namespace: {{ include "hoppscotch.namespace" . | quote }}
labels:
app.kubernetes.io/component: hoppscotch-admin
{{- include "hoppscotch.labels" . | nindent 4 }}
{{- if or .Values.commonAnnotations .Values.admin.httpRoute.annotations }}
annotations:
{{- if .Values.commonAnnotations }}
{{- toYaml .Values.commonAnnotations | nindent 4 }}
{{- end }}
{{- if .Values.admin.httpRoute.annotations }}
{{- toYaml .Values.admin.httpRoute.annotations | nindent 4 }}
{{- end }}
{{- end }}
spec:
{{- if .Values.admin.httpRoute.parentRefs }}
parentRefs:
{{- toYaml .Values.admin.httpRoute.parentRefs | nindent 4 }}
{{- end }}
{{- if .Values.admin.httpRoute.hostnames }}
hostnames:
{{- toYaml .Values.admin.httpRoute.hostnames | nindent 4 }}
{{- end }}
rules:
{{- if .Values.admin.httpRoute.rules }}
{{- toYaml .Values.admin.httpRoute.rules | nindent 4 }}
{{- else }}
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: {{ include "hoppscotch.fullname" . }}-admin
port: {{ .Values.admin.service.ports.http }}
{{- end }}
{{- end }}
40 changes: 40 additions & 0 deletions charts/hoppscotch/templates/aio/httproute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- if and (eq .Values.deploymentMode "aio") .Values.aio.httpRoute.enabled }}
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: {{ include "hoppscotch.fullname" . }}
namespace: {{ include "hoppscotch.namespace" . | quote }}
labels:
app.kubernetes.io/component: hoppscotch
{{- include "hoppscotch.labels" . | nindent 4 }}
{{- if or .Values.commonAnnotations .Values.aio.httpRoute.annotations }}
annotations:
{{- if .Values.commonAnnotations }}
{{- toYaml .Values.commonAnnotations | nindent 4 }}
{{- end }}
{{- if .Values.aio.httpRoute.annotations }}
{{- toYaml .Values.aio.httpRoute.annotations | nindent 4 }}
{{- end }}
{{- end }}
spec:
{{- if .Values.aio.httpRoute.parentRefs }}
parentRefs:
{{- toYaml .Values.aio.httpRoute.parentRefs | nindent 4 }}
{{- end }}
{{- if .Values.aio.httpRoute.hostnames }}
hostnames:
{{- toYaml .Values.aio.httpRoute.hostnames | nindent 4 }}
{{- end }}
rules:
{{- if .Values.aio.httpRoute.rules }}
{{- toYaml .Values.aio.httpRoute.rules | nindent 4 }}
{{- else }}
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: {{ include "hoppscotch.fullname" . }}
port: {{ .Values.aio.service.ports.http }}
{{- end }}
{{- end }}
40 changes: 40 additions & 0 deletions charts/hoppscotch/templates/backend/httproute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- if and (eq .Values.deploymentMode "distributed") .Values.backend.httpRoute.enabled }}
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: {{ include "hoppscotch.fullname" . }}-backend
namespace: {{ include "hoppscotch.namespace" . | quote }}
labels:
app.kubernetes.io/component: hoppscotch-backend
{{- include "hoppscotch.labels" . | nindent 4 }}
{{- if or .Values.commonAnnotations .Values.backend.httpRoute.annotations }}
annotations:
{{- if .Values.commonAnnotations }}
{{- toYaml .Values.commonAnnotations | nindent 4 }}
{{- end }}
{{- if .Values.backend.httpRoute.annotations }}
{{- toYaml .Values.backend.httpRoute.annotations | nindent 4 }}
{{- end }}
{{- end }}
spec:
{{- if .Values.backend.httpRoute.parentRefs }}
parentRefs:
{{- toYaml .Values.backend.httpRoute.parentRefs | nindent 4 }}
{{- end }}
{{- if .Values.backend.httpRoute.hostnames }}
hostnames:
{{- toYaml .Values.backend.httpRoute.hostnames | nindent 4 }}
{{- end }}
rules:
{{- if .Values.backend.httpRoute.rules }}
{{- toYaml .Values.backend.httpRoute.rules | nindent 4 }}
{{- else }}
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: {{ include "hoppscotch.fullname" . }}-backend
port: {{ .Values.backend.service.ports.http }}
{{- end }}
{{- end }}
40 changes: 40 additions & 0 deletions charts/hoppscotch/templates/frontend/httproute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- if and (eq .Values.deploymentMode "distributed") .Values.frontend.httpRoute.enabled }}
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: {{ include "hoppscotch.fullname" . }}-frontend
namespace: {{ include "hoppscotch.namespace" . | quote }}
labels:
app.kubernetes.io/component: hoppscotch-frontend
{{- include "hoppscotch.labels" . | nindent 4 }}
{{- if or .Values.commonAnnotations .Values.frontend.httpRoute.annotations }}
annotations:
{{- if .Values.commonAnnotations }}
{{- toYaml .Values.commonAnnotations | nindent 4 }}
{{- end }}
{{- if .Values.frontend.httpRoute.annotations }}
{{- toYaml .Values.frontend.httpRoute.annotations | nindent 4 }}
{{- end }}
{{- end }}
spec:
{{- if .Values.frontend.httpRoute.parentRefs }}
parentRefs:
{{- toYaml .Values.frontend.httpRoute.parentRefs | nindent 4 }}
{{- end }}
{{- if .Values.frontend.httpRoute.hostnames }}
hostnames:
{{- toYaml .Values.frontend.httpRoute.hostnames | nindent 4 }}
{{- end }}
rules:
{{- if .Values.frontend.httpRoute.rules }}
{{- toYaml .Values.frontend.httpRoute.rules | nindent 4 }}
{{- else }}
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: {{ include "hoppscotch.fullname" . }}-frontend
port: {{ .Values.frontend.service.ports.http }}
{{- end }}
{{- end }}
141 changes: 141 additions & 0 deletions charts/hoppscotch/tests/admin_httproute_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
suite: Admin HTTPRoute
templates:
- admin/deployment.yaml
- admin/httproute.yaml
- config/configmap.yaml
- config/secret.yaml
tests:
- it: should generate HTTPRoute when deployment mode is distributed and httpRoute is enabled
template: admin/httproute.yaml
set:
deploymentMode: distributed
admin:
httpRoute:
enabled: true
parentRefs:
- name: my-gateway
namespace: default
asserts:
- containsDocument:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
- equal:
path: metadata.name
value: release-name-hoppscotch-admin

- it: should not generate HTTPRoute when deployment mode is distributed and httpRoute is disabled
template: admin/httproute.yaml
set:
deploymentMode: distributed
admin:
httpRoute:
enabled: false
asserts:
- hasDocuments:
count: 0

- it: should not generate HTTPRoute when deployment mode is not distributed
template: admin/httproute.yaml
set:
deploymentMode: aio
admin:
httpRoute:
enabled: true
asserts:
- hasDocuments:
count: 0

- it: should set parentRefs when specified
template: admin/httproute.yaml
set:
deploymentMode: distributed
admin:
httpRoute:
enabled: true
parentRefs:
- name: my-gateway
namespace: default
sectionName: https
asserts:
- equal:
path: spec.parentRefs[0].name
value: my-gateway
- equal:
path: spec.parentRefs[0].namespace
value: default
- equal:
path: spec.parentRefs[0].sectionName
value: https

- it: should set hostnames when specified
template: admin/httproute.yaml
set:
deploymentMode: distributed
admin:
httpRoute:
enabled: true
parentRefs:
- name: my-gateway
hostnames:
- admin.example.com
asserts:
- equal:
path: spec.hostnames[0]
value: admin.example.com

- it: should set backendRefs to admin service
template: admin/httproute.yaml
set:
deploymentMode: distributed
admin:
httpRoute:
enabled: true
parentRefs:
- name: my-gateway
matches:
- path:
type: PathPrefix
value: /
Comment on lines +95 to +98
service:
ports:
http: 3100
asserts:
- equal:
path: spec.rules[0].backendRefs[0].name
value: release-name-hoppscotch-admin
- equal:
path: spec.rules[0].backendRefs[0].port
value: 3100

- it: should set default path match
template: admin/httproute.yaml
set:
deploymentMode: distributed
admin:
httpRoute:
enabled: true
parentRefs:
- name: my-gateway
asserts:
- equal:
path: spec.rules[0].matches[0].path.type
value: PathPrefix
- equal:
path: spec.rules[0].matches[0].path.value
value: /

- it: should include annotations when specified
template: admin/httproute.yaml
set:
deploymentMode: distributed
admin:
httpRoute:
enabled: true
parentRefs:
- name: my-gateway
annotations:
example.com/custom: "true"
asserts:
- equal:
path: metadata.annotations["example.com/custom"]
value: "true"
Loading