Skip to content

Commit 361a315

Browse files
committed
Use NodeSystemInfo rather than node labels
Signed-off-by: Raul Sevilla <rsevilla@redhat.com>
1 parent 22f69b9 commit 361a315

File tree

5 files changed

+86
-148
lines changed

5 files changed

+86
-148
lines changed

cmd/k8s-netperf/k8s-netperf.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,6 @@ func executeWorkload(nc config.Config,
465465
npr.EndTime = time.Now()
466466
npr.ClientNodeInfo = s.ClientNodeInfo
467467
npr.ServerNodeInfo = s.ServerNodeInfo
468-
npr.ServerNodeLabels, _ = k8s.GetNodeLabels(s.ClientSet, s.ServerNodeInfo.Hostname)
469-
npr.ClientNodeLabels, _ = k8s.GetNodeLabels(s.ClientSet, s.ClientNodeInfo.Hostname)
470468

471469
return npr
472470
}

pkg/archive/archive.go

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,36 @@ const ltcyMetric = "usec"
1919

2020
// Doc struct of the JSON document to be indexed
2121
type Doc struct {
22-
UUID string `json:"uuid"`
23-
Timestamp time.Time `json:"timestamp"`
24-
HostNetwork bool `json:"hostNetwork"`
25-
Driver string `json:"driver"`
26-
Parallelism int `json:"parallelism"`
27-
Profile string `json:"profile"`
28-
Duration int `json:"duration"`
29-
Service bool `json:"service"`
30-
Local bool `json:"local"`
31-
Virt bool `json:"virt"`
32-
AcrossAZ bool `json:"acrossAZ"`
33-
Samples int `json:"samples"`
34-
Messagesize int `json:"messageSize"`
35-
Burst int `json:"burst"`
36-
Throughput float64 `json:"throughput"`
37-
Latency float64 `json:"latency"`
38-
TputMetric string `json:"tputMetric"`
39-
LtcyMetric string `json:"ltcyMetric"`
40-
TCPRetransmit float64 `json:"tcpRetransmits"`
41-
UDPLossPercent float64 `json:"udpLossPercent"`
42-
ToolVersion string `json:"toolVersion"`
43-
ToolGitCommit string `json:"toolGitCommit"`
44-
Metadata result.Metadata `json:"metadata"`
45-
ServerNodeCPU metrics.NodeCPU `json:"serverCPU"`
46-
ServerPodCPU []metrics.PodCPU `json:"serverPods"`
47-
ClientNodeCPU metrics.NodeCPU `json:"clientCPU"`
48-
ClientPodCPU []metrics.PodCPU `json:"clientPods"`
49-
ClientNodeLabels map[string]string `json:"clientNodeLabels"`
50-
ServerNodeLabels map[string]string `json:"serverNodeLabels"`
51-
Confidence []float64 `json:"confidence"`
22+
UUID string `json:"uuid"`
23+
Timestamp time.Time `json:"timestamp"`
24+
HostNetwork bool `json:"hostNetwork"`
25+
Driver string `json:"driver"`
26+
Parallelism int `json:"parallelism"`
27+
Profile string `json:"profile"`
28+
Duration int `json:"duration"`
29+
Service bool `json:"service"`
30+
Local bool `json:"local"`
31+
Virt bool `json:"virt"`
32+
AcrossAZ bool `json:"acrossAZ"`
33+
Samples int `json:"samples"`
34+
Messagesize int `json:"messageSize"`
35+
Burst int `json:"burst"`
36+
Throughput float64 `json:"throughput"`
37+
Latency float64 `json:"latency"`
38+
TputMetric string `json:"tputMetric"`
39+
LtcyMetric string `json:"ltcyMetric"`
40+
TCPRetransmit float64 `json:"tcpRetransmits"`
41+
UDPLossPercent float64 `json:"udpLossPercent"`
42+
ToolVersion string `json:"toolVersion"`
43+
ToolGitCommit string `json:"toolGitCommit"`
44+
Metadata result.Metadata `json:"metadata"`
45+
ServerNodeCPU metrics.NodeCPU `json:"serverCPU"`
46+
ServerPodCPU []metrics.PodCPU `json:"serverPods"`
47+
ClientNodeCPU metrics.NodeCPU `json:"clientCPU"`
48+
ClientPodCPU []metrics.PodCPU `json:"clientPods"`
49+
Confidence []float64 `json:"confidence"`
50+
ServerNodeInfo metrics.NodeInfo `json:"serverNodeInfo"`
51+
ClientNodeInfo metrics.NodeInfo `json:"clientNodeInfo"`
5252
}
5353

