Skip to content

Commit 2ab4281

Browse files
committed
add health check support for ArgoCD Application
Signed-off-by: jasonz <[email protected]>
1 parent 0371401 commit 2ab4281

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

pkg/health/health.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ func GetHealthCheckFunc(gvk schema.GroupVersionKind) func(obj *unstructured.Unst
120120
switch gvk.Kind {
121121
case "Workflow":
122122
return getArgoWorkflowHealth
123+
case "Application":
124+
return getArgoApplicationHealth
123125
}
124126
case "apiregistration.k8s.io":
125127
switch gvk.Kind {

pkg/health/health_argo.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ type argoWorkflow struct {
2626
}
2727
}
2828

29+
type argoApplication struct {
30+
Status struct {
31+
Health struct {
32+
Status HealthStatusCode
33+
Message string
34+
}
35+
}
36+
}
37+
2938
func getArgoWorkflowHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
3039
var wf argoWorkflow
3140
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &wf)
@@ -42,3 +51,12 @@ func getArgoWorkflowHealth(obj *unstructured.Unstructured) (*HealthStatus, error
4251
}
4352
return &HealthStatus{Status: HealthStatusUnknown, Message: wf.Status.Message}, nil
4453
}
54+
55+
func getArgoApplicationHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
56+
var app argoApplication
57+
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &app)
58+
if err != nil {
59+
return nil, err
60+
}
61+
return &HealthStatus{Status: app.Status.Health.Status, Message: app.Status.Health.Message}, nil
62+
}

pkg/health/health_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,8 @@ func TestGetArgoWorkflowHealth(t *testing.T) {
167167
assert.Equal(t, "", health.Message)
168168

169169
}
170+
171+
func TestGetArgoApplicationHealth(t *testing.T) {
172+
assertAppHealth(t, "./testdata/application-healthy.yaml", HealthStatusHealthy)
173+
assertAppHealth(t, "./testdata/application-degraded.yaml", HealthStatusDegraded)
174+
}

0 commit comments

Comments
 (0)