Guide to add Argo CD custom Lua health checks for ConfigMap driven demos to mark application health based on ConfigMap values and resolve degraded states
This guide shows how to add a custom health check in Argo CD that validates a ConfigMap and influences the health status of an Argo CD Application. Argo CD includes many built-in health assessments for standard Kubernetes resources, but you can extend these checks by adding small Lua scripts to the Argo CD config (argocd-cm ConfigMap).
Custom health checks are Lua snippets stored in the argocd-cm ConfigMap under keys following a naming convention. Argo CD executes these scripts for matching resources and expects a table with at least a status field (e.g., “Healthy”, “Degraded”, “Progressing”) and an optional message.Key naming examples:
This demo repository contains an application named health-check that demonstrates a ConfigMap-driven scenario:
ConfigMap: moving-shapes-colors — defines color values for shapes.
Deployment: random-shapes — loads the ConfigMap via envFrom.
Service: exposes the application.
Example ConfigMap used by the application (note the TRIANGLE_COLOR intentionally set to “white”, which we use to trigger a Degraded health state):
Copy
apiVersion: v1kind: ConfigMapmetadata: name: moving-shapes-colorsdata: CIRCLE_COLOR: "pink" OVAL_COLOR: "lightgreen" SQUARE_COLOR: "orange" TRIANGLE_COLOR: "white" # using white will produce a Degraded message in Argo CD RECTANGLE_COLOR: "blue"
Deployment that consumes the ConfigMap via envFrom:
Create an Argo CD Application that points to the health-check path in the git repo, targets the namespace health-check, and asks Argo CD to create the namespace. If you are not logged in to the argocd server the create command can fail — log in first if necessary.Attempt to create the app (may fail if not logged in):
Sync the application. Argo CD will create the namespace, then the ConfigMap, the Service, and finally the Deployment. The pod will initially show states like ContainerCreating / Progressing in the UI:
You can also verify namespace and pod status with kubectl:
Copy
kubectl get namespaces# Example output:# NAME STATUS AGE# default Active 16h# argocd Active 4h47m# health-check Active 27skubectl -n health-check get pods# Example output:# NAME READY STATUS RESTARTS AGE# random-shapes-5d55cc76-lc95h 1/1 Running 0 34s
In this demo the triangle becomes invisible when TRIANGLE_COLOR is white. We’ll use that condition to mark the application as Degraded by adding a custom health check. Edit the argocd-cm ConfigMap in the argocd namespace and add a Lua snippet under the key resource.customizations.health.ConfigMap. The script below sets Degraded when TRIANGLE_COLOR equals white and returns a helpful message.
Copy
apiVersion: v1kind: ConfigMapmetadata: name: argocd-cm namespace: argocddata: resource.customizations.health.ConfigMap: | hs = {} hs.status = "Healthy" hs.message = "" -- If the triangle color is white, mark as Degraded if obj.data ~= nil and obj.data.TRIANGLE_COLOR == "white" then hs.status = "Degraded" hs.message = "Use any color other than white for TRIANGLE_COLOR" end return hs
Custom health checks are Lua scripts executed by Argo CD. Be careful with Lua equality operators: == tests equality, ~= tests inequality.
Apply the change by editing the ConfigMap:
Copy
kubectl -n argocd edit configmap argocd-cm# paste the resource.customizations.health.ConfigMap entry and save
After saving the ConfigMap, refresh the Application in the Argo CD UI. Because the deployed ConfigMap moving-shapes-colors has TRIANGLE_COLOR set to white, Argo CD will evaluate the health hook and mark the ConfigMap (and the Application) as Degraded with the message you supplied (“Use any color other than white for TRIANGLE_COLOR”).
To resolve the degraded state, change the TRIANGLE_COLOR value either in the Git repo and sync, or edit the deployed ConfigMap directly and then restart pods if necessary so they pick up the change.Example: edit the deployed ConfigMap in the health-check namespace:
Copy
kubectl -n health-check edit configmap moving-shapes-colors# change TRIANGLE_COLOR: white -> TRIANGLE_COLOR: red
Once the ConfigMap no longer matches the Degraded condition, Argo CD’s custom health check will evaluate to Healthy and the application health will return to Healthy.The Argo CD UI resource tree will then display the ConfigMap, Service, Deployment/pods, and overall application health: