Skip to content

Commit 8a3f4f1

Browse files
committed
Include pod count in Node.Get output
1 parent e521287 commit 8a3f4f1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

internal/dao/node.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,21 @@ func (n *Node) Get(ctx context.Context, path string) (runtime.Object, error) {
152152
nmx, _ = client.DialMetrics(n.Client()).FetchNodeMetrics(ctx, path)
153153
}
154154

155-
return &render.NodeWithMetrics{Raw: raw, MX: nmx}, nil
155+
podCount := -1
156+
shouldCountPods, _ := ctx.Value(internal.KeyPodCounting).(bool)
157+
if shouldCountPods {
158+
pods, err := n.GetPods(raw.GetName())
159+
if err != nil {
160+
slog.Error("Unable to get pods count",
161+
slogs.ResName, raw.GetName(),
162+
slogs.Error, err,
163+
)
164+
} else {
165+
podCount = len(pods)
166+
}
167+
}
168+
169+
return &render.NodeWithMetrics{Raw: raw, MX: nmx, PodCount: podCount}, nil
156170
}
157171

158172
// List returns a collection of node resources.

0 commit comments

Comments
 (0)