Skip to content

Commit

Permalink
improve crd status (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz authored Jan 10, 2024
1 parent 8699bc7 commit 81e2e49
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions pkg/sync/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubectl/pkg/util/podutils"
Expand Down Expand Up @@ -724,3 +726,33 @@ func getAppsv1DaemonSetHealth(daemon *appsv1.DaemonSet) (*HealthStatus, error) {
Status: HealthStatusHealthy,
}, nil
}

type Status struct {
Conditions []metav1.Condition
}

const readyCondition = "Ready"

func getOtherHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
sts := Status{}
status, ok := obj.Object["status"]
if ok {
s, ok := status.(map[string]interface{})
if ok {
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(s, &sts); err != nil {
return nil, nil
}
if meta.FindStatusCondition(sts.Conditions, readyCondition) != nil {
status := HealthStatusProgressing
if meta.IsStatusConditionTrue(sts.Conditions, readyCondition) {
status = HealthStatusHealthy
}
return &HealthStatus{
Status: status,
}, nil
}
}
}

return nil, nil
}
2 changes: 1 addition & 1 deletion pkg/sync/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func GetHealthCheckFunc(gvk schema.GroupVersionKind) func(obj *unstructured.Unst
return getHPAHealth
}
}
return nil
return getOtherHealth
}

func FormatSummary(namespace, name string, s stats.Stats) error {
Expand Down

0 comments on commit 81e2e49

Please sign in to comment.