Skip to content

Commit c3b67f6

Browse files
feat: add httproute template (#1211) (#1212)
* feat: add httproute template (#1211) * CI Automatic commit - align Chart version --------- Co-authored-by: codefresh-git-integration[bot] <151943927+codefresh-git-integration[bot]@users.noreply.github.com>
1 parent 8208b2c commit c3b67f6

9 files changed

Lines changed: 202 additions & 6 deletions

File tree

charts/gitops-runtime/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: 0.2.3
33
description: A Helm chart for Codefresh gitops runtime
44
name: gitops-runtime
5-
version: 0.29.12
5+
version: 0.29.13
66
home: https://github.com/codefresh-io/gitops-runtime-helm
77
icon: https://avatars1.githubusercontent.com/u/11412079?v=3
88
keywords:

charts/gitops-runtime/templates/_helpers.tpl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ Get ingress url for both tunnel based and ingress based runtimes
341341
{{- else }}
342342
{{ fail (printf "ERROR: Unsupported protocol %s for ingress. Only http and https supported" .Values.global.runtime.ingress.protocol)}}
343343
{{- end }}
344+
{{- else if .Values.global.runtime.httpRoute.enabled }}
345+
{{- if has .Values.global.runtime.httpRoute.protocol $supportedProtocols }}
346+
{{- printf "%s://%s" .Values.global.runtime.httpRoute.protocol (index .Values.global.runtime.httpRoute.hostnames 0)}}
347+
{{- else }}
348+
{{ fail (printf "ERROR: Unsupported protocol %s for httpRoute. Only http and https supported" .Values.global.runtime.httpRoute.protocol)}}
349+
{{- end }}
344350
{{/* If tunnel client is enabled - ingress url is <accoundId>-<runtimename>.<tunnel-subdomain> */}}
345351
{{- else if index .Values "tunnel-client" "enabled" }}
346352
{{- $accoundId := required "global.codefresh.accountId is required for tunnel based runtime" .Values.global.codefresh.accountId }}
@@ -357,7 +363,7 @@ Get ingress url for both tunnel based and ingress based runtimes
357363
{{- fail "ERROR: Only http and https are supported for global.runtime.ingressUrl"}}
358364
{{- end }}
359365
{{- else }}
360-
{{- fail "ERROR: When global.runtime.ingress.enabled is false and tunnel-client.enabled is false - global.runtime.ingressUrl must be provided" }}
366+
{{- fail "ERROR: When global.runtime.ingress.enabled and global.runtime.httpRoute.enabled are false and tunnel-client.enabled is false - global.runtime.ingressUrl must be provided" }}
361367
{{- end }}
362368
{{- end }}
363369
{{- end }}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{{- if .Values.global.runtime.httpRoute.enabled -}}
2+
{{- $svcName := include "internal-router.fullname" (dict "Values" (get .Values "internal-router")) -}}
3+
{{- $svcPort := index .Values "internal-router" "service" "port" -}}
4+
apiVersion: gateway.networking.k8s.io/v1
5+
kind: HTTPRoute
6+
metadata:
7+
name: codefresh-gitops-runtime
8+
labels:
9+
{{- include "codefresh-gitops-runtime.labels" . | nindent 4 }}
10+
{{- with .Values.global.runtime.httpRoute.labels }}
11+
{{- toYaml . | nindent 4 }}
12+
{{- end }}
13+
{{- with .Values.global.runtime.httpRoute.annotations }}
14+
annotations:
15+
{{- toYaml . | nindent 4 }}
16+
{{- end }}
17+
spec:
18+
parentRefs:
19+
{{- if .Values.global.runtime.httpRoute.parentRefs }}
20+
{{- toYaml .Values.global.runtime.httpRoute.parentRefs | nindent 4 }}
21+
{{- else }}
22+
{{- fail "ERROR: global.runtime.httpRoute.parentRefs is required when httpRoute is enabled" }}
23+
{{- end }}
24+
hostnames:
25+
{{- if .Values.global.runtime.httpRoute.hostnames }}
26+
{{- toYaml .Values.global.runtime.httpRoute.hostnames | nindent 4 }}
27+
{{- else }}
28+
{{- fail "ERROR: global.runtime.httpRoute.hostnames is required when httpRoute is enabled" }}
29+
{{- end }}
30+
rules:
31+
- matches:
32+
- path:
33+
type: PathPrefix
34+
value: /webhooks
35+
- path:
36+
type: PathPrefix
37+
value : /app-proxy
38+
{{- if (index (get $.Values "argo-workflows") "enabled") }}
39+
- path:
40+
type: PathPrefix
41+
value : /workflows
42+
{{- end }}
43+
backendRefs:
44+
- name: {{ $svcName }}
45+
port: {{ $svcPort }}
46+
{{- end }}

charts/gitops-runtime/templates/tunnel-client.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ to intruduce the subdomainPrefix to the tunnel.
44
Since the prefix is comprised of <accoundId>-<runtime name>, we can tempalate it and thus
55
reduce complexity of installation and number or mandatory values to provide for the installation to work.
66
*/}}
7-
{{- if and ( not .Values.global.runtime.ingress.enabled) (index .Values "tunnel-client" "enabled") }}
7+
{{- if and ( not .Values.global.runtime.ingress.enabled) ( not .Values.global.runtime.httpRoute.enabled) (index .Values "tunnel-client" "enabled") }}
88
{{ $tunnelClientContext := (index .Subcharts "tunnel-client")}}
99
{{ $accoundId := required "codefresh.accountId is required" .Values.global.codefresh.accountId }}
1010
{{ $runtimeName := required "runtime.name is required" .Values.global.runtime.name }}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
2+
suite: httproute test
3+
templates:
4+
- templates/httproute.yaml
5+
- templates/tunnel-client.yaml
6+
- templates/codefresh-cm.yaml
7+
tests:
8+
- it: no httproute is rendered when tunnel runtime is configured
9+
template: templates/httproute.yaml
10+
values:
11+
- ./values/mandatory-values.yaml
12+
asserts:
13+
- hasDocuments:
14+
count: 0
15+
16+
- it: no tunnel when httproute is configured
17+
template: templates/tunnel-client.yaml
18+
values:
19+
- ./values/mandatory-values-httproute.yaml
20+
asserts:
21+
- hasDocuments:
22+
count: 0
23+
24+
- it: httproute is rendered correctly when enabled
25+
template: templates/httproute.yaml
26+
values:
27+
- ./values/mandatory-values-httproute.yaml
28+
asserts:
29+
- hasDocuments:
30+
count: 1
31+
- equal:
32+
path: spec.parentRefs
33+
value:
34+
- name: traefik-gateway
35+
namespace: traefik
36+
- equal:
37+
path: spec.hostnames
38+
value:
39+
- runtime.example.com
40+
- equal:
41+
path: spec.rules
42+
value:
43+
- matches:
44+
- path:
45+
type: PathPrefix
46+
value: /webhooks
47+
- path:
48+
type: PathPrefix
49+
value : /app-proxy
50+
- path:
51+
type: PathPrefix
52+
value : /workflows
53+
backendRefs:
54+
- name: internal-router
55+
port: 80
56+
57+
- it: httroute has custom labels and annotations
58+
template: templates/httproute.yaml
59+
values:
60+
- ./values/mandatory-values-httproute.yaml
61+
set:
62+
global:
63+
runtime:
64+
httpRoute:
65+
labels:
66+
customLabel: customValue
67+
annotations:
68+
customAnnotation: customAnnotationValue
69+
asserts:
70+
- equal:
71+
path: metadata.labels.customLabel
72+
value: customValue
73+
- equal:
74+
path: metadata.annotations.customAnnotation
75+
value: customAnnotationValue
76+
77+
- it: codefresh-cm ingressHost is set correctly when httproute is enabled
78+
template: templates/codefresh-cm.yaml
79+
values:
80+
- ./values/mandatory-values-httproute.yaml
81+
asserts:
82+
- equal:
83+
path: data.ingressHost
84+
value: https://runtime.example.com
85+
86+
- it: error is thrown when httpRoute is enabled but parentRefs is missing
87+
template: templates/httproute.yaml
88+
values:
89+
- ./values/mandatory-values-httproute.yaml
90+
set:
91+
global.runtime.httpRoute.parentRefs: null
92+
asserts:
93+
- failedTemplate:
94+
errorMessage: "ERROR: global.runtime.httpRoute.parentRefs is required when httpRoute is enabled"
95+
96+
- it: error is thrown when httpRoute is enabled but hostnames is missing
97+
template: templates/httproute.yaml
98+
values:
99+
- ./values/mandatory-values-httproute.yaml
100+
set:
101+
global.runtime.httpRoute.hostnames: null
102+
asserts:
103+
- failedTemplate:
104+
errorMessage: "ERROR: global.runtime.httpRoute.hostnames is required when httpRoute is enabled"

