Skip to content

Commit

Permalink
Merge pull request #557 from mkilchhofer/feature/helm_ingressClassName
Browse files Browse the repository at this point in the history
chart: Implement setting ingressClassName
  • Loading branch information
yolossn authored Jan 27, 2022
2 parents 99d2dcf + bf5229c commit 34b9bc4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion charts/nebraska/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sources:
maintainers:
- name: kinvolk
url: https://kinvolk.io/
version: 0.1.11
version: 0.2.0
appVersion: "2.5.1"

dependencies:
Expand Down
4 changes: 4 additions & 0 deletions charts/nebraska/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ $ helm install my-nebraska nebraska/nebraska
| `ingress.enabled` | Enable ingress controller resource | `true` |
| `ingress.annotations` | Annotations for Ingress resource | `{}` |
| `ingress.hosts` | Hostname(s) for the Ingress resource | `["flatcar.example.com"]` |
| `ingress.ingressClassName` | Ingress controller which implements the resource. This replaces the deprecated `kubernetes.io/ingress.class` annotation on K8s > 1.19 | `""` |
| `ingress.tls` | Ingress TLS configuration | `[]` |
| `ingress.update.enabled` | Create a separate ingress for the `/v1/update` and `/flatcar` paths, with it's own annotations. | `false` |
| `ingress.update.annotations` | Annotations for Ingress resource | `{}` |
| `ingress.update.ingressClassName` | Ingress controller which implements the resource. This replaces the deprecated `kubernetes.io/ingress.class` annotation on K8s > 1.19 | `""` |
| `resources` | CPU/Memory resource requests/limits | `{}` |
| `nodeSelector` | Node labels for pod assignment | `{}` |
| `tolerations` | Toleration labels for pod assignment | `[]` |
Expand Down
13 changes: 13 additions & 0 deletions charts/nebraska/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for ingress
*/}}
{{- define "nebraska.ingress.apiVersion" -}}
{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.Version -}}
{{- print "extensions/v1beta1" -}}
{{- else if semverCompare "<1.19-0" .Capabilities.KubeVersion.Version -}}
{{- print "networking.k8s.io/v1beta1" -}}
{{- else -}}
{{- print "networking.k8s.io/v1" -}}
{{- end -}}
{{- end -}}

{{- define "nebraska.ingressScheme" -}}
http{{ if $.Values.ingress.tls }}s{{ end }}
{{- end -}}
Expand Down
16 changes: 7 additions & 9 deletions charts/nebraska/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{{- if .Values.ingress.enabled }}
{{- $fullName := include "nebraska.fullname" . }}
{{- $svcPort := .Values.service.port }}
{{- $kubeGitVersion := .Capabilities.KubeVersion.GitVersion }}
{{- if semverCompare ">=1.19-0" $kubeGitVersion }}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" $kubeGitVersion }}
apiVersion: networking.k8s.io/v1beta1
{{- else }}
apiVersion: extensions/v1beta1
{{- end }}
apiVersion: {{ include "nebraska.ingress.apiVersion" . }}
kind: Ingress
metadata:
name: {{ $fullName }}
Expand All @@ -19,6 +12,11 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if eq (include "nebraska.ingress.apiVersion" $) "networking.k8s.io/v1" }}
{{- with .Values.ingress.ingressClassName }}
ingressClassName: {{ . }}
{{- end }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
Expand All @@ -36,7 +34,7 @@ spec:
paths:
- path: /
backend:
{{- if semverCompare ">=1.19-0" $kubeGitVersion }}
{{- if eq (include "nebraska.ingress.apiVersion" $) "networking.k8s.io/v1" }}
service:
name: {{ $fullName }}
port:
Expand Down
18 changes: 8 additions & 10 deletions charts/nebraska/templates/update-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{{- if and .Values.ingress.enabled .Values.ingress.update.enabled }}
{{- $fullName := include "nebraska.fullname" . }}
{{- $svcPort := .Values.service.port }}
{{- $kubeGitVersion := .Capabilities.KubeVersion.GitVersion }}
{{- if semverCompare ">=1.19-0" $kubeGitVersion }}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" $kubeGitVersion }}
apiVersion: networking.k8s.io/v1beta1
{{- else }}
apiVersion: extensions/v1beta1
{{- end }}
apiVersion: {{ include "nebraska.ingress.apiVersion" . }}
kind: Ingress
metadata:
name: {{ $fullName | trunc 56 | trimSuffix "-" }}-update
Expand All @@ -19,6 +12,11 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if eq (include "nebraska.ingress.apiVersion" $) "networking.k8s.io/v1" }}
{{- with .Values.ingress.update.ingressClassName }}
ingressClassName: {{ . }}
{{- end }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
Expand All @@ -36,7 +34,7 @@ spec:
paths:
- path: /v1/update
backend:
{{- if semverCompare ">=1.19-0" $kubeGitVersion }}
{{- if eq (include "nebraska.ingress.apiVersion" $) "networking.k8s.io/v1" }}
service:
name: {{ $fullName }}
port:
Expand All @@ -53,7 +51,7 @@ spec:
- path: /flatcar
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $kubeGitVersion }}
{{- if eq (include "nebraska.ingress.apiVersion" $) "networking.k8s.io/v1" }}
service:
name: {{ $fullName }}
port:
Expand Down
2 changes: 2 additions & 0 deletions charts/nebraska/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ ingress:
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
ingressClassName: ""
update:
# Create a separate ingress for the /v1/update and /flatcar paths,
# with it's own annotations.
enabled: false
annotations: {}
ingressClassName: ""
hosts:
- flatcar.example.com
tls: []
Expand Down

0 comments on commit 34b9bc4

Please sign in to comment.