in contrib/cmd/runkperf/commands/bench/node100_pod10k.go [193:225]
func getDeploymentPodSize(ctx context.Context, kubeCfgPath string, namePattern string) (int, error) {
ns := fmt.Sprintf("%s-0", namePattern)
labelSelector := fmt.Sprintf("app=%s", namePattern)
log.GetLogger(ctx).
WithKeyValues("level", "info").
LogKV("msg", "get the size of pod", "labelSelector", labelSelector, "namespace", ns)
cli, err := utils.BuildClientset(kubeCfgPath)
if err != nil {
return 0, err
}
resp, err := cli.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{
LabelSelector: labelSelector,
Limit: 1,
})
if err != nil {
return 0, fmt.Errorf("failed to list pods with labelSelector %s: %w",
labelSelector, err)
}
if len(resp.Items) == 0 {
return 0, fmt.Errorf("no pod with labelSelector %s in namespace %s: %w",
labelSelector, ns, err)
}
pod := resp.Items[0]
data, err := json.Marshal(pod)
if err != nil {
return 0, fmt.Errorf("failed to json.Marshal pod: %w", err)
}
return len(data), nil
}