Skip to content

Commit

Permalink
add health check support for ArgoCD Application
Browse files Browse the repository at this point in the history
Signed-off-by: jasonz <[email protected]>
  • Loading branch information
ksdpmx committed Nov 27, 2024
1 parent 0371401 commit 2ab4281
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ func GetHealthCheckFunc(gvk schema.GroupVersionKind) func(obj *unstructured.Unst
switch gvk.Kind {
case "Workflow":
return getArgoWorkflowHealth
case "Application":
return getArgoApplicationHealth
}
case "apiregistration.k8s.io":
switch gvk.Kind {
Expand Down
18 changes: 18 additions & 0 deletions pkg/health/health_argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ type argoWorkflow struct {
}
}

type argoApplication struct {
Status struct {
Health struct {
Status HealthStatusCode
Message string
}
}
}

func getArgoWorkflowHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
var wf argoWorkflow
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &wf)
Expand All @@ -42,3 +51,12 @@ func getArgoWorkflowHealth(obj *unstructured.Unstructured) (*HealthStatus, error
}
return &HealthStatus{Status: HealthStatusUnknown, Message: wf.Status.Message}, nil
}

func getArgoApplicationHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
var app argoApplication
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &app)
if err != nil {
return nil, err
}
return &HealthStatus{Status: app.Status.Health.Status, Message: app.Status.Health.Message}, nil
}
5 changes: 5 additions & 0 deletions pkg/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,8 @@ func TestGetArgoWorkflowHealth(t *testing.T) {
assert.Equal(t, "", health.Message)

}

func TestGetArgoApplicationHealth(t *testing.T) {
assertAppHealth(t, "./testdata/application-healthy.yaml", HealthStatusHealthy)
assertAppHealth(t, "./testdata/application-degraded.yaml", HealthStatusDegraded)
}

0 comments on commit 2ab4281

Please sign in to comment.