diff --git a/charts/mercure/Chart.yaml b/charts/mercure/Chart.yaml index 0ba57c5b..56b61944 100644 --- a/charts/mercure/Chart.yaml +++ b/charts/mercure/Chart.yaml @@ -16,5 +16,5 @@ version: 0.21.2 appVersion: "v0.21.2" maintainers: - name: dunglas - email: kevin@dunglas.fr - url: https://dunglas.fr + email: kevin@dunglas.dev + url: https://dunglas.dev diff --git a/charts/mercure/templates/NOTES.txt b/charts/mercure/templates/NOTES.txt index c9f1d5ed..e2158220 100644 --- a/charts/mercure/templates/NOTES.txt +++ b/charts/mercure/templates/NOTES.txt @@ -1,5 +1,18 @@ 1. Get the URL of the Mercure Hub 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 }} diff --git a/charts/mercure/templates/deployment.yaml b/charts/mercure/templates/deployment.yaml index 4d06bfb9..91e531c1 100644 --- a/charts/mercure/templates/deployment.yaml +++ b/charts/mercure/templates/deployment.yaml @@ -20,19 +20,26 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} labels: - {{- include "mercure.selectorLabels" . | nindent 8 }} + {{- include "mercure.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} serviceAccountName: {{ include "mercure.serviceAccountName" . }} + {{- with .Values.podSecurityContext }} securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- toYaml . | nindent 8 }} + {{- end }} containers: - name: {{ .Chart.Name }} + {{- with .Values.securityContext }} securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} + {{- toYaml . | nindent 12 }} + {{- end }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" {{- if .Values.dev }} command: ["caddy"] diff --git a/charts/mercure/templates/hpa.yaml b/charts/mercure/templates/hpa.yaml index a1edc9f5..b755d466 100644 --- a/charts/mercure/templates/hpa.yaml +++ b/charts/mercure/templates/hpa.yaml @@ -1,9 +1,5 @@ {{- if .Values.autoscaling.enabled }} -{{- if .Capabilities.APIVersions.Has "autoscaling/v2" }} apiVersion: autoscaling/v2 -{{- else }} -apiVersion: autoscaling/v2beta1 -{{- end }} kind: HorizontalPodAutoscaler metadata: name: {{ include "mercure.fullname" . }} @@ -21,24 +17,16 @@ spec: - type: Resource resource: name: cpu - {{- if .Capabilities.APIVersions.Has "autoscaling/v2" }} target: type: Utilization averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} - {{- else }} - targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} - {{- end }} {{- end }} {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} - type: Resource resource: name: memory - {{- if .Capabilities.APIVersions.Has "autoscaling/v2" }} target: type: Utilization averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} - {{- else }} - targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} - {{- end }} {{- end }} {{- end }} diff --git a/charts/mercure/templates/httproute.yaml b/charts/mercure/templates/httproute.yaml new file mode 100644 index 00000000..8b11fe57 --- /dev/null +++ b/charts/mercure/templates/httproute.yaml @@ -0,0 +1,38 @@ +{{- if .Values.httpRoute.enabled -}} +{{- $fullName := include "mercure.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: {{ $fullName }} + labels: + {{- include "mercure.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 }} diff --git a/charts/mercure/templates/ingress.yaml b/charts/mercure/templates/ingress.yaml index 8d1a2fd8..ec3ad227 100644 --- a/charts/mercure/templates/ingress.yaml +++ b/charts/mercure/templates/ingress.yaml @@ -1,21 +1,8 @@ {{- if .Values.ingress.enabled -}} -{{- $fullName := include "mercure.fullname" . -}} -{{- $svcPort := .Values.service.port -}} -{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} - {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} - {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} - {{- end }} -{{- end }} -{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} apiVersion: networking.k8s.io/v1 -{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} -apiVersion: networking.k8s.io/v1beta1 -{{- else -}} -apiVersion: extensions/v1beta1 -{{- end }} kind: Ingress metadata: - name: {{ $fullName }} + name: {{ include "mercure.fullname" . }} labels: {{- include "mercure.labels" . | nindent 4 }} {{- with .Values.ingress.annotations }} @@ -23,8 +10,8 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} spec: - {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} - ingressClassName: {{ .Values.ingress.className }} + {{- with .Values.ingress.className }} + ingressClassName: {{ . }} {{- end }} {{- if .Values.ingress.tls }} tls: @@ -43,19 +30,14 @@ spec: paths: {{- range .paths }} - path: {{ .path }} - {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} - pathType: {{ .pathType }} + {{- with .pathType }} + pathType: {{ . }} {{- end }} backend: - {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} service: - name: {{ $fullName }} + name: {{ include "mercure.fullname" $ }} port: - number: {{ $svcPort }} - {{- else }} - serviceName: {{ $fullName }} - servicePort: {{ $svcPort }} - {{- end }} + number: {{ $.Values.service.port }} {{- end }} {{- end }} {{- end }} diff --git a/charts/mercure/templates/serviceaccount.yaml b/charts/mercure/templates/serviceaccount.yaml index f14cd4db..650f479e 100644 --- a/charts/mercure/templates/serviceaccount.yaml +++ b/charts/mercure/templates/serviceaccount.yaml @@ -9,4 +9,5 @@ metadata: annotations: {{- toYaml . | nindent 4 }} {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} {{- end }} diff --git a/charts/mercure/values.yaml b/charts/mercure/values.yaml index 399173b5..239c97ba 100644 --- a/charts/mercure/values.yaml +++ b/charts/mercure/values.yaml @@ -90,6 +90,8 @@ fullnameOverride: "" serviceAccount: # -- Specifies whether a service account should be created. create: true + # -- Automatically mount a ServiceAccount's API credentials? + automount: true # -- Annotations to add to the service account. annotations: {} # -- The name of the service account to use. @@ -99,6 +101,10 @@ serviceAccount: # -- Annotations to be added to pods. podAnnotations: {} +# This is for setting Kubernetes Labels to a Pod. +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ +podLabels: {} + # -- Pod [security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod). # See the [API reference](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#security-context) for details. podSecurityContext: {} @@ -148,6 +154,44 @@ ingress: # hosts: # - mercure-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: + - mercure-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 + # -- Container resource [requests and limits](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/). # See the [API reference](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#resources) for details. # @default -- No requests or limits.