From a76d5809b8223278261da33504e15a323fb89015 Mon Sep 17 00:00:00 2001 From: derailed Date: Fri, 14 Feb 2020 16:31:52 -0700 Subject: [PATCH] checkpoint --- internal/dao/healthz.go | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 internal/dao/healthz.go diff --git a/internal/dao/healthz.go b/internal/dao/healthz.go new file mode 100644 index 00000000..75e18971 --- /dev/null +++ b/internal/dao/healthz.go @@ -0,0 +1,45 @@ +package dao + +import ( + "context" + + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime" +) + +type Healthz struct { + Resource string + Count int64 + Errors int64 +} + +type Pulse interface{} +type Pulses []Pulse + + +func ClusterHealth(ctx context.Context, gvr string) (Pulses, error) { + var h Healthz + + oo, err := p.List(ctx, "") + if err != nil { + return nil, err + } + + h.Count = len(oo) + for _, o := range oo { + var pod v1.Pod + err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &pod) + if err != nil { + return nil, err + } + + if !happy(pod) { + h.Errors++ + } + } +} + +func happy(p v1.Pod) bool { + +}