charts/gitops-runtime/tests/ingress_test.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,17 @@ tests:
4242
- failedTemplate:
4343
errorMessage: codefresh.accountId is required
4444

45-
46-
4745
- it: when both tunnel-client and ingress are disabled fail rendering if ingressUrl is not provided
4846
template: templates/codefresh-cm.yaml
4947
values:
5048
- ./values/mandatory-values.yaml
5149
set:
5250
global.runtime.ingress.enabled: false
51+
global.runtime.httpRoute.enabled: false
5352
tunnel-client.enabled: false
5453
asserts:
5554
- failedTemplate:
56-
errorMessage: "ERROR: When global.runtime.ingress.enabled is false and tunnel-client.enabled is false - global.runtime.ingressUrl must be provided"
55+
errorMessage: "ERROR: When global.runtime.ingress.enabled and global.runtime.httpRoute.enabled are false and tunnel-client.enabled is false - global.runtime.ingressUrl must be provided"
5756

5857
- it: fail on ingressUrl that is not http or https
5958
template: templates/codefresh-cm.yaml
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
global:
2+
codefresh:
3+
accountId: 628a80b693a15c0f9c13ab75
4+
userToken:
5+
token: 'dummy'
6+
7+
runtime:
8+
name: test-runtime1
9+
10+
httpRoute:
11+
enabled: true
12+
parentRefs:
13+
- name: traefik-gateway
14+
namespace: traefik
15+
hostnames:
16+
- runtime.example.com

