Skip to content

Commit 55de613

Browse files
committed
Allow for extra HealthChecks for argo
Tested with: ``` acm: extraResourceHealthChecks: - group: app kind: Deployment check: | hs = {} if obj.status ~= nil then if obj.status.readyReplicas == obj.status.replicas then hs.status = "Healthy" else hs.status = "Progressing" end end return hs ``` And correctly got the following on the spoke: ``` oc get argocd -n vp-gitops vp-gitops -o jsonpath='{.spec.resourceHealthChecks}' | jq -r '.[].kind' Subscription Deployment ```
1 parent 8f8e736 commit 55de613

3 files changed

Lines changed: 124 additions & 0 deletions

File tree

templates/policies/ocp-gitops-policy.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ spec:
271271
kind: Subscription
272272
check: |
273273
{{- include "acm.subscription.healthcheck.lua" . | nindent 24 }}
274+
{{- range $.Values.acm.extraResourceHealthChecks }}
275+
- group: {{ .group }}
276+
kind: {{ .kind }}
277+
check: |
278+
{{ .check | nindent 24 }}
279+
{{- end }}
274280
server:
275281
autoscale:
276282
enabled: false

tests/ocp_gitops_policy_test.yaml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,110 @@ tests:
9595
equal:
9696
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.channel
9797
value: gitops-priority
98+
99+
- it: Should have only the default Subscription healthcheck when no extra healthchecks are configured
100+
values:
101+
- ./clusterselector_values.yaml
102+
asserts:
103+
- documentSelector:
104+
path: metadata.name
105+
value: group-one-gitops-policy-argocd
106+
lengthEqual:
107+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.resourceHealthChecks
108+
count: 1
109+
- documentSelector:
110+
path: metadata.name
111+
value: group-one-gitops-policy-argocd
112+
equal:
113+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.resourceHealthChecks[0].group
114+
value: operators.coreos.com
115+
- documentSelector:
116+
path: metadata.name
117+
value: group-one-gitops-policy-argocd
118+
equal:
119+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.resourceHealthChecks[0].kind
120+
value: Subscription
121+
122+
- it: Should append a single extra resource healthcheck
123+
values:
124+
- ./clusterselector_values.yaml
125+
set:
126+
acm:
127+
extraResourceHealthChecks:
128+
- group: argoproj.io
129+
kind: Application
130+
check: |
131+
hs = {}
132+
hs.status = "Healthy"
133+
return hs
134+
asserts:
135+
- documentSelector:
136+
path: metadata.name
137+
value: group-one-gitops-policy-argocd
138+
lengthEqual:
139+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.resourceHealthChecks
140+
count: 2
141+
- documentSelector:
142+
path: metadata.name
143+
value: group-one-gitops-policy-argocd
144+
equal:
145+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.resourceHealthChecks[0].group
146+
value: operators.coreos.com
147+
- documentSelector:
148+
path: metadata.name
149+
value: group-one-gitops-policy-argocd
150+
equal:
151+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.resourceHealthChecks[1].group
152+
value: argoproj.io
153+
- documentSelector:
154+
path: metadata.name
155+
value: group-one-gitops-policy-argocd
156+
equal:
157+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.resourceHealthChecks[1].kind
158+
value: Application
159+
160+
- it: Should append multiple extra resource healthchecks
161+
values:
162+
- ./clusterselector_values.yaml
163+
set:
164+
acm:
165+
extraResourceHealthChecks:
166+
- group: argoproj.io
167+
kind: Application
168+
check: |
169+
hs = {}
170+
hs.status = "Healthy"
171+
return hs
172+
- group: batch
173+
kind: Job
174+
check: |
175+
hs = {}
176+
if obj.status.succeeded == 1 then
177+
hs.status = "Healthy"
178+
end
179+
return hs
180+
asserts:
181+
- documentSelector:
182+
path: metadata.name
183+
value: group-one-gitops-policy-argocd
184+
lengthEqual:
185+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.resourceHealthChecks
186+
count: 3
187+
- documentSelector:
188+
path: metadata.name
189+
value: group-one-gitops-policy-argocd
190+
equal:
191+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.resourceHealthChecks[1].group
192+
value: argoproj.io
193+
- documentSelector:
194+
path: metadata.name
195+
value: group-one-gitops-policy-argocd
196+
equal:
197+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.resourceHealthChecks[2].group
198+
value: batch
199+
- documentSelector:
200+
path: metadata.name
201+
value: group-one-gitops-policy-argocd
202+
equal:
203+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.resourceHealthChecks[2].kind
204+
value: Job

values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ acm:
6868
# -- MultiClusterHub spec (empty by default)
6969
mch_spec: {}
7070

71+
# -- Extra resource health checks to add to the spoke ArgoCD instance.
72+
# Each entry needs group, kind, and check (Lua script) fields.
73+
# @default -- empty list
74+
extraResourceHealthChecks: []
75+
# - group: argoproj.io
76+
# kind: Application
77+
# check: |
78+
# local health_status = {}
79+
# health_status.status = "Healthy"
80+
# return health_status
81+
7182
# -- Just used for IIB testing, drives the source and channel for the MCE subscription triggered by ACM
7283
# @default -- Uses the official redhat sources
7384
mce_operator:

0 commit comments

Comments
 (0)