Skip to content
Draft
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ helm delete --namespace test my-application
| httpRoute.hostnames | tpl/list | `nil` | Hostnames for the HTTPRoute. |
| httpRoute.additionalLabels | object | `{}` | Additional labels for HTTPRoute. |
| httpRoute.annotations | object | `{}` | Annotations for HTTPRoute. |
| httpRoute.rules | tpl/list | `[{"backendRefs":[{"name":"{{ include \"application.name\" $ }}","port":"{{ (first $.Values.service.ports).port | int }}"}],"matches":[{"path":{"type":"PathPrefix","value":"/"}}]}]` | Rules for HTTPRoute. |
| httpRoute.rules | tpl/list | `[{"backendRefs":[{"name":"{{ include \"application.name\" $ }}","port":"{{ (first $.Values.service.ports).port }}"}],"matches":[{"path":{"type":"PathPrefix","value":"/"}}]}]` | Rules for HTTPRoute. |

### Route Parameters

Expand Down
50 changes: 50 additions & 0 deletions application/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,53 @@ reference:
kind: Route
name: {{ include "application.name" . }}
{{- end }}

{{/*
Renders httpRoute rules with proper integer type for port fields.
Usage:
{{ include "application.httpRoute.rules" . }}
*/}}
{{- define "application.httpRoute.rules" -}}
{{- $rulesYaml := include "application.tplvalues.render" ( dict "value" .Values.httpRoute.rules "context" . ) -}}
{{- $wrappedYaml := printf "rules:\n%s" $rulesYaml -}}
{{- $parsed := $wrappedYaml | fromYaml -}}
{{- range $ruleIndex, $rule := $parsed.rules -}}
{{- if $ruleIndex }}
{{ end -}}
- {{- if $rule.matches }}
matches: {{ $rule.matches | toYaml | nindent 4 }}
{{- end }}
{{- if $rule.filters }}
filters: {{ $rule.filters | toYaml | nindent 4 }}
{{- end }}
{{- if $rule.sessionAffinity }}
sessionAffinity: {{ $rule.sessionAffinity | toYaml | nindent 4 }}
{{- end }}
{{- if $rule.timeouts }}
timeouts: {{ $rule.timeouts | toYaml | nindent 4 }}
{{- end }}
{{- if $rule.backendRefs }}
backendRefs:
{{- range $rule.backendRefs }}
{{- $portVal := .port | int }}
{{- if or (lt $portVal 1) (gt $portVal 65535) }}
{{- fail (printf "Invalid port value: %v. Port must be between 1 and 65535" .port) }}
{{- end }}
- name: {{ .name }}
port: {{ $portVal }}
{{- if .weight }}
weight: {{ .weight | int }}
{{- end }}
{{- if .namespace }}
namespace: {{ .namespace }}
{{- end }}
{{- if .kind }}
kind: {{ .kind }}
{{- end }}
{{- if .group }}
group: {{ .group }}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}
{{- end -}}
2 changes: 1 addition & 1 deletion application/templates/httproute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ spec:
useDefaultGateways: {{ .Values.httpRoute.useDefaultGateways }}
{{- end }}
hostnames: {{- include "application.tplvalues.render" ( dict "value" .Values.httpRoute.hostnames "context" $ ) | nindent 4 }}
rules: {{- include "application.tplvalues.render" ( dict "value" .Values.httpRoute.rules "context" $ ) | nindent 4 }}
rules: {{- include "application.httpRoute.rules" . | nindent 4 }}
{{- end }}
37 changes: 37 additions & 0 deletions application/tests/httproute_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,40 @@ tests:
- equal:
path: spec.rules[0].filters[0].requestRedirect.port
value: 443

- it: renders HTTPRoute with default service port when using template expression
set:
applicationName: "test-app"
httpRoute:
enabled: true
parentRefs:
- name: my-gateway
hostnames:
- example.com
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: '{{ include "application.name" $ }}'
port: '{{ (first $.Values.service.ports).port }}'
service:
enabled: true
ports:
- port: 8080
name: http
protocol: TCP
targetPort: 8080
capabilities:
apiVersions:
- gateway.networking.k8s.io/v1
asserts:
- equal:
path: spec.rules[0].backendRefs[0].name
value: test-app
- equal:
path: spec.rules[0].backendRefs[0].port
value: 8080
- isKind:
of: HTTPRoute
2 changes: 1 addition & 1 deletion application/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ httpRoute:
value: /
backendRefs:
- name: '{{ include "application.name" $ }}'
port: '{{ (first $.Values.service.ports).port | int }}'
port: '{{ (first $.Values.service.ports).port }}'

route:
# -- (bool) Deploy a Route (OpenShift) resource.
Expand Down