Skip to content
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

Label hint #161

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ $ 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 lands 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=client
$ oc label nodes node-name netperf=server
```

## Running with Pods
Ensure your `kubeconfig` is properly set to the cluster you would like to run `k8s-netperf` against.

Expand Down
43 changes: 37 additions & 6 deletions pkg/k8s/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
}
if z != "" && numNodes > 1 {
cdp.NodeAffinity = corev1.NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z),
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z, "client"),
}
}

Expand Down Expand Up @@ -334,20 +334,35 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
if z != "" {
if numNodes > 1 {
cdpAcross.NodeAffinity = corev1.NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z),
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z, "client"),
RequiredDuringSchedulingIgnoredDuringExecution: workerNodeSelectorExpression,
}
} else {
cdpAcross.NodeAffinity = corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: workerNodeSelectorExpression,
}
}
} else {
affinity := corev1.NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.PreferredSchedulingTerm{
{
Weight: 100,
Preference: corev1.NodeSelectorTerm{
MatchExpressions: []corev1.NodeSelectorRequirement{
{Key: "netperf", Operator: corev1.NodeSelectorOpIn, Values: []string{"client"}},
},
},
},
},
}
cdpAcross.NodeAffinity = affinity
cdpHostAcross.NodeAffinity = affinity
}

if ncount > 1 {
if s.HostNetwork {
cdpHostAcross.NodeAffinity = corev1.NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z),
PreferredDuringSchedulingIgnoredDuringExecution: zoneNodeSelectorExpression(z, "client"),
RequiredDuringSchedulingIgnoredDuringExecution: workerNodeSelectorExpression,
}
cdpHostAcross.PodAntiAffinity = corev1.PodAntiAffinity{
Expand Down Expand Up @@ -412,9 +427,9 @@ func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
if z != "" {
var affinity corev1.NodeAffinity
if numNodes > 1 {
nodeZone := zoneNodeSelectorExpression(z)
nodeZone := zoneNodeSelectorExpression(z, "server")
if s.AcrossAZ {
nodeZone = zoneNodeSelectorExpression(acrossZone)
nodeZone = zoneNodeSelectorExpression(acrossZone, "server")
}
affinity = corev1.NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: nodeZone,
Expand All @@ -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{"server"}},
},
},
},
},
}
sdp.NodeAffinity = affinity
sdpHost.NodeAffinity = affinity
}
if ncount > 1 {
antiAffinity := corev1.PodAntiAffinity{
Expand Down Expand Up @@ -576,13 +606,14 @@ func launchClientVM(perf *config.PerfScenarios, name string, podAff *corev1.PodA
return nil
}

func zoneNodeSelectorExpression(zone string) []corev1.PreferredSchedulingTerm {
func zoneNodeSelectorExpression(zone string, role string) []corev1.PreferredSchedulingTerm {
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
Loading