@@ -12,6 +12,7 @@ import (
12
12
corev1 "k8s.io/api/core/v1"
13
13
v1 "k8s.io/api/rbac/v1"
14
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
+ "k8s.io/apimachinery/pkg/labels"
15
16
"k8s.io/apimachinery/pkg/util/intstr"
16
17
"k8s.io/apimachinery/pkg/watch"
17
18
"k8s.io/client-go/kubernetes"
@@ -218,7 +219,8 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
218
219
return err
219
220
}
220
221
}
221
- s .ClientNodeInfo , _ = GetPodNodeInfo (client , cdp )
222
+ s .ClientNodeInfo , err = GetPodNodeInfo (client , labels .Set (cdp .Labels ).String ())
223
+ return err
222
224
}
223
225
224
226
// Create iperf service
@@ -431,9 +433,12 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
431
433
if err != nil {
432
434
return err
433
435
}
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
+ }
435
440
if ! s .NodeLocal {
436
- s .ClientNodeInfo , _ = GetPodNodeInfo (client , cdpAcross )
441
+ s .ClientNodeInfo , err = GetPodNodeInfo (client , labels . Set ( cdpAcross . Labels ). String () )
437
442
}
438
443
if err != nil {
439
444
return err
@@ -459,17 +464,17 @@ func launchServerVM(perf *config.PerfScenarios, name string, podAff *corev1.PodA
459
464
return err
460
465
}
461
466
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 ))
463
468
if err != nil {
464
469
return err
465
470
}
466
471
} 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 ))
468
473
if err != nil {
469
474
return err
470
475
}
471
476
}
472
- perf .ServerNodeInfo , _ = GetNakedPodNodeInfo (perf .ClientSet , fmt .Sprintf ("app=%s" , serverRole ))
477
+ perf .ServerNodeInfo , _ = GetPodNodeInfo (perf .ClientSet , fmt .Sprintf ("app=%s" , serverRole ))
473
478
return nil
474
479
}
475
480
@@ -485,17 +490,17 @@ func launchClientVM(perf *config.PerfScenarios, name string, podAff *corev1.PodA
485
490
return err
486
491
}
487
492
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 ))
489
494
if err != nil {
490
495
return err
491
496
}
492
497
} 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 ))
494
499
if err != nil {
495
500
return err
496
501
}
497
502
}
498
- perf .ClientNodeInfo , _ = GetNakedPodNodeInfo (perf .ClientSet , fmt .Sprintf ("app=%s" , name ))
503
+ perf .ClientNodeInfo , _ = GetPodNodeInfo (perf .ClientSet , fmt .Sprintf ("app=%s" , name ))
499
504
return nil
500
505
}
501
506
@@ -525,7 +530,7 @@ func deployDeployment(client *kubernetes.Clientset, dp DeploymentParams) (corev1
525
530
return pods , err
526
531
}
527
532
// 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 () )
529
534
if err != nil {
530
535
return pods , err
531
536
}
@@ -660,46 +665,8 @@ func CreateDeployment(dp DeploymentParams, client *kubernetes.Clientset) (*appsv
660
665
return dc .Create (context .TODO (), deployment , metav1.CreateOptions {})
661
666
}
662
667
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
-
673
668
// 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 ) {
703
670
var info metrics.NodeInfo
704
671
listOpt := metav1.ListOptions {
705
672
LabelSelector : label ,
@@ -716,58 +683,29 @@ func GetNakedPodNodeInfo(c *kubernetes.Clientset, label string) (metrics.NodeInf
716
683
} else {
717
684
info .IP = p .Status .HostIP
718
685
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
719
691
}
720
692
}
721
693
log .Debugf ("Machine with lablel %s is Running on %s with IP %s" , label , info .Hostname , info .IP )
722
694
return info , nil
723
695
}
724
696
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 ) {
755
699
listOpt := metav1.ListOptions {
756
700
LabelSelector : label ,
701
+ FieldSelector : "status.phase=Running" ,
757
702
}
758
703
log .Infof ("Looking for pods with label %s" , fmt .Sprint (label ))
759
704
pods , err := c .CoreV1 ().Pods (namespace ).List (context .TODO (), listOpt )
760
705
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 )
769
707
}
770
- return npl , nil
708
+ return * pods , nil
771
709
772
710
}
773
711
0 commit comments