MCPcopy Create free account
hub / github.com/PostHog/duckgres / summary

Method summary

controlplane/admin/cluster.go:349–408  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

347}
348
349func (h *clusterHandler) summary(c *gin.Context) {
350 ctx := c.Request.Context()
351 var sum clusterSummary
352
353 nodeList, err := h.client.CoreV1().Nodes().List(ctx, metav1.ListOptions{Limit: clusterNodeLimit})
354 if err != nil {
355 if apierrors.IsForbidden(err) {
356 slog.Warn("admin: cluster summary node read forbidden — grant the duckgres-control-plane-cluster-topology ClusterRole", "error", err)
357 c.JSON(http.StatusOK, sum)
358 return
359 }
360 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
361 return
362 }
363 for i := range nodeList.Items {
364 if strings.HasPrefix(nodeList.Items[i].Labels["karpenter.sh/nodepool"], duckgresNodePool) {
365 sum.Nodes++
366 }
367 }
368
369 podList, err := h.client.CoreV1().Pods(metav1.NamespaceAll).List(ctx, metav1.ListOptions{Limit: clusterPodLimit})
370 if err != nil {
371 if apierrors.IsForbidden(err) {
372 c.JSON(http.StatusOK, sum)
373 return
374 }
375 c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
376 return
377 }
378 var workerMilli, workerMem, phMilli, phMem int64
379 for i := range podList.Items {
380 p := &podList.Items[i]
381 phase := p.Status.Phase
382 worker := p.Labels[workerPodLabel] == workerPodLabelValue
383 placeholder := isPlaceholderPod(p)
384 // Count as a worker/placeholder only when actually Running (and not
385 // terminating) — a Pending worker isn't on a node yet, so it belongs in
386 // the separate "pending" tally, not the running-worker count/CPU totals.
387 running := phase == corev1.PodRunning && p.DeletionTimestamp == nil
388 if running && worker {
389 sum.Workers++
390 mc, mb := podRequests(p)
391 workerMilli += mc
392 workerMem += mb
393 } else if running && placeholder {
394 sum.Placeholders++
395 mc, mb := podRequests(p)
396 phMilli += mc
397 phMem += mb
398 }
399 if phase == corev1.PodPending && (worker || placeholder) {
400 sum.Pending++
401 }
402 }
403 sum.WorkerCPUCores = roundCores(workerMilli)
404 sum.WorkerMemGiB = roundGiB(workerMem)
405 sum.PlaceholderCPUCores = roundCores(phMilli)
406 sum.PlaceholderMemGiB = roundGiB(phMem)

Callers

nothing calls this directly

Calls 7

isPlaceholderPodFunction · 0.85
podRequestsFunction · 0.85
roundCoresFunction · 0.85
roundGiBFunction · 0.85
ListMethod · 0.80
ContextMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected