Skip to content

Commit

Permalink
Merge pull request #161 from jtaleric/label-hint
Browse files Browse the repository at this point in the history
Label hint
  • Loading branch information
capolrik authored Jan 13, 2025
2 parents 71f74b8 + 75fcc0e commit dc1a1b1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
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

0 comments on commit dc1a1b1

Please sign in to comment.