Skip to content

Commit dcb9a3e

Browse files
committed
Introduce an argo-healthcheck make target
This is a simple quick check to see if all argo applications in all namespaces are synced and error out if they are not. Synced example: $ make argo-healthcheck make -f common/Makefile argo-healthcheck make[1]: Entering directory '/home/michele/Engineering/cloud-patterns/multicloud-gitops' Checking argo applications mcg-private-hub acm -> Sync: Synced - Health: Healthy mcg-private-hub config-demo -> Sync: Synced - Health: Healthy mcg-private-hub golang-external-secrets -> Sync: Synced - Health: Healthy mcg-private-hub hello-world -> Sync: Synced - Health: Healthy mcg-private-hub vault -> Sync: Synced - Health: Healthy openshift-gitops mcg-private-hub -> Sync: Synced - Health: Healthy make[1]: Leaving directory '/home/michele/Engineering/cloud-patterns/multicloud-gitops' Not synced example: $ make argo-healthcheck make -f common/Makefile argo-healthcheck make[1]: Entering directory '/home/michele/Engineering/cloud-patterns/multicloud-gitops' Checking argo applications mcg-private-hub acm -> Sync: Synced - Health: Healthy mcg-private-hub config-demo -> Sync: Synced - Health: Degraded mcg-private-hub golang-external-secrets -> Sync: Synced - Health: Healthy mcg-private-hub hello-world -> Sync: Synced - Health: Healthy mcg-private-hub vault -> Sync: Synced - Health: Progressing openshift-gitops mcg-private-hub -> Sync: Synced - Health: Healthy Some applications are not synced or are unhealthy make[1]: *** [common/Makefile:115: argo-healthcheck] Error 1 make[1]: Leaving directory '/home/michele/Engineering/cloud-patterns/multicloud-gitops' make: *** [Makefile:12: argo-healthcheck] Error 2
1 parent 41de1a3 commit dcb9a3e

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,30 @@ validate-prereq: ## verify pre-requisites
108108
@if ! ansible-galaxy collection list | grep kubernetes.core > /dev/null 2>&1; then echo "Not found"; exit 1; fi
109109
@echo "OK"
110110

111+
.PHONY: argo-healthcheck
112+
argo-healthcheck: ## Checks if all argo applications are synced
113+
@echo "Checking argo applications"
114+
$(eval APPS := $(shell oc get applications -A -o jsonpath='{range .items[*]}{@.metadata.namespace}{","}{@.metadata.name}{"\n"}{end}'))
115+
@NOTOK=0; \
116+
for i in $(APPS); do\
117+
n=`echo "$${i}" | cut -f1 -d,`;\
118+
a=`echo "$${i}" | cut -f2 -d,`;\
119+
STATUS=`oc get -n "$${n}" application/"$${a}" -o jsonpath='{.status.sync.status}'`;\
120+
if [[ $$STATUS != "Synced" ]]; then\
121+
NOTOK=$$(( $${NOTOK} + 1));\
122+
fi;\
123+
HEALTH=`oc get -n "$${n}" application/"$${a}" -o jsonpath='{.status.health.status}'`;\
124+
if [[ $$HEALTH != "Healthy" ]]; then\
125+
NOTOK=$$(( $${NOTOK} + 1));\
126+
fi;\
127+
echo "$${n} $${a} -> Sync: $${STATUS} - Health: $${HEALTH}";\
128+
done;\
129+
if [ $${NOTOK} -gt 0 ]; then\
130+
echo "Some applications are not synced or are unhealthy";\
131+
exit 1;\
132+
fi
133+
134+
111135
##@ Test and Linters Tasks
112136

113137
CHARTS=$(shell find . -type f -iname 'Chart.yaml' -exec dirname "{}" \; | grep -v examples | sed -e 's/.\///')

0 commit comments

Comments
 (0)