From 8ee36ab42a00ca8a53b982f6ac508567da363429 Mon Sep 17 00:00:00 2001 From: Yonatan Rubin Date: Tue, 26 Sep 2023 13:30:26 +0300 Subject: [PATCH 1/6] allow loadbalancer service external IP --- application/templates/service.yaml | 33 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/application/templates/service.yaml b/application/templates/service.yaml index 49b3493f..942d132c 100644 --- a/application/templates/service.yaml +++ b/application/templates/service.yaml @@ -7,20 +7,35 @@ metadata: namespace: {{ template "application.namespace" $ }} labels: {{- include "application.labels" . | nindent 4 }} -{{- if .Values.service.additionalLabels }} -{{ toYaml .Values.service.additionalLabels | indent 4 }} -{{- end }} -{{- if .Values.service.annotations }} + {{- if .Values.service.additionalLabels }} + {{ toYaml .Values.service.additionalLabels | indent 4 }} + {{- end }} + {{- if .Values.service.annotations }} annotations: {{ include "application.tplvalues.render" ( dict "value" .Values.service.annotations "context" $ ) | indent 4 }} {{- end }} spec: -{{- if .Values.service.type }} - type: "{{ .Values.service.type }}" -{{- end }} -{{- with .Values.service.clusterIP }} +{{- if (or (eq .Values.service.type "ClusterIP") (empty .Values.service.type)) }} + type: ClusterIP + {{- with .Values.service.clusterIP }} clusterIP: {{ . }} -{{- end }} + {{- end }} + {{- else if eq .Values.service.type "LoadBalancer" }} + type: {{ .Values.service.type }} + {{- with .Values.service.loadBalancerIP }} + loadBalancerIP: {{ . }} + {{- end }} + {{- with .Values.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- else }} + type: {{ .Values.service.type }} + {{- end }} + {{- with .Values.service.externalIPs }} + externalIPs: + {{- toYaml . | nindent 4 }} + {{- end }} selector: {{ include "application.selectorLabels" . | indent 4 }} {{- if .Values.deployment.podLabels }} From e90b5d3f9fca3b26ab57198eac17664a9f97fdcc Mon Sep 17 00:00:00 2001 From: d3adb5 Date: Sun, 7 Jan 2024 14:05:31 -0800 Subject: [PATCH 2/6] refactor: define service type outside conditionals Define the type property of our Service spec outside the branches of these conditional statements, as it should always honor the chart value. --- application/templates/service.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/application/templates/service.yaml b/application/templates/service.yaml index 942d132c..e6b968dd 100644 --- a/application/templates/service.yaml +++ b/application/templates/service.yaml @@ -15,13 +15,12 @@ metadata: {{ include "application.tplvalues.render" ( dict "value" .Values.service.annotations "context" $ ) | indent 4 }} {{- end }} spec: + type: {{ .Values.service.type }} {{- if (or (eq .Values.service.type "ClusterIP") (empty .Values.service.type)) }} - type: ClusterIP {{- with .Values.service.clusterIP }} clusterIP: {{ . }} {{- end }} {{- else if eq .Values.service.type "LoadBalancer" }} - type: {{ .Values.service.type }} {{- with .Values.service.loadBalancerIP }} loadBalancerIP: {{ . }} {{- end }} @@ -30,7 +29,6 @@ spec: {{- toYaml . | nindent 4 }} {{- end }} {{- else }} - type: {{ .Values.service.type }} {{- end }} {{- with .Values.service.externalIPs }} externalIPs: From ac230da2071ff1baf130386115a258e36843e892 Mon Sep 17 00:00:00 2001 From: d3adb5 Date: Sun, 7 Jan 2024 14:09:51 -0800 Subject: [PATCH 3/6] fix: proxy cluster ip value for all service types Proxy the chart value for the Service's clusterIP field for all service types. --- application/templates/service.yaml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/application/templates/service.yaml b/application/templates/service.yaml index e6b968dd..556e440d 100644 --- a/application/templates/service.yaml +++ b/application/templates/service.yaml @@ -16,11 +16,9 @@ metadata: {{- end }} spec: type: {{ .Values.service.type }} + clusterIP: {{ .Values.service.clusterIP }} {{- if (or (eq .Values.service.type "ClusterIP") (empty .Values.service.type)) }} - {{- with .Values.service.clusterIP }} - clusterIP: {{ . }} - {{- end }} - {{- else if eq .Values.service.type "LoadBalancer" }} +{{- else if eq .Values.service.type "LoadBalancer" }} {{- with .Values.service.loadBalancerIP }} loadBalancerIP: {{ . }} {{- end }} @@ -28,8 +26,7 @@ spec: loadBalancerSourceRanges: {{- toYaml . | nindent 4 }} {{- end }} - {{- else }} - {{- end }} +{{- end }} {{- with .Values.service.externalIPs }} externalIPs: {{- toYaml . | nindent 4 }} From 7380d160125f6298c571cf7527ae268a42452746 Mon Sep 17 00:00:00 2001 From: d3adb5 Date: Sun, 7 Jan 2024 14:14:34 -0800 Subject: [PATCH 4/6] refactor: remove empty conditional branch Remove empty conditional branch from the Service template. --- application/templates/service.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/templates/service.yaml b/application/templates/service.yaml index 556e440d..e6c88325 100644 --- a/application/templates/service.yaml +++ b/application/templates/service.yaml @@ -17,8 +17,7 @@ metadata: spec: type: {{ .Values.service.type }} clusterIP: {{ .Values.service.clusterIP }} -{{- if (or (eq .Values.service.type "ClusterIP") (empty .Values.service.type)) }} -{{- else if eq .Values.service.type "LoadBalancer" }} +{{- if eq .Values.service.type "LoadBalancer" }} {{- with .Values.service.loadBalancerIP }} loadBalancerIP: {{ . }} {{- end }} From 5488bbc1653be44d92563845f6eac216665f2986 Mon Sep 17 00:00:00 2001 From: d3adb5 Date: Sun, 7 Jan 2024 14:20:58 -0800 Subject: [PATCH 5/6] feat: warn the user of the deprecation of load-balancer-ip Warn the chart's user of the deprecation of the Service loadBalacerIP field since Kubernetes v1.24. --- application/templates/NOTES.txt | 8 ++++++++ application/tests/notes_test.yaml | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 application/templates/NOTES.txt create mode 100644 application/tests/notes_test.yaml diff --git a/application/templates/NOTES.txt b/application/templates/NOTES.txt new file mode 100644 index 00000000..e0c46719 --- /dev/null +++ b/application/templates/NOTES.txt @@ -0,0 +1,8 @@ +{{- if .Values.service.loadBalancerIP }} +service.loadBalancerIP: + You have defined the value of service.loadBalancerIP for this release. Please + be mindful that this field has been deprecated as of Kubernetes v1.24 and may + be removed from the API in a later release. + + Please refer to the Kubernetes documentation for more information. +{{- end }} diff --git a/application/tests/notes_test.yaml b/application/tests/notes_test.yaml new file mode 100644 index 00000000..c80e08e8 --- /dev/null +++ b/application/tests/notes_test.yaml @@ -0,0 +1,19 @@ +suite: NOTES.txt + +templates: + - NOTES.txt + +tests: + - it: warns the user of the deprecation of loadBalancerIP + set: + service.loadBalancerIP: 1.1.1.1 + asserts: + - matchRegexRaw: + pattern: 'service.loadBalancerIP:' + + - it: does not emit a warning for loadBalancerIP when not set + set: + service.loadBalancerIP: null + asserts: + - notMatchRegexRaw: + pattern: 'service.loadBalancerIP:' From 0bd9dabec89d35eb4351005ab3f32fe8a273b006 Mon Sep 17 00:00:00 2001 From: d3adb5 Date: Sun, 7 Jan 2024 14:26:39 -0800 Subject: [PATCH 6/6] fix: address whitespace concerns in service metadata Address whitespace concerns when rendering Service labels and annotations. --- application/templates/service.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/templates/service.yaml b/application/templates/service.yaml index e6c88325..2286377d 100644 --- a/application/templates/service.yaml +++ b/application/templates/service.yaml @@ -8,11 +8,11 @@ metadata: labels: {{- include "application.labels" . | nindent 4 }} {{- if .Values.service.additionalLabels }} - {{ toYaml .Values.service.additionalLabels | indent 4 }} + {{- toYaml .Values.service.additionalLabels | nindent 4 }} {{- end }} {{- if .Values.service.annotations }} annotations: -{{ include "application.tplvalues.render" ( dict "value" .Values.service.annotations "context" $ ) | indent 4 }} + {{- include "application.tplvalues.render" ( dict "value" .Values.service.annotations "context" $ ) | nindent 4 }} {{- end }} spec: type: {{ .Values.service.type }}