From 52a64ac60982512d60d7965b6e13d4b67fc47672 Mon Sep 17 00:00:00 2001 From: Marco Kilchhofer Date: Mon, 24 Jan 2022 08:45:54 +0100 Subject: [PATCH 1/3] chart: Dedup code for ingress apiVersion evaluation --- charts/nebraska/templates/_helpers.tpl | 13 +++++++++++++ charts/nebraska/templates/ingress.yaml | 11 ++--------- charts/nebraska/templates/update-ingress.yaml | 13 +++---------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/charts/nebraska/templates/_helpers.tpl b/charts/nebraska/templates/_helpers.tpl index ec1fd205b..c94f9af07 100644 --- a/charts/nebraska/templates/_helpers.tpl +++ b/charts/nebraska/templates/_helpers.tpl @@ -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 -}} diff --git a/charts/nebraska/templates/ingress.yaml b/charts/nebraska/templates/ingress.yaml index 96404398a..ac25ffc5b 100644 --- a/charts/nebraska/templates/ingress.yaml +++ b/charts/nebraska/templates/ingress.yaml @@ -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 }} @@ -36,7 +29,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: diff --git a/charts/nebraska/templates/update-ingress.yaml b/charts/nebraska/templates/update-ingress.yaml index e992543c0..82044d0db 100644 --- a/charts/nebraska/templates/update-ingress.yaml +++ b/charts/nebraska/templates/update-ingress.yaml @@ -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 @@ -36,7 +29,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: @@ -53,7 +46,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: From 174cac91b8465dd0c5d9a2361147b7636c00c3a8 Mon Sep 17 00:00:00 2001 From: Marco Kilchhofer Date: Mon, 24 Jan 2022 08:48:03 +0100 Subject: [PATCH 2/3] chart: Implement setting ingressClassName --- charts/nebraska/Chart.yaml | 2 +- charts/nebraska/README.md | 2 ++ charts/nebraska/templates/ingress.yaml | 5 +++++ charts/nebraska/templates/update-ingress.yaml | 5 +++++ charts/nebraska/values.yaml | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/charts/nebraska/Chart.yaml b/charts/nebraska/Chart.yaml index b9b112ac0..56d69fd73 100644 --- a/charts/nebraska/Chart.yaml +++ b/charts/nebraska/Chart.yaml @@ -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: diff --git a/charts/nebraska/README.md b/charts/nebraska/README.md index e1d984e5e..1ab4d93b1 100644 --- a/charts/nebraska/README.md +++ b/charts/nebraska/README.md @@ -43,7 +43,9 @@ $ 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.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 | `[]` | diff --git a/charts/nebraska/templates/ingress.yaml b/charts/nebraska/templates/ingress.yaml index ac25ffc5b..529e82764 100644 --- a/charts/nebraska/templates/ingress.yaml +++ b/charts/nebraska/templates/ingress.yaml @@ -12,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 }} diff --git a/charts/nebraska/templates/update-ingress.yaml b/charts/nebraska/templates/update-ingress.yaml index 82044d0db..99ee94180 100644 --- a/charts/nebraska/templates/update-ingress.yaml +++ b/charts/nebraska/templates/update-ingress.yaml @@ -12,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 }} diff --git a/charts/nebraska/values.yaml b/charts/nebraska/values.yaml index 54dc9e267..7b1c85f28 100644 --- a/charts/nebraska/values.yaml +++ b/charts/nebraska/values.yaml @@ -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: [] From bf5229c8e63743aa828560381bae911986994186 Mon Sep 17 00:00:00 2001 From: Marco Kilchhofer Date: Mon, 24 Jan 2022 08:50:05 +0100 Subject: [PATCH 3/3] chart: Add missing docs from PR #345 --- charts/nebraska/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/charts/nebraska/README.md b/charts/nebraska/README.md index 1ab4d93b1..f684b6760 100644 --- a/charts/nebraska/README.md +++ b/charts/nebraska/README.md @@ -45,6 +45,8 @@ $ helm install my-nebraska nebraska/nebraska | `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 | `{}` |