diff --git a/docs/maps.md b/docs/maps.md index 1cb1279..d6eea58 100644 --- a/docs/maps.md +++ b/docs/maps.md @@ -362,7 +362,13 @@ One PR each, in order: and ingresses aren't judged; what they send to is. A part links to its workload rather than to a host. On the overview each cluster is one box, opening into its services; they aren't listed as found, - since the API says they're there. On kind (2026-11-13), with the + since the API says they're there. The box says what the cluster is + (Kubernetes, OpenShift or Proxmox cluster, vCenter, HMC) and is never + in better shape than the cluster itself, as the Clusters page and the + network map show it: a cluster with a failed job and every service + fine is yellow, with the reason ("· 1 problem"). VMs someone stopped + don't turn a running cluster's box grey; it says how many aren't + running. On kind (2026-11-13), with the ClusterRole before this step, the agent logged a 403 for each new kind and carried on; with it, Routes were a quiet 404. Ten Services and two Ingresses came through right: ready counts, a crash-looping diff --git a/internal/server/maps_test.go b/internal/server/maps_test.go index e2de63e..fd5fd90 100644 --- a/internal/server/maps_test.go +++ b/internal/server/maps_test.go @@ -354,7 +354,9 @@ func TestClusterOnTheServiceMap(t *testing.T) { report.Workload{Kind: report.KindService, ID: "s1", Name: "web", Namespace: "shop", State: report.StateOK, Word: "2 ready endpoints", Facts: map[string]any{"type": "ClusterIP", "cluster_ips": "10.96.0.10", "ports": "80", "backends": "deployment/web"}}, report.Workload{Kind: report.KindIngress, ID: "i1", Name: "ingress/shop", Namespace: "shop", State: report.StateOK, Word: "shop.example.org → web", - Facts: map[string]any{"hosts": "shop.example.org", "backends": "web:80", "tls": true}}) + Facts: map[string]any{"hosts": "shop.example.org", "backends": "web:80", "tls": true}}, + // A failed job: the cluster has a problem, its services none. + report.Workload{Kind: report.KindJob, ID: "j9", Name: "job/nightly-report", Namespace: "batch", State: report.StateDown, Word: "Failed: BackoffLimitExceeded"}) sendBatch(t, a, clusterTok, report.Workloads{Full: "begin", Records: recs}) sendBatch(t, a, clusterTok, report.Workloads{Full: "end"}) a.store.Put("node1", report.Report{V: report.Version, Map: &report.Map{ @@ -372,13 +374,23 @@ func TestClusterOnTheServiceMap(t *testing.T) { t.Errorf("overview boxes: %s", ids) } for _, b := range v.Boxes { - if b.ID == "group:cluster:prod" && (b.Sub != "Kubernetes cluster" || b.Count != 3) { + if b.ID == "group:cluster:prod" && (!strings.HasPrefix(b.Sub, "Kubernetes cluster") || b.Count != 3) { t.Errorf("cluster box: %+v", b) } } if l := lineKeys(v); !strings.Contains(l, ">group:cluster:prod needs") { t.Errorf("overview lines: %s", l) } + // The box is never better than the cluster itself, as the Clusters page + // and the network map show it (#38). + _, conds := a.view(now) + for _, c := range a.clusterViews(now, conds) { + for _, b := range v.Boxes { + if b.ID == "group:cluster:"+c.Name && statusOrder[b.Status] < statusOrder[c.Status] { + t.Errorf("service map says %s, the cluster %s (%s)", b.Status, c.Status, c.Word) + } + } + } v, ok = a.servicesView("group:cluster:prod", 1, now) if !ok { @@ -437,3 +449,29 @@ func TestClusterOnTheServiceMap(t *testing.T) { t.Errorf("corrections: %s", rec.Body) } } + +// A cluster's box on the service map: never better than the cluster (#38), +// and not grey for a few stopped VMs when the rest run. +func TestClusterBox(t *testing.T) { + status := map[string]string{"a": "good", "b": "good", "c": "waiting"} + b := MapBox{Status: "good"} + clusterBox(&b, "", ClusterView{Status: "warning", Word: "1 problem"}, true, []string{"a", "b"}, status) + if b.Status != "warning" || b.Sub != "Kubernetes cluster · 1 problem" { + t.Errorf("cluster with a problem, services fine: %+v", b) + } + b = MapBox{Status: "waiting"} + clusterBox(&b, "Proxmox cluster", ClusterView{Status: "good", Word: "Current"}, true, []string{"a", "b", "c"}, status) + if b.Status != "good" || b.Sub != "Proxmox cluster · 1 not running" { + t.Errorf("one VM stopped: %+v", b) + } + b = MapBox{Status: "waiting"} + clusterBox(&b, "vCenter", ClusterView{}, false, []string{"c"}, status) + if b.Status != "waiting" || b.Sub != "vCenter" { + t.Errorf("nothing running: %+v", b) + } + b = MapBox{Status: "critical"} + clusterBox(&b, "", ClusterView{Status: "warning", Word: "1 problem"}, true, []string{"a"}, status) + if b.Status != "critical" || b.Sub != "Kubernetes cluster" { + t.Errorf("services worse than the cluster: %+v", b) + } +} diff --git a/internal/server/mapviews.go b/internal/server/mapviews.go index a52c155..137721e 100644 --- a/internal/server/mapviews.go +++ b/internal/server/mapviews.go @@ -692,6 +692,14 @@ func (srv *Server) servicesView(focus string, steps int, now time.Time) (*MapVie for _, s := range srv.workloadSnapshot() { kinds[s.name] = s.kindLabel() } + // A cluster's box takes the cluster's own state too, the one the + // Clusters page and the network map show (#38), not only its + // services'. + clusters := map[string]ClusterView{} + _, conds := srv.view(now) + for _, c := range srv.clusterViews(now, conds) { + clusters[c.Name] = c + } for _, gid := range order { b := fold(gid, "group", names[gid], members[gid], status) for i, m := range b.Problems { @@ -699,7 +707,8 @@ func (srv *Server) servicesView(focus string, steps int, now time.Time) (*MapVie } b.Layer = layer[gid] if c, ok := strings.CutPrefix(gid, "group:cluster:"); ok { - b.Sub = cmp.Or(kinds[c], "Kubernetes cluster") + cv, known := clusters[c] + clusterBox(&b, kinds[c], cv, known, members[gid], status) } v.Boxes = append(v.Boxes, b) } @@ -874,6 +883,33 @@ func (srv *Server) handleMapFind(w http.ResponseWriter, r *http.Request) { // k8sCluster is the cluster a service on the map comes from, if it's from // one: its parts are all that cluster's (docs/maps.md, step 7). +// clusterBox says what a cluster's box on the service map is, and gives it +// the cluster's own state when that's worse than its services' (#38): the +// state the Clusters page and the network map show. VMs someone stopped are +// grey on their own but don't grey a cluster whose other services run. +func clusterBox(b *MapBox, kind string, cv ClusterView, known bool, members []string, status map[string]string) { + b.Sub = cmp.Or(kind, "Kubernetes cluster") + if b.Status == "waiting" { + idle, running := 0, 0 + for _, m := range members { + switch status[m] { + case "waiting", "": + idle++ + case "good": + running++ + } + } + if running > 0 { + b.Status = "good" + b.Sub += fmt.Sprintf(" · %d not running", idle) + } + } + if known && statusOrder[cv.Status] > statusOrder[b.Status] { + b.Status = cv.Status + b.Sub += " · " + cv.Word // why it isn't green when its services are + } +} + func k8sCluster(s mapgraph.Service) (string, bool) { if s.Source != "kubernetes" || len(s.Parts) == 0 { return "", false