@@ -54,6 +54,8 @@ const (
5454 IgnorefileName = ".helmignore"
5555 // IngressFileName is the name of the example ingress file.
5656 IngressFileName = TemplatesDir + sep + "ingress.yaml"
57+ // HTTPRouteFileName is the name of the example HTTPRoute file.
58+ HTTPRouteFileName = TemplatesDir + sep + "httproute.yaml"
5759 // DeploymentName is the name of the example deployment file.
5860 DeploymentName = TemplatesDir + sep + "deployment.yaml"
5961 // ServiceName is the name of the example service file.
@@ -177,6 +179,44 @@ ingress:
177179 # hosts:
178180 # - chart-example.local
179181
182+ # -- Expose the service via gateway-api HTTPRoute
183+ # Requires Gateway API resources and suitable controller installed within the cluster
184+ # (see: https://gateway-api.sigs.k8s.io/guides/)
185+ httpRoute:
186+ # HTTPRoute enabled.
187+ enabled: false
188+ # HTTPRoute annotations.
189+ annotations: {}
190+ # Which Gateways this Route is attached to.
191+ parentRefs:
192+ - name: gateway
193+ sectionName: http
194+ # namespace: default
195+ # Hostnames matching HTTP header.
196+ hostnames:
197+ - chart-example.local
198+ # List of rules and filters applied.
199+ rules:
200+ - matches:
201+ - path:
202+ type: PathPrefix
203+ value: /headers
204+ # filters:
205+ # - type: RequestHeaderModifier
206+ # requestHeaderModifier:
207+ # set:
208+ # - name: My-Overwrite-Header
209+ # value: this-is-the-only-value
210+ # remove:
211+ # - User-Agent
212+ # - matches:
213+ # - path:
214+ # type: PathPrefix
215+ # value: /echo
216+ # headers:
217+ # - name: version
218+ # value: v2
219+
180220resources: {}
181221 # We usually recommend not to specify default resources and to leave this as a conscious
182222 # choice for the user. This also increases chances charts run on environments with little
@@ -297,6 +337,46 @@ spec:
297337{{- end }}
298338`
299339
340+ const defaultHTTPRoute = `{{- if .Values.httpRoute.enabled -}}
341+ {{- $fullName := include "<CHARTNAME>.fullname" . -}}
342+ {{- $svcPort := .Values.service.port -}}
343+ apiVersion: gateway.networking.k8s.io/v1
344+ kind: HTTPRoute
345+ metadata:
346+ name: {{ $fullName }}
347+ labels:
348+ {{- include "<CHARTNAME>.labels" . | nindent 4 }}
349+ {{- with .Values.httpRoute.annotations }}
350+ annotations:
351+ {{- toYaml . | nindent 4 }}
352+ {{- end }}
353+ spec:
354+ parentRefs:
355+ {{- with .Values.httpRoute.parentRefs }}
356+ {{- toYaml . | nindent 4 }}
357+ {{- end }}
358+ {{- with .Values.httpRoute.hostnames }}
359+ hostnames:
360+ {{- toYaml . | nindent 4 }}
361+ {{- end }}
362+ rules:
363+ {{- range .Values.httpRoute.rules }}
364+ {{- with .matches }}
365+ - matches:
366+ {{- toYaml . | nindent 8 }}
367+ {{- end }}
368+ {{- with .filters }}
369+ filters:
370+ {{- toYaml . | nindent 8 }}
371+ {{- end }}
372+ backendRefs:
373+ - name: {{ $fullName }}
374+ port: {{ $svcPort }}
375+ weight: 1
376+ {{- end }}
377+ {{- end }}
378+ `
379+
300380const defaultDeployment = `apiVersion: apps/v1
301381kind: Deployment
302382metadata:
@@ -444,7 +524,20 @@ spec:
444524`
445525
446526const defaultNotes = `1. Get the application URL by running these commands:
447- {{- if .Values.ingress.enabled }}
527+ {{- if .Values.httpRoute.enabled }}
528+ {{- if .Values.httpRoute.hostnames }}
529+ export APP_HOSTNAME={{ .Values.httpRoute.hostnames | first }}
530+ {{- else }}
531+ export APP_HOSTNAME=$(kubectl get --namespace {{(first .Values.httpRoute.parentRefs).namespace | default .Release.Namespace }} gateway/{{ (first .Values.httpRoute.parentRefs).name }} -o jsonpath="{.spec.listeners[0].hostname}")
532+ {{- end }}
533+ {{- if and .Values.httpRoute.rules (first .Values.httpRoute.rules).matches (first (first .Values.httpRoute.rules).matches).path.value }}
534+ echo "Visit http://$APP_HOSTNAME{{ (first (first .Values.httpRoute.rules).matches).path.value }} to use your application"
535+
536+ NOTE: Your HTTPRoute depends on the listener configuration of your gateway and your HTTPRoute rules.
537+ The rules can be set for path, method, header and query parameters.
538+ You can check the gateway configuration with 'kubectl get --namespace {{(first .Values.httpRoute.parentRefs).namespace | default .Release.Namespace }} gateway/{{ (first .Values.httpRoute.parentRefs).name }} -o yaml'
539+ {{- end }}
540+ {{- else if .Values.ingress.enabled }}
448541{{- range $host := .Values.ingress.hosts }}
449542 {{- range .paths }}
450543 http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
@@ -658,6 +751,11 @@ func Create(name, dir string) (string, error) {
658751 path : filepath .Join (cdir , IngressFileName ),
659752 content : transform (defaultIngress , name ),
660753 },
754+ {
755+ // httproute.yaml
756+ path : filepath .Join (cdir , HTTPRouteFileName ),
757+ content : transform (defaultHTTPRoute , name ),
758+ },
661759 {
662760 // deployment.yaml
663761 path : filepath .Join (cdir , DeploymentName ),
0 commit comments