mirror of
https://github.com/helm/helm.git
synced 2026-04-21 22:27:03 -04:00
Merge pull request #30658 from helm/gjenkins/backport_12912
[v3 backport] feat: add httproute from gateway-api to create chart template
This commit is contained in:
commit
b4e06a11d2
2 changed files with 101 additions and 3 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,44 @@ ingress:
|
|||
# hosts:
|
||||
# - chart-example.local
|
||||
|
||||
# -- Expose the service via gateway-api HTTPRoute
|
||||
# Requires Gateway API resources and suitable controller installed within the cluster
|
||||
# (see: https://gateway-api.sigs.k8s.io/guides/)
|
||||
httpRoute:
|
||||
# HTTPRoute enabled.
|
||||
enabled: false
|
||||
# HTTPRoute annotations.
|
||||
annotations: {}
|
||||
# Which Gateways this Route is attached to.
|
||||
parentRefs:
|
||||
- name: gateway
|
||||
sectionName: http
|
||||
# namespace: default
|
||||
# Hostnames matching HTTP header.
|
||||
hostnames:
|
||||
- chart-example.local
|
||||
# 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 +337,46 @@ spec:
|
|||
{{- end }}
|
||||
`
|
||||
|
||||
const defaultHTTPRoute = `{{- if .Values.httpRoute.enabled -}}
|
||||
{{- $fullName := include "<CHARTNAME>.fullname" . -}}
|
||||
{{- $svcPort := .Values.service.port -}}
|
||||
apiVersion: gateway.networking.k8s.io/v1
|
||||
kind: HTTPRoute
|
||||
metadata:
|
||||
name: {{ $fullName }}
|
||||
labels:
|
||||
{{- include "<CHARTNAME>.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:
|
||||
|
|
@ -444,7 +524,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 }}
|
||||
|
|
@ -658,6 +751,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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue