Skip to content

Commit

Permalink
merge(#976): refactored Ingress chart template
Browse files Browse the repository at this point in the history
  • Loading branch information
akijakya authored Jan 20, 2023
2 parents 609a98f + ba8979c commit 2215086
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion charts/cloudinfo/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
description: Cloud instance type and price information as a service
name: cloudinfo
version: 0.9.0
version: 0.10.0

appVersion: "0.18.0"

Expand Down
49 changes: 36 additions & 13 deletions charts/cloudinfo/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{{- if .Values.frontend.ingress.enabled -}}
{{- $fullName := include "cloudinfo.frontend.fullname" . -}}
{{- $svcPort := .Values.frontend.service.port -}}
{{- if and .Values.frontend.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.frontend.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.frontend.ingress.annotations "kubernetes.io/ingress.class" .Values.frontend.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 }}
Expand All @@ -15,29 +27,40 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ingressClassName: {{ .Values.frontend.ingress.ingressClassName }}
{{- if .Values.frontend.ingress.tls }}
{{- if and .Values.frontend.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.frontend.ingress.className }}
{{- end }}
{{- if .Values.frontend.ingress.tls }}
tls:
{{- range .Values.frontend.ingress.tls }}
{{- range .Values.frontend.ingress.tls }}
- hosts:
{{- range .hosts }}
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
{{- end }}
rules:
{{- range .Values.frontend.ingress.hosts }}
{{- $url := splitList "/" . }}
- host: {{ first $url }}
{{- range .Values.frontend.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
- path: /{{ rest $url | join "/" }}
pathType: {{ .Values.frontend.ingress.pathType }}
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ .Values.frontend.service.port }}
{{- end }}
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

18 changes: 15 additions & 3 deletions charts/cloudinfo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,31 @@ frontend:
port: 80

ingress:
# -- Enable [ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/).
enabled: false
ingressClassName: traefik

# -- Ingress [class name](https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class).
className: ""

# -- Annotations to be added to the ingress.
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"

# -- Ingress host configuration.
# @default -- See [values.yaml](values.yaml).
hosts:
- "/"
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific

# -- Ingress TLS configuration.
# @default -- See [values.yaml](values.yaml).
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
pathType: Prefix

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
Expand Down

0 comments on commit 2215086

Please sign in to comment.