Skip to content

Commit d126002

Browse files
authored
Merge pull request #84 from mbaldessari/ishubcluster
Make clusterGroup.isHubCluster optional
2 parents 1274727 + 9590d38 commit d126002

7 files changed

Lines changed: 235 additions & 8 deletions

File tree

‎templates/_helpers.tpl‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,26 @@ annotations:
281281
{{- end }}
282282
{{- end }}
283283
{{- end }}
284+
285+
{{/*
286+
Determines if the current cluster is a hub cluster.
287+
First checks if clusterGroup.isHubCluster is explicitly set (and not null) and uses that value.
288+
If not set or null, falls back to comparing global.localClusterDomain and global.hubClusterDomain.
289+
If domains are equal or localClusterDomain is not set (defaults to hubClusterDomain), this is a hub cluster.
290+
Usage: {{ include "clustergroup.ishubcluster" . }}
291+
Returns: "true" or "false" as a string
292+
*/}}
293+
{{- define "clustergroup.ishubcluster" -}}
294+
{{- if and (hasKey .Values.clusterGroup "isHubCluster") (not (kindIs "invalid" .Values.clusterGroup.isHubCluster)) -}}
295+
{{- .Values.clusterGroup.isHubCluster | toString -}}
296+
{{- else if $.Values.global.hubClusterDomain -}}
297+
{{- $localDomain := coalesce $.Values.global.localClusterDomain $.Values.global.hubClusterDomain -}}
298+
{{- if eq $localDomain $.Values.global.hubClusterDomain -}}
299+
true
300+
{{- else -}}
301+
false
302+
{{- end -}}
303+
{{- else -}}
304+
false
305+
{{- end -}}
306+
{{- end }}

‎templates/imperative/unsealjob.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{{- end }}
1313
{{- end }}
1414

15-
{{- if or $.Values.clusterGroup.isHubCluster $hashicorp_vault_found }}
15+
{{- if or (eq (include "clustergroup.ishubcluster" .) "true") $hashicorp_vault_found }}
1616
---
1717
apiVersion: batch/v1
1818
kind: CronJob

‎tests/application_vault_unseal_test.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tests:
77
- it: should not output an unsealjob by default
88
asserts:
99
- hasDocuments:
10-
count: 1
10+
count: 0
1111

