Skip to content

Commit

Permalink
Fix hostNetwork code
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Sevilla <[email protected]>
  • Loading branch information
rsevilla87 committed Feb 19, 2024
1 parent 36a00d3 commit 85213fd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 41 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ Flags:
- When using `--prom` with a non-openshift clsuter, it will be necessary to pass the prometheus URL.
- `--metrics` will enable displaying prometheus captured metrics to stdout. By default they will be written to a csv file.
- `--iperf` will enable the iperf3 load driver for any stream test (TCP_STREAM, UDP_STREAM). iperf3 doesn't have a RR or CRR test-type.
- `--uperf ` will enable the uperf load driver for any stream test (TCP_STREAM, UDP_STREAM). uperf doesn't have CRR test-type.
- `--uperf` will enable the uperf load driver for any stream test (TCP_STREAM, UDP_STREAM). uperf doesn't have CRR test-type.
> *Note: With OpenShift, we attempt to discover the OpenShift route. If that route is not reachable, it might be required to `port-forward` the service and pass that via the `--prom` option.*
### Config file
#### Config File v2
The v2 config file will be executed in the order the tests are presented in the config file.
```yml
tests :
- TCPStream: # Place-holder of a test name
Expand Down
51 changes: 16 additions & 35 deletions cmd/k8s-netperf/k8s-netperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ var rootCmd = &cobra.Command{
Use: "k8s-netperf",
Short: "A tool to run network performance tests in Kubernetes cluster",
Run: func(cmd *cobra.Command, args []string) {
var acrossAZ, hostNetwork bool
var sr result.ScenarioResults
if version {
fmt.Println("Version:", cmdVersion.Version)
fmt.Println("Git Commit:", cmdVersion.GitCommit)
Expand Down Expand Up @@ -139,13 +141,11 @@ var rootCmd = &cobra.Command{
log.Fatal(err)
}

var sr result.ScenarioResults
sr.Version = cmdVersion.Version
sr.GitCommit = cmdVersion.GitCommit
// If the client and server needs to be across zones
lz, zones, _ := k8s.GetZone(client)
nodesInZone := zones[lz]
var acrossAZ bool
if nodesInZone > 1 {
acrossAZ = false
} else {
Expand All @@ -161,40 +161,24 @@ var rootCmd = &cobra.Command{
}
nc.Metric = metric
nc.AcrossAZ = acrossAZ

if s.HostNetwork {
// No need to run hostNetwork through Service.
if !nc.Service {
if netperf {
npr := executeWorkload(nc, s, true, true, false, false)
sr.Results = append(sr.Results, npr)
}
if iperf3 {
ipr := executeWorkload(nc, s, true, true, true, false)
if len(ipr.Profile) > 1 {
sr.Results = append(sr.Results, ipr)
}
}
if uperf {
upr := executeWorkload(nc, s, true, true, true, true)
if len(upr.Profile) > 1 {
sr.Results = append(sr.Results, upr)
}
}
}
// No need to run hostNetwork through Service.
if s.HostNetwork && !nc.Service {
hostNetwork = true
} else {
hostNetwork = false
}
if netperf {
npr := executeWorkload(nc, s, false, true, false, false)
npr := executeWorkload(nc, s, hostNetwork, true, false, false)
sr.Results = append(sr.Results, npr)
}
if iperf3 {
ipr := executeWorkload(nc, s, false, false, true, false)
ipr := executeWorkload(nc, s, hostNetwork, false, true, false)
if len(ipr.Profile) > 1 {
sr.Results = append(sr.Results, ipr)
}
}
if uperf {
upr := executeWorkload(nc, s, false, false, false, true)
upr := executeWorkload(nc, s, hostNetwork, false, false, true)
if len(upr.Profile) > 1 {
sr.Results = append(sr.Results, upr)
}
Expand Down Expand Up @@ -338,14 +322,12 @@ func cleanup(client *kubernetes.Clientset) {

}

func executeWorkload(nc config.Config, s config.PerfScenarios, hostNet bool, netperfDriver, iperf3, uperf bool) result.Data {
// executeWorkload executes the workload and returns the result data.
func executeWorkload(nc config.Config, s config.PerfScenarios, hostNet bool, netperf, iperf3, uperf bool) result.Data {
serverIP := ""
service := false
sameNode := true
Client := s.Client
var driver drivers.Driver
if nc.Service {
service = true
if iperf3 {
serverIP = s.IperfService.Spec.ClusterIP
} else if uperf {
Expand All @@ -362,27 +344,26 @@ func executeWorkload(nc config.Config, s config.PerfScenarios, hostNet bool, net
}
if !s.NodeLocal {
Client = s.ClientAcross
sameNode = false
}
if hostNet {
Client = s.ClientHost
}
npr := result.Data{}
npr.Config = nc
npr.Metric = nc.Metric
npr.Service = service
npr.SameNode = sameNode
npr.Service = nc.Service
npr.SameNode = s.NodeLocal
npr.HostNetwork = hostNet
if s.AcrossAZ {
npr.AcrossAZ = true
} else {
npr.AcrossAZ = nc.AcrossAZ
}
npr.StartTime = time.Now()
log.Debugf("Executing workloads. hostNetwork is %t, service is %t", hostNet, service)
log.Debugf("Executing workloads. hostNetwork is %t, service is %t", hostNet, nc.Service)
for i := 0; i < nc.Samples; i++ {
nr := sample.Sample{}
if netperfDriver {
if netperf {
driver = drivers.NewDriver("netperf")
npr.Driver = "netperf"
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/drivers/iperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,9 @@ func (i *iperf3) ParseResults(stdout *bytes.Buffer) (sample.Sample, error) {
sample.Driver = i.driverName
result := IperfResult{}
sample.Metric = "Mb/s"
error := json.NewDecoder(stdout).Decode(&result)
if error != nil {
log.Error("Issue while decoding")
log.Error(error)
err := json.NewDecoder(stdout).Decode(&result)
if err != nil {
log.Errorf("Issue while decoding: %v", err)
}
if result.Data.TCPStream.Rate > 0 {
sample.Throughput = float64(result.Data.TCPStream.Rate) / 1000000
Expand All @@ -191,7 +190,7 @@ func (i *iperf3) ParseResults(stdout *bytes.Buffer) (sample.Sample, error) {
sample.LossPercent = result.Data.UDPStream.LossPercent
}

log.Debugf("Storing %s sample throughput: %f", sample.Driver, sample.Throughput)
log.Debugf("Storing %s sample throughput: %f", sample.Driver, sample.Throughput)

return sample, nil
}

0 comments on commit 85213fd

Please sign in to comment.