Skip to content

Commit b5efb6c

Browse files
committed
Labels take the highest priority
Signed-off-by: Joe Talerico aka rook <[email protected]>
1 parent 6e2b3a6 commit b5efb6c

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

pkg/k8s/kubernetes.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
354354
}
355355
if z != "" && numNodes > 1 {
356356
cdp.NodeAffinity = corev1.NodeAffinity{
357-
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z, "client"),
357+
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(*client, z, "client"),
358358
}
359359
}
360360

@@ -440,7 +440,7 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
440440
if z != "" {
441441
if numNodes > 1 {
442442
cdpAcross.NodeAffinity = corev1.NodeAffinity{
443-
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z, "client"),
443+
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(*client, z, "client"),
444444
RequiredDuringSchedulingIgnoredDuringExecution: workerNodeSelectorExpression,
445445
}
446446
} else {
@@ -468,7 +468,7 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
468468
if ncount > 1 {
469469
if s.HostNetwork {
470470
cdpHostAcross.NodeAffinity = corev1.NodeAffinity{
471-
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z, "client"),
471+
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(*client, z, "client"),
472472
RequiredDuringSchedulingIgnoredDuringExecution: workerNodeSelectorExpression,
473473
}
474474
cdpHostAcross.PodAntiAffinity = corev1.PodAntiAffinity{
@@ -533,9 +533,9 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
533533
if z != "" {
534534
var affinity corev1.NodeAffinity
535535
if numNodes > 1 {
536-
nodeZone := zoneNodeSelectorExpression(z, "server")
536+
nodeZone := zoneNodeSelectorExpression(*client, z, "server")
537537
if s.AcrossAZ {
538-
nodeZone = zoneNodeSelectorExpression(acrossZone, "server")
538+
nodeZone = zoneNodeSelectorExpression(*client, acrossZone, "server")
539539
}
540540
affinity = corev1.NodeAffinity{
541541
PreferredDuringSchedulingIgnoredDuringExecution: nodeZone,
@@ -717,8 +717,9 @@ func launchClientVM(perf *config.PerfScenarios, name string, podAff *corev1.PodA
717717
return nil
718718
}
719719

720-
func zoneNodeSelectorExpression(zone string, role string) []corev1.PreferredSchedulingTerm {
721-
if zone != "" {
720+
func zoneNodeSelectorExpression(c kubernetes.Clientset, zone string, role string) []corev1.PreferredSchedulingTerm {
721+
labeled := areNodesLabeled(&c)
722+
if labeled != true && zone != "" {
722723
return []corev1.PreferredSchedulingTerm{
723724
{
724725
Weight: 100,
@@ -739,7 +740,6 @@ func zoneNodeSelectorExpression(zone string, role string) []corev1.PreferredSche
739740
{Key: "netperf", Operator: corev1.NodeSelectorOpIn, Values: []string{role}},
740741
},
741742
},
742-
743743
},
744744
}
745745
}
@@ -787,6 +787,17 @@ func WaitForReady(c *kubernetes.Clientset, dp DeploymentParams) (bool, error) {
787787
return false, fmt.Errorf("❌ Deployment had issues")
788788
}
789789

790+
func areNodesLabeled(c *kubernetes.Clientset) bool {
791+
nodes, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{LabelSelector: "netperf=server,netperf=client"})
792+
if err != nil {
793+
log.Errorf("Unable to query nodes: %v", err)
794+
}
795+
if len(nodes.Items) == 0 {
796+
return false
797+
}
798+
return true
799+
}
800+
790801
// WaitForDelete return nil if the namespace is deleted, error otherwise
791802
func waitForNamespaceDelete(c *kubernetes.Clientset, nsName string) error {
792803
log.Infof("⏰ Waiting for %s Namespace to be deleted...", nsName)

0 commit comments

Comments
 (0)