5454
// Connect returns a client connected to the desired cluster.
@@ -89,29 +89,31 @@ func BuildDocs(sr result.ScenarioResults, uuid string) ([]interface{}, error) {
8989
}
9090
c := []float64{lo, hi}
9191
d := Doc{
92-
UUID: uuid,
93-
Timestamp: time,
94-
ToolVersion: sr.Version,
95-
ToolGitCommit: sr.GitCommit,
96-
Driver: r.Driver,
97-
HostNetwork: r.HostNetwork,
98-
Parallelism: r.Parallelism,
99-
Profile: r.Profile,
100-
Duration: r.Duration,
101-
Virt: sr.Virt,
102-
Samples: r.Samples,
103-
Service: r.Service,
104-
Messagesize: r.MessageSize,
105-
Burst: r.Burst,
106-
TputMetric: r.Metric,
107-
LtcyMetric: ltcyMetric,
108-
ServerNodeCPU: r.ServerMetrics,
109-
ClientNodeCPU: r.ClientMetrics,
110-
ServerPodCPU: r.ServerPodCPU.Results,
111-
ClientPodCPU: r.ClientPodCPU.Results,
112-
Metadata: sr.Metadata,
113-
AcrossAZ: r.AcrossAZ,
114-
Confidence: c,
92+
UUID: uuid,
93+
Timestamp: time,
94+
ToolVersion: sr.Version,
95+
ToolGitCommit: sr.GitCommit,
96+
Driver: r.Driver,
97+
HostNetwork: r.HostNetwork,
98+
Parallelism: r.Parallelism,
99+
Profile: r.Profile,
100+
Duration: r.Duration,
101+
Virt: sr.Virt,
102+
Samples: r.Samples,
103+
Service: r.Service,
104+
Messagesize: r.MessageSize,
105+
Burst: r.Burst,
106+
TputMetric: r.Metric,
107+
LtcyMetric: ltcyMetric,
108+
ServerNodeCPU: r.ServerMetrics,
109+
ClientNodeCPU: r.ClientMetrics,
110+
ServerPodCPU: r.ServerPodCPU.Results,
111+
ClientPodCPU: r.ClientPodCPU.Results,
112+
Metadata: sr.Metadata,
113+
AcrossAZ: r.AcrossAZ,
114+
Confidence: c,
115+
ClientNodeInfo: r.ClientNodeInfo,
116+
ServerNodeInfo: r.ServerNodeInfo,
115117
}
116118
UDPLossPercent, e := result.Average(r.LossSummary)
117119
if e != nil {

pkg/k8s/kubernetes.go

Lines changed: 26 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
corev1 "k8s.io/api/core/v1"
1313
v1 "k8s.io/api/rbac/v1"
1414
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+
"k8s.io/apimachinery/pkg/labels"
1516
"k8s.io/apimachinery/pkg/util/intstr"
1617
"k8s.io/apimachinery/pkg/watch"
1718
"k8s.io/client-go/kubernetes"
@@ -218,7 +219,8 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
218219
return err
219220
}
220221
}
221-
s.ClientNodeInfo, _ = GetPodNodeInfo(client, cdp)
222+
s.ClientNodeInfo, err = GetPodNodeInfo(client, labels.Set(cdp.Labels).String())
223+
return err
222224
}
223225

224226
// Create iperf service
@@ -431,9 +433,12 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
431433
if err != nil {
432434
return err
433435
}
434-
s.ServerNodeInfo, _ = GetPodNodeInfo(client, sdp)
436+
s.ServerNodeInfo, err = GetPodNodeInfo(client, labels.Set(sdp.Labels).String())
437+
if err != nil {
438+
return err
439+
}
435440
if !s.NodeLocal {
436-
s.ClientNodeInfo, _ = GetPodNodeInfo(client, cdpAcross)
441+
s.ClientNodeInfo, err = GetPodNodeInfo(client, labels.Set(cdpAcross.Labels).String())
437442
}
438443
if err != nil {
439444
return err
@@ -459,17 +464,17 @@ func launchServerVM(perf *config.PerfScenarios, name string, podAff *corev1.PodA
459464
return err
460465
}
461466
if strings.Contains(name, "host") {
462-
perf.ServerHost, err = GetNakedPods(perf.ClientSet, fmt.Sprintf("app=%s", serverRole))
467+
perf.ServerHost, err = GetPods(perf.ClientSet, fmt.Sprintf("app=%s", serverRole))
463468
if err != nil {
464469
return err
465470
}
466471
} else {
467-
perf.Server, err = GetNakedPods(perf.ClientSet, fmt.Sprintf("app=%s", serverRole))
472+
perf.Server, err = GetPods(perf.ClientSet, fmt.Sprintf("app=%s", serverRole))
468473
if err != nil {
469474
return err
470475
}
471476
}
472-
perf.ServerNodeInfo, _ = GetNakedPodNodeInfo(perf.ClientSet, fmt.Sprintf("app=%s", serverRole))
477+
perf.ServerNodeInfo, _ = GetPodNodeInfo(perf.ClientSet, fmt.Sprintf("app=%s", serverRole))
473478
return nil
474479
}
475480

