Skip to content

Commit

Permalink
修复ingress 多版本kubernetes api 兼容 1.18上测试通过
Browse files Browse the repository at this point in the history
  • Loading branch information
AceAttorney committed Jan 15, 2022
1 parent 0c9b0c4 commit e2e179a
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/charts/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
{{- $fullName := include "archery.fullname" . -}}
{{- $ingressPaths := .Values.ingress.paths -}}
{{- $servicePort := .Values.ingress.servicePort -}}
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" }}
apiVersion: networking.k8s.io/v1
{{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1/Ingress" }}
apiVersion: networking.k8s.io/v1beta1
{{- else }}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
Expand All @@ -16,26 +22,29 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . | quote }}
{{- range .Values.ingress.hosts }}
{{- $url := splitList "/" . }}
- host: {{ first $url }}
http:
paths:
{{- range $ingressPaths }}
- path: {{ . }}
- path: /{{ rest $url | join "/" }}
backend:
{{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" }}
service:
name: {{ $fullName }}
port:
number: {{ $servicePort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $servicePort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" }}
pathType: Prefix
{{- end }}
{{- end -}}
{{- if .Values.ingress.tls }}
tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
{{- end -}}
{{- end -}}

0 comments on commit e2e179a

Please sign in to comment.