Skip to content

Hint ordering matters #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions pkg/k8s/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
}
if z != "" && numNodes > 1 {
cdp.NodeAffinity = corev1.NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z, "client"),
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(*client, z, "client"),
}
}

Expand Down Expand Up @@ -440,7 +440,7 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
if z != "" {
if numNodes > 1 {
cdpAcross.NodeAffinity = corev1.NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z, "client"),
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(*client, z, "client"),
RequiredDuringSchedulingIgnoredDuringExecution: workerNodeSelectorExpression,
}
} else {
Expand Down Expand Up @@ -468,7 +468,7 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
if ncount > 1 {
if s.HostNetwork {
cdpHostAcross.NodeAffinity = corev1.NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z, "client"),
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(*client, z, "client"),
RequiredDuringSchedulingIgnoredDuringExecution: workerNodeSelectorExpression,
}
cdpHostAcross.PodAntiAffinity = corev1.PodAntiAffinity{
Expand Down Expand Up @@ -533,9 +533,9 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
if z != "" {
var affinity corev1.NodeAffinity
if numNodes > 1 {
nodeZone := zoneNodeSelectorExpression(z, "server")
nodeZone := zoneNodeSelectorExpression(*client, z, "server")
if s.AcrossAZ {
nodeZone = zoneNodeSelectorExpression(acrossZone, "server")
nodeZone = zoneNodeSelectorExpression(*client, acrossZone, "server")
}
affinity = corev1.NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: nodeZone,
Expand Down Expand Up @@ -717,13 +717,26 @@ func launchClientVM(perf *config.PerfScenarios, name string, podAff *corev1.PodA
return nil
}

func zoneNodeSelectorExpression(zone string, role string) []corev1.PreferredSchedulingTerm {
func zoneNodeSelectorExpression(c kubernetes.Clientset, zone string, role string) []corev1.PreferredSchedulingTerm {
labeled := areNodesLabeled(&c)
if !labeled && zone != "" {
return []corev1.PreferredSchedulingTerm{
{
Weight: 100,
Preference: corev1.NodeSelectorTerm{
MatchExpressions: []corev1.NodeSelectorRequirement{
{Key: "netperf", Operator: corev1.NodeSelectorOpIn, Values: []string{role}},
{Key: "topology.kubernetes.io/zone", Operator: corev1.NodeSelectorOpIn, Values: []string{zone}},
},
},
},
}
}
return []corev1.PreferredSchedulingTerm{
{
Weight: 100,
Preference: corev1.NodeSelectorTerm{
MatchExpressions: []corev1.NodeSelectorRequirement{
{Key: "topology.kubernetes.io/zone", Operator: corev1.NodeSelectorOpIn, Values: []string{zone}},
{Key: "netperf", Operator: corev1.NodeSelectorOpIn, Values: []string{role}},
},
},
Expand Down Expand Up @@ -774,6 +787,21 @@ func WaitForReady(c *kubernetes.Clientset, dp DeploymentParams) (bool, error) {
return false, fmt.Errorf("❌ Deployment had issues")
}

func areNodesLabeled(c *kubernetes.Clientset) bool {
server, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{LabelSelector: "netperf=server"})
if err != nil {
log.Errorf("Unable to query nodes: %v", err)
}
client, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{LabelSelector: "netperf=client"})
if err != nil {
log.Errorf("Unable to query nodes: %v", err)
}
if len(server.Items) == 0 && len(client.Items) == 0 {
return false
}
return true
}

// WaitForDelete return nil if the namespace is deleted, error otherwise
func waitForNamespaceDelete(c *kubernetes.Clientset, nsName string) error {
log.Infof("⏰ Waiting for %s Namespace to be deleted...", nsName)
Expand Down
Loading