@@ -485,17 +490,17 @@ func launchClientVM(perf *config.PerfScenarios, name string, podAff *corev1.PodA
485490
return err
486491
}
487492
if strings.Contains(name, "host") {
488-
perf.ClientHost, err = GetNakedPods(perf.ClientSet, fmt.Sprintf("app=%s", name))
493+
perf.ClientHost, err = GetPods(perf.ClientSet, fmt.Sprintf("app=%s", name))
489494
if err != nil {
490495
return err
491496
}
492497
} else {
493-
perf.ClientAcross, err = GetNakedPods(perf.ClientSet, fmt.Sprintf("app=%s", name))
498+
perf.ClientAcross, err = GetPods(perf.ClientSet, fmt.Sprintf("app=%s", name))
494499
if err != nil {
495500
return err
496501
}
497502
}
498-
perf.ClientNodeInfo, _ = GetNakedPodNodeInfo(perf.ClientSet, fmt.Sprintf("app=%s", name))
503+
perf.ClientNodeInfo, _ = GetPodNodeInfo(perf.ClientSet, fmt.Sprintf("app=%s", name))
499504
return nil
500505
}
501506

@@ -525,7 +530,7 @@ func deployDeployment(client *kubernetes.Clientset, dp DeploymentParams) (corev1
525530
return pods, err
526531
}
527532
// Retrieve pods which match the server/client role labels
528-
pods, err = GetPods(client, dp)
533+
pods, err = GetPods(client, labels.Set(dp.Labels).String())
529534
if err != nil {
530535
return pods, err
531536
}
@@ -660,46 +665,8 @@ func CreateDeployment(dp DeploymentParams, client *kubernetes.Clientset) (*appsv
660665
return dc.Create(context.TODO(), deployment, metav1.CreateOptions{})
661666
}
662667