charts/gitops-runtime/tests/values/mandatory-values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ global:
88
name: test-runtime1
99
ingress:
1010
enabled: false
11+
httpRoute:
12+
enabled: false

charts/gitops-runtime/values.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,29 @@ global:
6565
labels: {}
6666
# -- Hosts for runtime ingress. Note that Codefresh platform will always use the first host in the list to access the runtime.
6767
hosts: []
68+
# -- HTTPRoute settings
69+
httpRoute:
70+
# -- Enable HTTPRoute
71+
enabled: false
72+
# -- The protocol that Codefresh platform will use to access the runtime. Can be http or https.
73+
protocol: https
74+
# -- Required! List of parent Gateway references this HTTPRoute should attach to
75+
# ref: https://gateway-api.sigs.k8s.io/reference/api-spec/main/spec/#parentreference
76+
# E.g.
77+
# parentRefs:
78+
# - name: traefik-gateway
79+
# namespace: traefik
80+
parentRefs: []
81+
# -- List of hostnames to be covered by this HTTPRoute
82+
# ref: https://gateway-api.sigs.k8s.io/reference/api-spec/main/spec/#hostname
83+
# E.g.
84+
# hostnames:
85+
# - runtime.example.com
86+
hostnames: []
87+
# -- Set annotations on the HTTPRoute resource
88+
annotations: {}
89+
# -- Set labels on the HTTPRoute resource
90+
labels: {}
6891
# -- Explicit url for runtime ingress. Provide this value only if you don't want the chart to create and ingress (global.runtime.ingress.enabled=false) and tunnel-client is not used (tunnel-client.enabled=false)
6992
ingressUrl: ""
7093
# -- is the runtime set as a "configuration runtime".

0 commit comments

Comments
 (0)