From 8b3f6a7e536e022449a5cda1713af1dccb54aa45 Mon Sep 17 00:00:00 2001 From: yxxhero Date: Fri, 19 Mar 2021 19:10:57 +0800 Subject: [PATCH] fix defaultIngress template Signed-off-by: yxxhero --- pkg/chartutil/create.go | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index ee6bf7721..a8e835a77 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -216,9 +216,13 @@ const defaultIgnore = `# Patterns to ignore when building packages. const defaultIngress = `{{- if .Values.ingress.enabled -}} {{- $fullName := include ".fullname" . -}} {{- $svcPort := .Values.service.port -}} -{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +{{- if eq "true" (include ".ingressApiVersionChanged" .) }} +{{- if semverCompare "<1.19-0" .Capabilities.KubeVersion.GitVersion -}} apiVersion: networking.k8s.io/v1beta1 {{- else -}} +apiVersion: networking.k8s.io/v1 +{{- end }} +{{- else -}} apiVersion: extensions/v1beta1 {{- end }} kind: Ingress @@ -242,6 +246,22 @@ spec: {{- end }} {{- end }} rules: + {{- if eq "true" (include ".ingressApiVersionChanged" .) }} + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: Prefix + backend: + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- end }} + {{- end }} + {{- else }} {{- range .Values.ingress.hosts }} - host: {{ .host | quote }} http: @@ -253,7 +273,8 @@ spec: servicePort: {{ $svcPort }} {{- end }} {{- end }} - {{- end }} + {{- end }} +{{- end }} ` const defaultDeployment = `apiVersion: apps/v1 @@ -436,6 +457,17 @@ Create chart name and version as used by the chart label. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end }} +{{/* +According to the kubernetes version, judge whether the content of ingress needs to be updated. +*/}} +{{- define ".ingressApiVersionChanged" -}} +{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion }} +{{- printf "%s" "true" }} +{{- else }} +{{- printf "%s" "false" }} +{{- end }} +{{- end }} + {{/* Common labels */}}