From 0bfe6ee78eeeea5625c32bb5a591512d67e6c54e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20Larivi=C3=A8re?= Date: Fri, 18 Apr 2025 14:20:54 -0400 Subject: [PATCH 1/2] feat(gw-apis): Support GW-APIS HTTPRoute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add helm unittest to run helm unit tests on specific helm templates - modify readme to add web.route.* - update values - update .gitignore/.helmignore Signed-off-by: Christopher Larivière --- .gitignore | 2 + .helmignore | 2 + README.md | 27 ++++ templates/web-route.yaml | 38 +++++ .../unittest/gateway-apis/web-route-test.yaml | 151 ++++++++++++++++++ values.yaml | 35 ++++ 6 files changed, 255 insertions(+) create mode 100644 templates/web-route.yaml create mode 100644 test/unittest/gateway-apis/web-route-test.yaml diff --git a/.gitignore b/.gitignore index eea54c36..f389ff1e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ charts [._]s[a-rt-v][a-z] [._]ss[a-gi-z] [._]sw[a-p] + +__snapshot__ \ No newline at end of file diff --git a/.helmignore b/.helmignore index 8904c0d2..e09cb823 100644 --- a/.helmignore +++ b/.helmignore @@ -20,3 +20,5 @@ .idea/ *.tmprojt tests/ + +__snapshot__/ \ No newline at end of file diff --git a/README.md b/README.md index e6853e18..85b36fab 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,11 @@ The following table lists the configurable parameters of the Concourse chart and | `web.ingress.ingressClassName` | IngressClass to register to | `nil` | | `web.ingress.rulesOverride` | Concourse Web Ingress rules (override) (alternate to `web.ingress.hosts`) | `[]` | | `web.ingress.tls` | Concourse Web Ingress TLS configuration | `[]` | +| `web.route.annotations` | Concourse Web HTTPRoute annotations | `{}` | +| `web.route.enabled` | Enable Concourse Web HTTPRoute | `false` | +| `web.route.hosts` | Concourse Web HTTPRoutes Hostnames | `[]` | +| `web.route.labels` | Concourse Web HTTPRoute labels | `{}` | +| `web.route.parentRefs` | Concourse Web HTTPRoute parentRefs (gateways) | `{}` | | `web.keySecretsPath` | Specify the mount directory of the web keys secrets | `/concourse-keys` | | `web.labels`| Additional labels to be added to the web deployment `metadata.labels` | `{}` | | `web.deploymentAnnotations` | Additional annotations to be added to the web deployment `metadata.annotations` | `{}` | @@ -768,3 +773,25 @@ Instead, you may add a comment specifying the default, such as This prevents the behaviour drifting from that of the binary in case the binary's default values change. We understand that the comment stating the binary's default can become stale. The current solution is a suboptimal one. It may be improved in the future by generating a list of the default values from the binary. + +## Helm Unit Test + +When running unit tests for helm, from the root of the repository, you can simply run the following. + +```bash +helm unittest -f test/unittest/**/*.yaml . +``` + +If you are debugging specific tests, simply target the folder or yaml file you want to run tests on. + +`Folder` + +```bash +helm unittest -f test/unittest/gateway-apis/*.yaml . +``` + +`Specific Test Suite` + +```bash +helm unittest -f test/unittest/gateway-apis/web-route-test.yaml . +``` \ No newline at end of file diff --git a/templates/web-route.yaml b/templates/web-route.yaml new file mode 100644 index 00000000..1b5918bc --- /dev/null +++ b/templates/web-route.yaml @@ -0,0 +1,38 @@ +{{- if .Values.web.enabled -}} +{{- if .Values.web.route.enabled -}} +{{- $route := .Values.web.route -}} +{{- $releaseName := .Release.Name -}} +{{- $serviceName := include "concourse.web.fullname" . -}} +{{- $servicePort := .Values.concourse.web.bindPort -}} +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: {{ template "concourse.web.fullname" . }} + labels: + app: {{ template "concourse.web.fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" + {{- with $route.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with $route.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + parentRefs: + {{- toYaml $route.parentRefs | nindent 2 }} + hostnames: + {{- toYaml $route.hosts | nindent 2 }} + rules: + - matches: + - path: + type: PathPrefix + value: / + backendRefs: + - name: {{ $serviceName }} + port: {{ $servicePort }} + namespace: {{ .Release.Namespace | quote }} +{{- end -}} +{{- end -}} diff --git a/test/unittest/gateway-apis/web-route-test.yaml b/test/unittest/gateway-apis/web-route-test.yaml new file mode 100644 index 00000000..5cbe2c39 --- /dev/null +++ b/test/unittest/gateway-apis/web-route-test.yaml @@ -0,0 +1,151 @@ +suite: GatewayApis + +tests: + - it: Route Disabled + set: + web: + route: + enabled: false + template: web-route.yaml + asserts: + - hasDocuments: + count: 0 + + - it: Route Exposure + set: + web: + route: + enabled: true + parentRefs: + - name: test-parent + namespace: test-namespace + group: gateway.networking.k8s.io + sectionName: test-section + kind: Gateway + hostnames: + - concourse.example.com + template: web-route.yaml + asserts: + - equal: + path: spec.hostnames[0] + value: concourse.example.com + - equal: + path: spec.parentRefs[0].name + value: test-parent + - equal: + path: spec.parentRefs[0].namespace + value: test-namespace + - equal: + path: spec.parentRefs[0].group + value: gateway.networking.k8s.io + - equal: + path: spec.parentRefs[0].sectionName + value: test-section + - equal: + path: spec.parentRefs[0].kind + value: Gateway + + - it: Route Extra Annotations + set: + web: + route: + enabled: true + annotations: + test.annotation: test-annotation + parentRefs: + - name: test-parent + namespace: test-namespace + hostnames: + - concourse.example.com + template: templates/web-route.yaml + asserts: + - equal: + path: metadata.annotations["test.annotation"] + value: test-annotation + + - it: Route Extra Labels + set: + web: + route: + enabled: true + labels: + test.label: test-label + parentRefs: + - name: test-parent + namespace: test-namespace + hostnames: + - concourse.example.com + template: web-route.yaml + asserts: + - equal: + path: metadata.labels["test.label"] + value: test-label + + - it: Route Service Exposure + set: + web: + route: + enabled: true + parentRefs: + - name: test-parent + namespace: test-namespace + hostnames: + - concourse.example.com + template: web-route.yaml + asserts: + - equal: + path: spec.rules[0].backendRefs[0].name + value: RELEASE-NAME-web + - equal: + path: spec.rules[0].matches[0].path.value + value: / + - equal: + path: spec.rules[0].backendRefs[0].port + value: 8080 + + - it: Multiple Hostnames + set: + web: + route: + enabled: true + parentRefs: + - name: test-parent + namespace: test-namespace + hostnames: + - concourse.example.com + - concourse.alternate.com + template: web-route.yaml + asserts: + - equal: + path: spec.hostnames[0] + value: concourse.example.com + - equal: + path: spec.hostnames[1] + value: concourse.alternate.com + - lengthEqual: + path: spec.hostnames + count: 2 + + - it: Multiple ParentRefs + set: + web: + route: + enabled: true + parentRefs: + - name: test-parent-1 + namespace: test-namespace-1 + - name: test-parent-2 + namespace: test-namespace-2 + hostnames: + - concourse.example.com + template: web-route.yaml + asserts: + - equal: + path: spec.parentRefs[0].name + value: test-parent-1 + - equal: + path: spec.parentRefs[1].name + value: test-parent-2 + - lengthEqual: + path: spec.parentRefs + count: 2 diff --git a/values.yaml b/values.yaml index 3351860d..640efe24 100644 --- a/values.yaml +++ b/values.yaml @@ -2441,6 +2441,41 @@ web: ## tls: + ## Route configuration + ## Ref: https://gateway-api.sigs.k8s.io/api-types/httproute/ + ## + route: + + ## Enable HTTPRoutes + ## + enabled: false + + ## Label to be added to the web route. + ## Example: + ## my.label: my-label-value + ## + labels: {} + + ## Annotations to be added to the web route. + ## Example: + ## my.annotation: my-annotation-value + ## + annotations: {} + + ## Gateway API Parent Refs + ## Example + ## - name: envoy + ## namespace: networking + ## sectionName: https + ## group: gateway.networking.k8s.io + ## kind: Gateway + parentRefs: {} + + ## Hosts to attach to the HTTPRoute + ## Example: + ## - "concourse.example.com" + hosts: [] + ## Configuration values for Concourse Worker components. ## For more information regarding the characteristics of ## Concourse Workers, see https://concourse-ci.org/concourse-worker.html From ab662e70d565418fef218797e4ea9d971e7b8798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20Larivi=C3=A8re?= Date: Tue, 26 Aug 2025 20:05:53 -0400 Subject: [PATCH 2/2] incorrect mapping in values file + update readme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christopher Larivière --- README.md | 6 +++--- templates/web-route.yaml | 6 +++++- values.yaml | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 85b36fab..abde3cd9 100644 --- a/README.md +++ b/README.md @@ -200,9 +200,9 @@ The following table lists the configurable parameters of the Concourse chart and | `web.ingress.tls` | Concourse Web Ingress TLS configuration | `[]` | | `web.route.annotations` | Concourse Web HTTPRoute annotations | `{}` | | `web.route.enabled` | Enable Concourse Web HTTPRoute | `false` | -| `web.route.hosts` | Concourse Web HTTPRoutes Hostnames | `[]` | -| `web.route.labels` | Concourse Web HTTPRoute labels | `{}` | -| `web.route.parentRefs` | Concourse Web HTTPRoute parentRefs (gateways) | `{}` | +| `web.route.hostnames` | Concourse Web HTTPRoutes Hostnames | `[]` | +| `web.route.parentRefs` | Concourse Web HTTPRoute parentRefs (gateways) | `[]` | +| `web.route.labels` | Concourse Web HTTPRoute labels | `[]` | | `web.keySecretsPath` | Specify the mount directory of the web keys secrets | `/concourse-keys` | | `web.labels`| Additional labels to be added to the web deployment `metadata.labels` | `{}` | | `web.deploymentAnnotations` | Additional annotations to be added to the web deployment `metadata.annotations` | `{}` | diff --git a/templates/web-route.yaml b/templates/web-route.yaml index 1b5918bc..ba1b3b97 100644 --- a/templates/web-route.yaml +++ b/templates/web-route.yaml @@ -21,10 +21,14 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} spec: + {{- if and $route.parentRefs (gt (len $route.parentRefs) 0) }} parentRefs: {{- toYaml $route.parentRefs | nindent 2 }} + {{- end }} + {{- if and $route.hostnames (gt (len $route.hostnames) 0) }} hostnames: - {{- toYaml $route.hosts | nindent 2 }} + {{- toYaml $route.hostnames | nindent 2 }} + {{- end }} rules: - matches: - path: diff --git a/values.yaml b/values.yaml index 640efe24..9907f1f4 100644 --- a/values.yaml +++ b/values.yaml @@ -2469,12 +2469,12 @@ web: ## sectionName: https ## group: gateway.networking.k8s.io ## kind: Gateway - parentRefs: {} + parentRefs: [] ## Hosts to attach to the HTTPRoute ## Example: ## - "concourse.example.com" - hosts: [] + hostnames: [] ## Configuration values for Concourse Worker components. ## For more information regarding the characteristics of