Skip to content

Add CD Driver Health Status #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions charts/core/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: A Helm chart for deploying Unikorn Core

type: application

version: v1.1.0-rc5
appVersion: v1.1.0-rc5
version: v1.1.0-rc6
appVersion: v1.1.0-rc6

icon: https://assets.unikorn-cloud.org/images/logos/dark-on-light/icon.svg

Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/unikorn/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ const (

// ConditionReason defines the possible reasons of a resource
// condition. These are generic and may be used by any condition.
// +kubebuilder:validation:Enum=Provisioning;Provisioned;Cancelled;Errored;Deprovisioning;Deprovisioned;Healthy;Degraded
// +kubebuilder:validation:Enum=Provisioning;Provisioned;Cancelled;Errored;Deprovisioning;Deprovisioned;Unknown;Healthy;Degraded
type ConditionReason string

// Condition reasons for ConditionAvailable.
Expand Down Expand Up @@ -313,6 +313,8 @@ const (

// Condition reasons for ConditionHealthy.
const (
// ConditionReasonUnknown means the health status cannot be derived.
ConditionReasonUnknown ConditionReason = "Unknown"
// ConditionReasonHealthy means all subresources associated with the
// resource are in a healthy state.
ConditionReasonHealthy ConditionReason = "Healthy"
Expand Down
29 changes: 29 additions & 0 deletions pkg/cd/argocd/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,35 @@ func convertApplicationList(in *argoprojv1.ApplicationList) map[*cd.ResourceIden
return out
}

// GetHealthStatus returns an overall health status of all applications
// referenced by the resource identifier.
func (d *Driver) GetHealthStatus(ctx context.Context, id *cd.ResourceIdentifier) (cd.HealthStatus, error) {
options := &client.ListOptions{
Namespace: namespace,
LabelSelector: labels.SelectorFromSet(applicationLabelsForOwningResource(id)),
}

var resources argoprojv1.ApplicationList

if err := d.client.List(ctx, &resources, options); err != nil {
return cd.HealthStatusUnknown, err
}

for i := range resources.Items {
application := &resources.Items[i]

if application.Status.Health == nil {
return cd.HealthStatusUnknown, nil
}

if application.Status.Health.Status != argoprojv1.Healthy {
return cd.HealthStatusDegraded, nil
}
}

return cd.HealthStatusHealthy, nil
}

// ListHelmApplications gets all applications that match the resource identifier.
func (d *Driver) ListHelmApplications(ctx context.Context, id *cd.ResourceIdentifier) (map[*cd.ResourceIdentifier]*cd.HelmApplication, error) {
options := &client.ListOptions{
Expand Down
4 changes: 4 additions & 0 deletions pkg/cd/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type Driver interface {
// your hack.
Kind() DriverKind

// GetHealthStatus returns an overall health status of all applications
// referenced by the resource identifier.
GetHealthStatus(ctx context.Context, id *ResourceIdentifier) (HealthStatus, error)

// ListHelmApplications gets all applications that match the resource identifier.
ListHelmApplications(ctx context.Context, id *ResourceIdentifier) (map[*ResourceIdentifier]*HelmApplication, error)

Expand Down
15 changes: 15 additions & 0 deletions pkg/cd/mock/interfaces.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pkg/cd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,16 @@ type Cluster struct {
// import that cluster as a region.
Prefix string
}

// HealthStatus is used to describe the health of the application.
type HealthStatus string

const (
// HealthStatusUnknown means the application health cannot be derived.
HealthStatusUnknown HealthStatus = "unknown"
// HealthStatusHealthy means everything is as expected.
HealthStatusHealthy HealthStatus = "healthy"
// HealthStatusDegraded means the application may still function
// but is in a degraded state.
HealthStatusDegraded HealthStatus = "degraded"
)