663-
// GetNodeLabels Return Labels for a specific node
664-
func GetNodeLabels(c *kubernetes.Clientset, node string) (map[string]string, error) {
665-
log.Debugf("Looking for Node labels for node - %s", node)
666-
nodeInfo, err := c.CoreV1().Nodes().Get(context.TODO(), node, metav1.GetOptions{})
667-
if err != nil {
668-
return nil, err
669-
}
670-
return nodeInfo.GetLabels(), nil
671-
}
672-
673668
// GetPodNodeInfo collects the node information for a specific pod
674-
func GetPodNodeInfo(c *kubernetes.Clientset, dp DeploymentParams) (metrics.NodeInfo, error) {
675-
var info metrics.NodeInfo
676-
d, err := c.AppsV1().Deployments(dp.Namespace).Get(context.TODO(), dp.Name, metav1.GetOptions{})
677-
if err != nil {
678-
return info, fmt.Errorf("❌ Failure to capture deployment: %v", err)
679-
}
680-
selector, err := metav1.LabelSelectorAsSelector(d.Spec.Selector)
681-
if err != nil {
682-
return info, fmt.Errorf("❌ Failure to capture deployment label: %v", err)
683-
}
684-
pods, err := c.CoreV1().Pods(dp.Namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.String(), FieldSelector: "status.phase=Running"})
685-
if err != nil {
686-
return info, fmt.Errorf("❌ Failure to capture pods: %v", err)
687-
}
688-
for pod := range pods.Items {
689-
p := pods.Items[pod]
690-
if pods.Items[pod].DeletionTimestamp != nil {
691-
continue
692-
} else {
693-
info.IP = p.Status.HostIP
694-
info.Hostname = p.Spec.NodeName
695-
}
696-
}
697-
log.Debugf("%s Running on %s with IP %s", d.Name, info.Hostname, info.IP)
698-
return info, nil
699-
}
700-
701-
// GetNakedPodNodeInfo collects the node information for a specific pod
702-
func GetNakedPodNodeInfo(c *kubernetes.Clientset, label string) (metrics.NodeInfo, error) {
669+
func GetPodNodeInfo(c *kubernetes.Clientset, label string) (metrics.NodeInfo, error) {
703670
var info metrics.NodeInfo
704671
listOpt := metav1.ListOptions{
705672
LabelSelector: label,
@@ -716,58 +683,29 @@ func GetNakedPodNodeInfo(c *kubernetes.Clientset, label string) (metrics.NodeInf
716683
} else {
717684
info.IP = p.Status.HostIP
718685
info.Hostname = p.Spec.NodeName
686+
node, err := c.CoreV1().Nodes().Get(context.TODO(), p.Spec.NodeName, metav1.GetOptions{})
687+
if err != nil {
688+
return info, err
689+
}
690+
info.NodeSystemInfo = node.Status.NodeInfo
719691
}
720692
}
721693
log.Debugf("Machine with lablel %s is Running on %s with IP %s", label, info.Hostname, info.IP)
722694
return info, nil
723695
}
724696

725-
// GetPods searches for a specific set of pods from DeploymentParms
726-
// It returns a PodList if the deployment is found.
727-
// NOTE : Since we can update the replicas to be > 1, is why I return a PodList.
728-
func GetPods(c *kubernetes.Clientset, dp DeploymentParams) (corev1.PodList, error) {
729-
d, err := c.AppsV1().Deployments(dp.Namespace).Get(context.TODO(), dp.Name, metav1.GetOptions{})
730-
npl := corev1.PodList{}
731-
if err != nil {
732-
return npl, fmt.Errorf("❌ Failure to capture deployment: %v", err)
733-
}
734-
selector, err := metav1.LabelSelectorAsSelector(d.Spec.Selector)
735-
if err != nil {
736-
return npl, fmt.Errorf("❌ Failure to capture deployment label: %v", err)
737-
}
738-
pods, err := c.CoreV1().Pods(dp.Namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.String(), FieldSelector: "status.phase=Running"})
739-
if err != nil {
740-
return npl, fmt.Errorf("❌ Failure to capture pods: %v", err)
741-
}
742-
for pod := range pods.Items {
743-
if pods.Items[pod].DeletionTimestamp != nil {
744-
continue
745-
} else {
746-
npl.Items = append(npl.Items, pods.Items[pod])
747-
}
748-
}
749-
return npl, nil
750-
}
751-
752-
// GetNakedPods when we deploy pods without a higher-level controller like deployment
753-
func GetNakedPods(c *kubernetes.Clientset, label string) (corev1.PodList, error) {
754-
npl := corev1.PodList{}
697+
// GetPods when we deploy pods without a higher-level controller like deployment
698+
func GetPods(c *kubernetes.Clientset, label string) (corev1.PodList, error) {
755699
listOpt := metav1.ListOptions{
756700
LabelSelector: label,
701+
FieldSelector: "status.phase=Running",
757702
}
758703
log.Infof("Looking for pods with label %s", fmt.Sprint(label))
759704
pods, err := c.CoreV1().Pods(namespace).List(context.TODO(), listOpt)
760705
if err != nil {
761-
return npl, fmt.Errorf("❌ Failure to capture pods: %v", err)
762-
}
763-
for pod := range pods.Items {
764-
if pods.Items[pod].DeletionTimestamp != nil {
765-
continue
766-
} else {
767-
npl.Items = append(npl.Items, pods.Items[pod])
768-
}
706+
return *pods, fmt.Errorf("❌ Failure to capture pods: %v", err)
769707
}
770-
return npl, nil
708+
return *pods, nil
771709

772710
}
773711

pkg/metrics/system.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import (
1111
"github.com/cloud-bulldozer/go-commons/prometheus"
1212
"github.com/cloud-bulldozer/k8s-netperf/pkg/logging"
1313
"github.com/prometheus/common/model"
14+
corev1 "k8s.io/api/core/v1"
1415
"k8s.io/client-go/tools/clientcmd"
1516
)
1617

1718
// NodeInfo stores the node metadata like IP and Hostname
1819
type NodeInfo struct {
19-
IP string
20-
Hostname string
21-
NodeName string
20+
IP string `json:"ip"`
21+
Hostname string `json:"hostname"`
22+
NodeName string `json:"nodeName"`
23+
corev1.NodeSystemInfo
2224
}
2325

2426
// NodeCPU stores CPU information for a specific Node

pkg/results/result.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ type Data struct {
4444
ServerMetrics metrics.NodeCPU
4545
ClientPodCPU metrics.PodValues
4646
ServerPodCPU metrics.PodValues
47-
ClientNodeLabels map[string]string
48-
ServerNodeLabels map[string]string
4947
}
5048

5149
// ScenarioResults each scenario could have multiple results

0 commit comments

Comments
 (0)