From 11888db742c042af607fe084493d30cc2833742c Mon Sep 17 00:00:00 2001 From: Joe Talerico aka rook Date: Thu, 9 Jan 2025 15:10:54 -0500 Subject: [PATCH] Label hint If the user wants to provide hints to help schedule the client and server on specific nodes, they can add `netperf=true` label to the nodes they want tested. Signed-off-by: Joe Talerico aka rook --- README.md | 10 ++++++++++ pkg/k8s/kubernetes.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/README.md b/README.md index 6fa1d79..c7bf5dd 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,16 @@ $ cd k8s-netperf $ make container-build ``` +## Label nodes +k8s-netperf will make the best decision it can to schedule the client and server in your cluster. However, +you can provide hints to ensure the client and server will always land on specific nodes. + +To do this, apply a label to the nodes you want the client and server running + +```shell +$ oc label nodes node-name netperf=true +``` + ## Running with Pods Ensure your `kubeconfig` is properly set to the cluster you would like to run `k8s-netperf` against. diff --git a/pkg/k8s/kubernetes.go b/pkg/k8s/kubernetes.go index 36e953a..2649318 100644 --- a/pkg/k8s/kubernetes.go +++ b/pkg/k8s/kubernetes.go @@ -342,6 +342,21 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error { RequiredDuringSchedulingIgnoredDuringExecution: workerNodeSelectorExpression, } } + } else { + affinity := corev1.NodeAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []corev1.PreferredSchedulingTerm{ + { + Weight: 100, + Preference: corev1.NodeSelectorTerm{ + MatchExpressions: []corev1.NodeSelectorRequirement{ + {Key: "netperf", Operator: corev1.NodeSelectorOpIn, Values: []string{"true"}}, + }, + }, + }, + }, + } + cdpAcross.NodeAffinity = affinity + cdpHostAcross.NodeAffinity = affinity } if ncount > 1 { @@ -427,6 +442,21 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error { } sdp.NodeAffinity = affinity sdpHost.NodeAffinity = affinity + } else { + affinity := corev1.NodeAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []corev1.PreferredSchedulingTerm{ + { + Weight: 100, + Preference: corev1.NodeSelectorTerm{ + MatchExpressions: []corev1.NodeSelectorRequirement{ + {Key: "netperf", Operator: corev1.NodeSelectorOpIn, Values: []string{"true"}}, + }, + }, + }, + }, + } + sdp.NodeAffinity = affinity + sdpHost.NodeAffinity = affinity } if ncount > 1 { antiAffinity := corev1.PodAntiAffinity{ @@ -583,6 +613,7 @@ func zoneNodeSelectorExpression(zone string) []corev1.PreferredSchedulingTerm { Preference: corev1.NodeSelectorTerm{ MatchExpressions: []corev1.NodeSelectorRequirement{ {Key: "topology.kubernetes.io/zone", Operator: corev1.NodeSelectorOpIn, Values: []string{zone}}, + {Key: "netperf", Operator: corev1.NodeSelectorOpIn, Values: []string{"true"}}, }, }, },