From a5359190259b6f503ebc41cf5e2d4409174c6a41 Mon Sep 17 00:00:00 2001 From: Karitham Date: Mon, 15 Jul 2024 15:13:25 +0000 Subject: [PATCH] feat: `service.{http,ssh}.loadBalancerClass` (#640) ### Description of the change Introduce `service.{http,ssh}.loadBalancerClass` ### Benefits Feature was not supported before. This is required if your cluster has multiple loadBalancer options and you want to select one ### Possible drawbacks More yaml. ### Checklist - [x] Parameters are documented in the `values.yaml` and added to the `README.md` using [readme-generator-for-helm](https://github.com/bitnami-labs/readme-generator-for-helm) - [x] Templating unittests are added Reviewed-on: https://gitea.com/gitea/helm-chart/pulls/640 Reviewed-by: pat-s Co-authored-by: Karitham Co-committed-by: Karitham --- README.md | 2 + templates/gitea/http-svc.yaml | 7 ++- templates/gitea/ssh-svc.yaml | 3 + unittests/deployment/svc-configuration.yaml | 67 +++++++++++++++++++++ values.yaml | 4 ++ 5 files changed, 82 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 52dc794..ec29243 100644 --- a/README.md +++ b/README.md @@ -904,6 +904,7 @@ To comply with the Gitea helm chart definition of the digest parameter, a "custo | `service.http.loadBalancerSourceRanges` | Source range filter for http loadbalancer | `[]` | | `service.http.annotations` | HTTP service annotations | `{}` | | `service.http.labels` | HTTP service additional labels | `{}` | +| `service.http.loadBalancerClass` | Loadbalancer class | `nil` | | `service.ssh.type` | Kubernetes service type for ssh traffic | `ClusterIP` | | `service.ssh.port` | Port number for ssh traffic | `22` | | `service.ssh.clusterIP` | ClusterIP setting for ssh autosetup for deployment is None | `None` | @@ -917,6 +918,7 @@ To comply with the Gitea helm chart definition of the digest parameter, a "custo | `service.ssh.loadBalancerSourceRanges` | Source range filter for ssh loadbalancer | `[]` | | `service.ssh.annotations` | SSH service annotations | `{}` | | `service.ssh.labels` | SSH service additional labels | `{}` | +| `service.ssh.loadBalancerClass` | Loadbalancer class | `nil` | ### Ingress diff --git a/templates/gitea/http-svc.yaml b/templates/gitea/http-svc.yaml index 0ec7370..06163a6 100644 --- a/templates/gitea/http-svc.yaml +++ b/templates/gitea/http-svc.yaml @@ -11,7 +11,11 @@ metadata: {{- toYaml .Values.service.http.annotations | nindent 4 }} spec: type: {{ .Values.service.http.type }} - {{- if and .Values.service.http.loadBalancerIP (eq .Values.service.http.type "LoadBalancer") }} + {{- if eq .Values.service.http.type "LoadBalancer" }} + {{- if .Values.service.http.loadBalancerClass }} + loadBalancerClass: {{ .Values.service.http.loadBalancerClass }} + {{- end }} + {{- if and .Values.service.http.loadBalancerIP }} loadBalancerIP: {{ .Values.service.http.loadBalancerIP }} {{- end }} {{- if .Values.service.http.loadBalancerSourceRanges }} @@ -20,6 +24,7 @@ spec: - {{ . }} {{- end }} {{- end }} + {{- end }} {{- if .Values.service.http.externalIPs }} externalIPs: {{- toYaml .Values.service.http.externalIPs | nindent 4 }} diff --git a/templates/gitea/ssh-svc.yaml b/templates/gitea/ssh-svc.yaml index 3ee756c..131b0b9 100644 --- a/templates/gitea/ssh-svc.yaml +++ b/templates/gitea/ssh-svc.yaml @@ -12,6 +12,9 @@ metadata: spec: type: {{ .Values.service.ssh.type }} {{- if eq .Values.service.ssh.type "LoadBalancer" }} + {{- if .Values.service.ssh.loadBalancerClass }} + loadBalancerClass: {{ .Values.service.ssh.loadBalancerClass }} + {{- end }} {{- if .Values.service.ssh.loadBalancerIP }} loadBalancerIP: {{ .Values.service.ssh.loadBalancerIP }} {{- end -}} diff --git a/unittests/deployment/svc-configuration.yaml b/unittests/deployment/svc-configuration.yaml index a032470..24059ea 100644 --- a/unittests/deployment/svc-configuration.yaml +++ b/unittests/deployment/svc-configuration.yaml @@ -49,3 +49,70 @@ tests: asserts: - exists: path: metadata.labels["app"] + + - it: render service.ssh.loadBalancerClass if set and type is LoadBalancer + template: templates/gitea/ssh-svc.yaml + set: + service: + ssh: + loadBalancerClass: "example.com/class" + type: LoadBalancer + loadBalancerIP: "1.2.3.4" + loadBalancerSourceRanges: + - "1.2.3.4/32" + - "5.6.7.8/32" + asserts: + - equal: + path: spec.loadBalancerClass + value: "example.com/class" + - equal: + path: spec.loadBalancerIP + value: "1.2.3.4" + - equal: + path: spec.loadBalancerSourceRanges + value: ["1.2.3.4/32", "5.6.7.8/32"] + + - it: does not render when loadbalancer properties are set but type is not loadBalancerClass + template: templates/gitea/http-svc.yaml + set: + service: + http: + type: ClusterIP + loadBalancerClass: "example.com/class" + loadBalancerIP: "1.2.3.4" + loadBalancerSourceRanges: + - "1.2.3.4/32" + - "5.6.7.8/32" + asserts: + - notExists: + path: spec.loadBalancerClass + - notExists: + path: spec.loadBalancerIP + - notExists: + path: spec.loadBalancerSourceRanges + + - it: does not render loadBalancerClass by default even when type is LoadBalancer + template: templates/gitea/http-svc.yaml + set: + service: + http: + type: LoadBalancer + loadBalancerIP: "1.2.3.4" + asserts: + - notExists: + path: spec.loadBalancerClass + - equal: + path: spec.loadBalancerIP + value: "1.2.3.4" + + - it: both ssh and http services exist + templates: + - templates/gitea/ssh-svc.yaml + - templates/gitea/http-svc.yaml + asserts: + - matchRegex: + path: metadata.name + pattern: "^gitea-unittests-(?:ssh|http)$" + - matchRegex: + path: spec.ports[0].name + pattern: "^(?:ssh|http)$" diff --git a/values.yaml b/values.yaml index a44eca9..af66f24 100644 --- a/values.yaml +++ b/values.yaml @@ -107,6 +107,7 @@ service: ## @param service.http.loadBalancerSourceRanges Source range filter for http loadbalancer ## @param service.http.annotations HTTP service annotations ## @param service.http.labels HTTP service additional labels + ## @param service.http.loadBalancerClass Loadbalancer class http: type: ClusterIP port: 3000 @@ -120,6 +121,7 @@ service: loadBalancerSourceRanges: [] annotations: {} labels: {} + loadBalancerClass: ## @param service.ssh.type Kubernetes service type for ssh traffic ## @param service.ssh.port Port number for ssh traffic ## @param service.ssh.clusterIP ClusterIP setting for ssh autosetup for deployment is None @@ -133,6 +135,7 @@ service: ## @param service.ssh.loadBalancerSourceRanges Source range filter for ssh loadbalancer ## @param service.ssh.annotations SSH service annotations ## @param service.ssh.labels SSH service additional labels + ## @param service.ssh.loadBalancerClass Loadbalancer class ssh: type: ClusterIP port: 22 @@ -147,6 +150,7 @@ service: loadBalancerSourceRanges: [] annotations: {} labels: {} + loadBalancerClass: ## @section Ingress ## @param ingress.enabled Enable ingress