1212
- it: should render the unsealVault job when the application dict has hashicorp-vault but when isHubCluster is false
1313
set:
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
suite: Test Hub Cluster Detection Logic
2+
templates:
3+
- templates/imperative/unsealjob.yaml
4+
release:
5+
name: release-test
6+
tests:
7+
# Test 1: isHubCluster takes precedence over domain logic (explicit true)
8+
- it: should use isHubCluster true even when domains do not match
9+
set:
10+
global:
11+
repoURL: https://github.com/validatedpatterns/multicloud-gitops
12+
multiSourceRepoUrl: https://charts.validatedpatterns.io
13+
hubClusterDomain: "apps.hub.example.com"
14+
localClusterDomain: "apps.spoke.example.com"
15+
clusterGroup:
16+
isHubCluster: true # This takes precedence over domain logic
17+
applications:
18+
test:
19+
name: test
20+
namespace: test
21+
project: test
22+
chart: test-chart
23+
asserts:
24+
- isKind:
25+
of: CronJob
26+
- hasDocuments:
27+
count: 1
28+
29+
# Test 2: isHubCluster takes precedence over domain logic (explicit false)
30+
- it: should use isHubCluster false even when domains match
31+
set:
32+
global:
33+
repoURL: https://github.com/validatedpatterns/multicloud-gitops
34+
multiSourceRepoUrl: https://charts.validatedpatterns.io
35+
hubClusterDomain: "apps.hub.example.com"
36+
localClusterDomain: "apps.hub.example.com"
37+
secretStore:
38+
backend: "vault"
39+
clusterGroup:
40+
isHubCluster: false # This takes precedence over domain logic
41+
applications:
42+
test:
43+
name: test
44+
namespace: test
45+
project: test
46+
chart: test-chart
47+
asserts:
48+
- hasDocuments:
49+
count: 0
50+
51+
# Test 3: Domain logic fallback - hub cluster when domains match (isHubCluster not set)
52+
- it: should detect hub cluster via domain logic when isHubCluster is not set and domains match
53+
set:
54+
global:
55+
repoURL: https://github.com/validatedpatterns/multicloud-gitops
56+
multiSourceRepoUrl: https://charts.validatedpatterns.io
57+
hubClusterDomain: "apps.hub.example.com"
58+
localClusterDomain: "apps.hub.example.com"
59+
clusterGroup:
60+
isHubCluster: null # Explicitly null to trigger domain logic fallback
61+
applications:
62+
test:
63+
name: test
64+
namespace: test
65+
project: test
66+
chart: test-chart
67+
asserts:
68+
- isKind:
69+
of: CronJob
70+
- hasDocuments:
71+
count: 1
72+
73+
# Test 4: Domain logic fallback - managed cluster when domains differ (isHubCluster not set)
74+
- it: should detect managed cluster via domain logic when isHubCluster is not set and domains differ
75+
set:
76+
global:
77+
repoURL: https://github.com/validatedpatterns/multicloud-gitops
78+
multiSourceRepoUrl: https://charts.validatedpatterns.io
79+
hubClusterDomain: "apps.hub.example.com"
80+
localClusterDomain: "apps.spoke.example.com"
81+
secretStore:
82+
backend: "vault"
83+
clusterGroup:
84+
isHubCluster: null # Explicitly null to trigger domain logic fallback
85+
applications:
86+
test:
87+
name: test
88+
namespace: test
89+
project: test
90+
chart: test-chart
91+
asserts:
92+
- hasDocuments:
93+
count: 0
94+
95+
# Test 5: Domain logic fallback - hub cluster when localClusterDomain is unset
96+
- it: should detect hub cluster when isHubCluster not set and localClusterDomain defaults to hubClusterDomain
97+
set:
98+
global:
99+
repoURL: https://github.com/validatedpatterns/multicloud-gitops
100+
multiSourceRepoUrl: https://charts.validatedpatterns.io
101+
hubClusterDomain: "apps.hub.example.com"
102+
# localClusterDomain is intentionally not set - defaults to hubClusterDomain
103+
clusterGroup:
104+
isHubCluster: null # Explicitly null to trigger domain logic fallback
105+
applications:
106+
test:
107+
name: test
108+
namespace: test
109+
project: test
110+
chart: test-chart
111+
asserts:
112+
- isKind:
113+
of: CronJob
114+
- hasDocuments:
115+
count: 1
116+
117+
# Test 6: Fallback to false when no isHubCluster and no domain configuration
118+
- it: should default to false when no isHubCluster and no domain configuration
119+
set:
120+
global:
121+
repoURL: https://github.com/validatedpatterns/multicloud-gitops
122+
multiSourceRepoUrl: https://charts.validatedpatterns.io
123+
secretStore:
124+
backend: "vault"
125+
# No domain configuration provided
126+
clusterGroup:
127+
isHubCluster: null # Explicitly null to trigger fallback logic
128+
applications:
129+
test:
130+
name: test
131+
namespace: test
132+
project: test
133+
chart: test-chart
134+
asserts:
135+
- hasDocuments:
136+
count: 0
137+
138+
# Test 7: Should still create unsealjob when hashicorp-vault app exists regardless of hub status
139+
- it: should create unsealjob when hashicorp-vault app exists even on managed cluster
140+
set:
141+
global:
142+
repoURL: https://github.com/validatedpatterns/multicloud-gitops
143+
multiSourceRepoUrl: https://charts.validatedpatterns.io
144+
hubClusterDomain: "apps.hub.example.com"
145+
localClusterDomain: "apps.spoke.example.com"
146+
clusterGroup:
147+
isHubCluster: false # This confirms it's a managed cluster
148+
applications:
149+
vault:
150+
name: vault
151+
namespace: vault
152+
project: hub
153+
chart: hashicorp-vault
154+
chartVersion: 0.1.*
155+
asserts:
156+
- isKind:
157+
of: CronJob
158+
- hasDocuments:
159+
count: 1
160+
161+
# Test 8: isHubCluster true with no domain configuration
162+
- it: should use isHubCluster true when no domain configuration is provided
163+
set:
164+
global:
165+
repoURL: https://github.com/validatedpatterns/multicloud-gitops
166+
multiSourceRepoUrl: https://charts.validatedpatterns.io
167+
# No domain configuration provided
168+
clusterGroup:
169+
isHubCluster: true
170+
applications:
171+
test:
172+
name: test
173+
namespace: test
174+
project: test
175+
chart: test-chart
176+
asserts:
177+
- isKind:
178+
of: CronJob
179+
- hasDocuments:
180+
count: 1
181+
182+
# Test 9: isHubCluster false with no domain configuration
183+
- it: should use isHubCluster false when no domain configuration is provided
184+
set:
185+
global:
186+
repoURL: https://github.com/validatedpatterns/multicloud-gitops
187+
multiSourceRepoUrl: https://charts.validatedpatterns.io
188+
secretStore:
189+
backend: "vault"
190+
# No domain configuration provided
191+
clusterGroup:
192+
isHubCluster: false
193+
applications:
194+
test:
195+
name: test
196+
namespace: test
197+
project: test
198+
chart: test-chart
199+
asserts:
200+
- hasDocuments:
201+
count: 0

‎tests/unsealjob_null_handling_test.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tests:
77
- it: should not output an unsealjob by default
88
asserts:
99
- hasDocuments:
10-
count: 1
10+
count: 0
1111

1212
- it: should render the unsealVault job when hashicorp-vault exists and no null applications
1313
set:
@@ -124,4 +124,4 @@ tests:
124124
- isKind:
125125
of: CronJob
126126
- hasDocuments:
127-
count: 1
127+
count: 1

‎values.schema.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@
298298
"type": "string"
299299
},
300300
"isHubCluster": {
301-
"type": "boolean",
302-
"description": "If set to true the values is used to identify whether this is the hub cluster or an edge/spoke cluster configuration."
301+
"type": ["boolean", "null"],
302+
"deprecated": true,
303+
"description": "DEPRECATED: If set to true the values is used to identify whether this is the hub cluster or an edge/spoke cluster configuration. Use global.localClusterDomain and global.hubClusterDomain instead."
303304
},
304305
"sharedValueFiles": {
305306
"type": "array",
@@ -458,7 +459,6 @@
458459
},
459460
"required": [
460461
"applications",
461-
"isHubCluster",
462462
"name",
463463
"namespaces"
464464
],

‎values.yaml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ global:
1616
# Note that sometimes changing helm values might require a hard refresh (https://github.com/helm/helm/issues/3486)
1717
clusterGroup:
1818
name: example
19-
isHubCluster: true
19+
# DEPRECATED: isHubCluster is deprecated. Use global.localClusterDomain and global.hubClusterDomain instead.
20+
# When both domain values are set, hub cluster detection will be based on whether they are equal.
21+
# This field is kept for backwards compatibility when domain values are not set.
22+
# isHubCluster: true
2023
targetCluster: in-cluster
2124
sharedValueFiles: []
2225

0 commit comments

Comments
 (0)