From 90daeadeb521b40baa1669029549e2d68c1ce5bc Mon Sep 17 00:00:00 2001 From: Henrik Gerdes Date: Tue, 26 Mar 2024 19:32:32 +0100 Subject: [PATCH 1/7] feat: add httproute from gateway-api to create chart template Adds the HTTPRoute from https://gateway-api.sigs.k8s.io/reference/spec/ to the example getting started chart. This closes #12603 Signed-off-by: Henrik Gerdes --- pkg/chart/v2/util/create.go | 86 +++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/pkg/chart/v2/util/create.go b/pkg/chart/v2/util/create.go index 7eb3398f5..fdb740fa9 100644 --- a/pkg/chart/v2/util/create.go +++ b/pkg/chart/v2/util/create.go @@ -54,6 +54,8 @@ const ( IgnorefileName = ".helmignore" // IngressFileName is the name of the example ingress file. IngressFileName = TemplatesDir + sep + "ingress.yaml" + // HttpRouteFileName is the name of the example HTTPRoute file. + HttpRouteFileName = TemplatesDir + sep + "httproute.yaml" // DeploymentName is the name of the example deployment file. DeploymentName = TemplatesDir + sep + "deployment.yaml" // ServiceName is the name of the example service file. @@ -177,6 +179,41 @@ ingress: # hosts: # - chart-example.local +# -- How the service is exposed via gateway-apis HTTPRoute. +httpRoute: + # -- HTTPRoute enabled. + enabled: false + # -- HTTPRoute annotations. + annotations: {} + # -- Which Gateways this Route is attached to + parentRefs: + - name: gateway + sectionName: http + # -- Hostnames matching HTTP header. + hostnames: + - "example.com" + # -- List of rules and filters applied. + rules: + - matches: + - path: + type: PathPrefix + value: /headers + # filters: + # - type: RequestHeaderModifier + # requestHeaderModifier: + # set: + # - name: My-Overwrite-Header + # value: this-is-the-only-value + # remove: + # - User-Agent + # - matches: + # - path: + # type: PathPrefix + # value: /echo + # headers: + # - name: version + # value: v2 + resources: {} # We usually recommend not to specify default resources and to leave this as a conscious # choice for the user. This also increases chances charts run on environments with little @@ -297,6 +334,50 @@ spec: {{- end }} ` +const defaultHttpRoute = `{{- if .Values.httpRoute.enabled -}} +{{- $fullName := include ".fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if .Capabilities.APIVersions.Has "gateway.networking.k8s.io/v1" -}} +apiVersion: gateway.networking.k8s.io/v1 +{{- else -}} +apiVersion: gateway.networking.k8s.io/v1alpha2 +{{- end }} +kind: HTTPRoute +metadata: + name: {{ $fullName }} + labels: + {{- include ".labels" . | nindent 4 }} + {{- with .Values.httpRoute.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + parentRefs: + {{- with .Values.httpRoute.parentRefs }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.httpRoute.hostnames }} + hostnames: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + {{- range .Values.httpRoute.rules }} + {{- with .matches }} + - matches: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .filters }} + filters: + {{- toYaml . | nindent 8 }} + {{- end }} + backendRefs: + - name: {{ $fullName }} + port: {{ $svcPort }} + weight: 1 + {{- end }} +{{- end }} +` + const defaultDeployment = `apiVersion: apps/v1 kind: Deployment metadata: @@ -658,6 +739,11 @@ func Create(name, dir string) (string, error) { path: filepath.Join(cdir, IngressFileName), content: transform(defaultIngress, name), }, + { + // httproute.yaml + path: filepath.Join(cdir, HttpRouteFileName), + content: transform(defaultHttpRoute, name), + }, { // deployment.yaml path: filepath.Join(cdir, DeploymentName), From 3fc5d689e611416e4d5fe9ff12004b58df315a85 Mon Sep 17 00:00:00 2001 From: Henrik Gerdes Date: Thu, 28 Mar 2024 19:07:18 +0100 Subject: [PATCH 2/7] docs: add notes in chart templates for accessing httproute Signed-off-by: Henrik Gerdes --- pkg/chart/v2/util/create.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/chart/v2/util/create.go b/pkg/chart/v2/util/create.go index fdb740fa9..149d9f456 100644 --- a/pkg/chart/v2/util/create.go +++ b/pkg/chart/v2/util/create.go @@ -189,6 +189,7 @@ httpRoute: parentRefs: - name: gateway sectionName: http + # namespace: default # -- Hostnames matching HTTP header. hostnames: - "example.com" @@ -525,7 +526,20 @@ spec: ` const defaultNotes = `1. Get the application URL by running these commands: -{{- if .Values.ingress.enabled }} +{{- if .Values.httpRoute.enabled }} +{{- if .Values.httpRoute.hostnames }} + export APP_HOSTNAME={{ .Values.httpRoute.hostnames | first }} +{{- else }} + 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}") + {{- end }} +{{- if and .Values.httpRoute.rules (first .Values.httpRoute.rules).matches (first (first .Values.httpRoute.rules).matches).path.value }} + echo "Visit http://$APP_HOSTNAME{{ (first (first .Values.httpRoute.rules).matches).path.value }} to use your application" + + NOTE: Your HTTPRoute depends on the listener configuration of your gateway and your HTTPRoute rules. + The rules can be set for path, method, header and query parameters. + 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' +{{- end }} +{{- else if .Values.ingress.enabled }} {{- range $host := .Values.ingress.hosts }} {{- range .paths }} http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} From d22939b439831f1c28ac9ad6643939aaee46f970 Mon Sep 17 00:00:00 2001 From: Henrik Gerdes Date: Thu, 11 Apr 2024 21:19:21 +0200 Subject: [PATCH 3/7] fix: correct expected number of template files in unit-test Signed-off-by: Henrik Gerdes --- pkg/chart/v2/util/create.go | 10 +++++----- pkg/cmd/create_test.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/chart/v2/util/create.go b/pkg/chart/v2/util/create.go index 149d9f456..0330055e4 100644 --- a/pkg/chart/v2/util/create.go +++ b/pkg/chart/v2/util/create.go @@ -54,8 +54,8 @@ const ( IgnorefileName = ".helmignore" // IngressFileName is the name of the example ingress file. IngressFileName = TemplatesDir + sep + "ingress.yaml" - // HttpRouteFileName is the name of the example HTTPRoute file. - HttpRouteFileName = TemplatesDir + sep + "httproute.yaml" + // HTTPRouteFileName is the name of the example HTTPRoute file. + HTTPRouteFileName = TemplatesDir + sep + "httproute.yaml" // DeploymentName is the name of the example deployment file. DeploymentName = TemplatesDir + sep + "deployment.yaml" // ServiceName is the name of the example service file. @@ -335,7 +335,7 @@ spec: {{- end }} ` -const defaultHttpRoute = `{{- if .Values.httpRoute.enabled -}} +const defaultHTTPRoute = `{{- if .Values.httpRoute.enabled -}} {{- $fullName := include ".fullname" . -}} {{- $svcPort := .Values.service.port -}} {{- if .Capabilities.APIVersions.Has "gateway.networking.k8s.io/v1" -}} @@ -755,8 +755,8 @@ func Create(name, dir string) (string, error) { }, { // httproute.yaml - path: filepath.Join(cdir, HttpRouteFileName), - content: transform(defaultHttpRoute, name), + path: filepath.Join(cdir, HTTPRouteFileName), + content: transform(defaultHTTPRoute, name), }, { // deployment.yaml diff --git a/pkg/cmd/create_test.go b/pkg/cmd/create_test.go index bfdf3db5a..26eabbfc3 100644 --- a/pkg/cmd/create_test.go +++ b/pkg/cmd/create_test.go @@ -105,7 +105,7 @@ func TestCreateStarterCmd(t *testing.T) { t.Errorf("Wrong API version: %q", c.Metadata.APIVersion) } - expectedNumberOfTemplates := 9 + expectedNumberOfTemplates := 10 if l := len(c.Templates); l != expectedNumberOfTemplates { t.Errorf("Expected %d templates, got %d", expectedNumberOfTemplates, l) } @@ -173,7 +173,7 @@ func TestCreateStarterAbsoluteCmd(t *testing.T) { t.Errorf("Wrong API version: %q", c.Metadata.APIVersion) } - expectedNumberOfTemplates := 9 + expectedNumberOfTemplates := 10 if l := len(c.Templates); l != expectedNumberOfTemplates { t.Errorf("Expected %d templates, got %d", expectedNumberOfTemplates, l) } From 5d0c6e9ae4da0fff8b79a43506ac90f114f5de16 Mon Sep 17 00:00:00 2001 From: Henrik Gerdes Date: Mon, 15 Apr 2024 17:56:27 +0200 Subject: [PATCH 4/7] fix: remove v1alpha2 gateway api support Signed-off-by: Henrik Gerdes --- pkg/chart/v2/util/create.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/chart/v2/util/create.go b/pkg/chart/v2/util/create.go index 0330055e4..0c61d353f 100644 --- a/pkg/chart/v2/util/create.go +++ b/pkg/chart/v2/util/create.go @@ -338,11 +338,7 @@ spec: const defaultHTTPRoute = `{{- if .Values.httpRoute.enabled -}} {{- $fullName := include ".fullname" . -}} {{- $svcPort := .Values.service.port -}} -{{- if .Capabilities.APIVersions.Has "gateway.networking.k8s.io/v1" -}} apiVersion: gateway.networking.k8s.io/v1 -{{- else -}} -apiVersion: gateway.networking.k8s.io/v1alpha2 -{{- end }} kind: HTTPRoute metadata: name: {{ $fullName }} From 1aac5b0b70e650e1d02142095c6847fc5e0f7b3b Mon Sep 17 00:00:00 2001 From: Henrik Gerdes Date: Sat, 8 Jun 2024 19:25:07 +0200 Subject: [PATCH 5/7] fix: use common chart-example.local hostname for http-route default Signed-off-by: Henrik Gerdes --- pkg/chart/v2/util/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/chart/v2/util/create.go b/pkg/chart/v2/util/create.go index 0c61d353f..489571ba4 100644 --- a/pkg/chart/v2/util/create.go +++ b/pkg/chart/v2/util/create.go @@ -192,7 +192,7 @@ httpRoute: # namespace: default # -- Hostnames matching HTTP header. hostnames: - - "example.com" + - chart-example.local # -- List of rules and filters applied. rules: - matches: From ca367d970cf14be07449b02eb97af1a5ec85f1b9 Mon Sep 17 00:00:00 2001 From: Henrik Gerdes Date: Tue, 19 Nov 2024 19:05:41 +0100 Subject: [PATCH 6/7] docs: more user-friendly info for httpRoute scaffold Co-authored-by: George Jenkins Signed-off-by: Henrik Gerdes --- pkg/chart/v2/util/create.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/chart/v2/util/create.go b/pkg/chart/v2/util/create.go index 489571ba4..658a9846a 100644 --- a/pkg/chart/v2/util/create.go +++ b/pkg/chart/v2/util/create.go @@ -179,7 +179,9 @@ ingress: # hosts: # - chart-example.local -# -- How the service is exposed via gateway-apis HTTPRoute. +# -- Expose the service via gateway-api HTTPRoute +# Requires Gateway API resources and suitable controller installed incluster +# (see: https://gateway-api.sigs.k8s.io/guides/) httpRoute: # -- HTTPRoute enabled. enabled: false From 597c35852a185284695e74b193aeef983b0c9da0 Mon Sep 17 00:00:00 2001 From: Henrik Gerdes Date: Mon, 10 Feb 2025 10:20:57 +0100 Subject: [PATCH 7/7] fix: align values comments/docs to scaffold standard Signed-off-by: Henrik Gerdes --- pkg/chart/v2/util/create.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/chart/v2/util/create.go b/pkg/chart/v2/util/create.go index 658a9846a..35a8c64a0 100644 --- a/pkg/chart/v2/util/create.go +++ b/pkg/chart/v2/util/create.go @@ -180,22 +180,22 @@ ingress: # - chart-example.local # -- Expose the service via gateway-api HTTPRoute -# Requires Gateway API resources and suitable controller installed incluster +# Requires Gateway API resources and suitable controller installed within the cluster # (see: https://gateway-api.sigs.k8s.io/guides/) httpRoute: - # -- HTTPRoute enabled. + # HTTPRoute enabled. enabled: false - # -- HTTPRoute annotations. + # HTTPRoute annotations. annotations: {} - # -- Which Gateways this Route is attached to + # Which Gateways this Route is attached to. parentRefs: - name: gateway sectionName: http # namespace: default - # -- Hostnames matching HTTP header. + # Hostnames matching HTTP header. hostnames: - chart-example.local - # -- List of rules and filters applied. + # List of rules and filters applied. rules: - matches: - path: