Skip to content

Commit 9e781be

Browse files
authored
Add virtctl ssh option (#220)
* Add virtctl ssh option Allow the user to toggle between SSH and virtctl ssh. The virtctl option does not use the virtctl ssh as a lib -- due to lib conflicts. Signed-off-by: jtalerico <joe.talerico@gmail.com> * Fix virtctl issue Signed-off-by: jtalerico <joe.talerico@gmail.com> * Remove go.sum Signed-off-by: jtalerico <joe.talerico@gmail.com> * Add go.sum Signed-off-by: jtalerico <joe.talerico@gmail.com> * Update go-commons Signed-off-by: jtalerico <joe.talerico@gmail.com> * Fix go.mod Signed-off-by: jtalerico <joe.talerico@gmail.com> * Revert go version Signed-off-by: jtalerico <joe.talerico@gmail.com> * Move to 1.23 Signed-off-by: jtalerico <joe.talerico@gmail.com> * address lint Signed-off-by: jtalerico <joe.talerico@gmail.com> * Match driver retry Signed-off-by: jtalerico <joe.talerico@gmail.com> --------- Signed-off-by: jtalerico <joe.talerico@gmail.com>
1 parent 1e4ccde commit 9e781be

File tree

20 files changed

+532
-215
lines changed

20 files changed

+532
-215
lines changed

.github/workflows/build-container.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313

1414
env:
1515
CONTAINER_REGISTRY: ${{ 'quay.io' }}
16-
GO_VER: 1.19
16+
GO_VER: 1.23
1717
RHEL_VERSION: ubi9
1818

1919
jobs:
@@ -57,4 +57,4 @@ jobs:
5757
make gha-push
5858
env:
5959
QUAY_USER: ${{ secrets.QUAY_USER }}
60-
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
60+
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}

.github/workflows/go-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Go
1717
uses: actions/setup-go@v6
1818
with:
19-
go-version: 1.19
19+
go-version: 1.23
2020

2121
- name: Build
2222
run: make build

.github/workflows/go-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Go
1616
uses: actions/setup-go@v6
1717
with:
18-
go-version: 1.19
18+
go-version: 1.23
1919

2020
- uses: actions/checkout@v3
2121

.github/workflows/go-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
env:
99
CONTAINER_REGISTRY: ${{ github.repository_owner == 'cloud-bulldozer' && 'quay.io' }}
10-
GO_VER: 1.19
10+
GO_VER: 1.23
1111

1212
jobs:
1313
build-binaries:

.github/workflows/go-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Go
1717
uses: actions/setup-go@v6
1818
with:
19-
go-version: 1.19
19+
go-version: 1.23
2020

2121
- name: Test
2222
run: go test -v ./...

cmd/k8s-netperf/k8s-netperf.go

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/cloud-bulldozer/k8s-netperf/pkg/metrics"
2424
result "github.com/cloud-bulldozer/k8s-netperf/pkg/results"
2525
"github.com/cloud-bulldozer/k8s-netperf/pkg/sample"
26+
"github.com/cloud-bulldozer/k8s-netperf/pkg/virtctl"
2627
"github.com/google/uuid"
2728
"github.com/spf13/cobra"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -49,6 +50,7 @@ var (
4950
hostNetOnly bool
5051
vm bool
5152
vmimage string
53+
useVirtctl bool
5254
debug bool
5355
bridge string
5456
bridgeNetwork string
@@ -86,7 +88,7 @@ var rootCmd = &cobra.Command{
8688
fmt.Println("OS/Arch:", cmdVersion.OsArch)
8789
os.Exit(0)
8890
}
89-
if !(uperf || netperf || iperf3) {
91+
if !uperf && !netperf && !iperf3 {
9092
log.Fatalf("😭 At least one driver needs to be enabled")
9193
}
9294

@@ -203,6 +205,7 @@ var rootCmd = &cobra.Command{
203205
if vm {
204206
s.VM = true
205207
s.VMImage = vmimage
208+
s.UseVirtctl = useVirtctl
206209
// Create a dynamic client
207210
if s.DClient == nil {
208211
dynClient, err := dynamic.NewForConfig(rconfig)
@@ -308,12 +311,27 @@ var rootCmd = &cobra.Command{
308311
}
309312
} else {
310313
sr.Virt = true
311-
log.Info("Connecting via ssh to the VMI")
312-
client, err := k8s.SSHConnect(&s)
314+
if s.UseVirtctl {
315+
log.Info("Connecting to VMI using virtctl")
316+
} else {
317+
log.Info("Connecting via ssh to the VMI")
318+
}
319+
320+
// Use the new unified connection method
321+
vmClient, err := k8s.ConnectToVM(&s)
313322
if err != nil {
314323
log.Fatal(err)
315324
}
316-
s.SSHClient = client
325+
s.VMClient = vmClient
326+
327+
// Also set SSHClient for backward compatibility if using SSH
328+
if !s.UseVirtctl {
329+
sshClient, err := k8s.SSHConnect(&s)
330+
if err != nil {
331+
log.Fatal(err)
332+
}
333+
s.SSHClient = sshClient
334+
}
317335
for _, nc := range s.Configs {
318336
// Determine the metric for the test
319337
metric := string("OP/s")
@@ -364,20 +382,20 @@ var rootCmd = &cobra.Command{
364382
if err == nil {
365383
metadata, err := meta.GetClusterMetadata()
366384
if err == nil {
367-
sr.Metadata.ClusterMetadata = metadata
385+
sr.ClusterMetadata = metadata
368386
} else {
369387
log.Error("Issue getting common metadata using go-commons")
370388
}
371389
}
372390

373391
node := metrics.NodeDetails(pcon)
374-
sr.Metadata.Kernel = node.Metric.Kernel
392+
sr.Kernel = node.Metric.Kernel
375393
shortReg, _ := regexp.Compile(`([0-9]\.[0-9]+)-*`)
376-
short := shortReg.FindString(sr.Metadata.OCPVersion)
377-
sr.Metadata.OCPShortVersion = short
394+
short := shortReg.FindString(sr.OCPVersion)
395+
sr.OCPShortVersion = short
378396
mtu, err := metrics.NodeMTU(pcon)
379397
if err == nil {
380-
sr.Metadata.MTU = mtu
398+
sr.MTU = mtu
381399
}
382400

383401
if len(searchURL) > 1 {
@@ -453,6 +471,10 @@ var rootCmd = &cobra.Command{
453471
if clean {
454472
cleanup(client)
455473
}
474+
// Cleanup extracted virtctl binary if any
475+
if err := virtctl.CleanupExtractedBinary(); err != nil {
476+
log.Debugf("Failed to cleanup extracted virtctl binary: %v", err)
477+
}
456478
os.Exit(retCode)
457479
},
458480
}
@@ -473,7 +495,11 @@ func parseNetworkConfig(jsonFile string) (string, string, error) {
473495
if err != nil {
474496
return "", "", fmt.Errorf("error opening file: %v", err)
475497
}
476-
defer file.Close()
498+
defer func() {
499+
if err := file.Close(); err != nil {
500+
log.Warnf("Error closing file: %v", err)
501+
}
502+
}()
477503

478504
// Read the file contents
479505
log.Debugf("Reading BridgeNetwork configuration from JSON file: %s ", jsonFile)
@@ -513,11 +539,12 @@ func executeWorkload(nc config.Config,
513539
serverIP = serverIPAddr
514540
npr.ExternalServer = true
515541
} else if nc.Service {
516-
if driverName == "iperf3" {
542+
switch driverName {
543+
case "iperf3":
517544
serverIP = s.IperfService.Spec.ClusterIP
518-
} else if driverName == "uperf" {
545+
case "uperf":
519546
serverIP = s.UperfService.Spec.ClusterIP
520-
} else {
547+
default:
521548
serverIP = s.NetperfService.Spec.ClusterIP
522549
}
523550
} else if s.Udn {
@@ -639,6 +666,7 @@ func main() {
639666
rootCmd.Flags().BoolVar(&nl, "local", false, "Run network performance tests with Server-Pods/Client-Pods on the same Node")
640667
rootCmd.Flags().BoolVar(&vm, "vm", false, "Launch Virtual Machines instead of pods for client/servers")
641668
rootCmd.Flags().StringVar(&vmimage, "vm-image", "quay.io/containerdisks/fedora:39", "Use specified VM image")
669+
rootCmd.Flags().BoolVar(&useVirtctl, "use-virtctl", false, "Use virtctl ssh for VM connections instead of traditional SSH")
642670
rootCmd.Flags().Uint32Var(&sockets, "sockets", 2, "Number of Sockets for VM")
643671
rootCmd.Flags().Uint32Var(&cores, "cores", 2, "Number of cores for VM")
644672
rootCmd.Flags().Uint32Var(&threads, "threads", 1, "Number of threads for VM")

go.mod

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,81 @@
11
module github.com/cloud-bulldozer/k8s-netperf
22

3-
go 1.19
3+
go 1.23
44

55
require (
66
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794
7-
github.com/cloud-bulldozer/go-commons v1.0.16
8-
github.com/google/uuid v1.3.0
7+
github.com/cloud-bulldozer/go-commons v1.0.19
8+
github.com/google/uuid v1.6.0
99
github.com/melbahja/goph v1.4.0
1010
github.com/montanaflynn/stats v0.6.6
1111
github.com/olekukonko/tablewriter v0.0.5
12-
github.com/prometheus/common v0.44.0
12+
github.com/prometheus/common v0.62.0
1313
github.com/sirupsen/logrus v1.9.3
14-
github.com/spf13/cobra v1.6.1
15-
golang.org/x/crypto v0.14.0
16-
golang.org/x/text v0.13.0
14+
github.com/spf13/cobra v1.8.0
15+
golang.org/x/crypto v0.33.0
16+
golang.org/x/text v0.22.0
1717
gopkg.in/yaml.v3 v3.0.1
18-
k8s.io/api v0.28.4
19-
k8s.io/apimachinery v0.28.4
20-
k8s.io/client-go v0.28.4
21-
k8s.io/utils v0.0.0-20230505201702-9f6742963106
18+
k8s.io/api v0.31.1
19+
k8s.io/apimachinery v0.31.1
20+
k8s.io/client-go v0.31.1
21+
k8s.io/utils v0.0.0-20241210054802-24370beab758
2222
kubevirt.io/api v1.2.2
2323
)
2424

2525
require (
26-
github.com/davecgh/go-spew v1.1.1 // indirect
26+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2727
github.com/elastic/go-elasticsearch/v7 v7.13.1 // indirect
28-
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
29-
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
30-
github.com/go-logr/logr v1.2.4 // indirect
31-
github.com/go-openapi/jsonpointer v0.19.6 // indirect
32-
github.com/go-openapi/jsonreference v0.20.2 // indirect
33-
github.com/go-openapi/swag v0.22.3 // indirect
28+
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
29+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
30+
github.com/go-logr/logr v1.4.2 // indirect
31+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
32+
github.com/go-openapi/jsonreference v0.21.0 // indirect
33+
github.com/go-openapi/swag v0.23.0 // indirect
3434
github.com/gogo/protobuf v1.3.2 // indirect
35-
github.com/golang/protobuf v1.5.3 // indirect
36-
github.com/google/gnostic-models v0.6.8 // indirect
37-
github.com/google/go-cmp v0.5.9 // indirect
35+
github.com/golang/protobuf v1.5.4 // indirect
36+
github.com/google/gnostic-models v0.6.9 // indirect
37+
github.com/google/go-cmp v0.6.0 // indirect
3838
github.com/google/gofuzz v1.2.0 // indirect
39+
github.com/google/pprof v0.0.0-20250208200701-d0013a598941 // indirect
40+
github.com/gorilla/websocket v1.5.0 // indirect
3941
github.com/imdario/mergo v0.3.6 // indirect
40-
github.com/inconshreveable/mousetrap v1.0.1 // indirect
42+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4143
github.com/josharian/intern v1.0.0 // indirect
4244
github.com/json-iterator/go v1.1.12 // indirect
4345
github.com/kr/fs v0.1.0 // indirect
44-
github.com/mailru/easyjson v0.7.7 // indirect
46+
github.com/mailru/easyjson v0.9.0 // indirect
4547
github.com/mattn/go-runewidth v0.0.9 // indirect
46-
github.com/moby/spdystream v0.2.0 // indirect
48+
github.com/moby/spdystream v0.4.0 // indirect
4749
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4850
github.com/modern-go/reflect2 v1.0.2 // indirect
4951
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
52+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
53+
github.com/onsi/ginkgo/v2 v2.22.2 // indirect
54+
github.com/onsi/gomega v1.36.2 // indirect
5055
github.com/opensearch-project/opensearch-go v1.1.0 // indirect
51-
github.com/openshift/api v0.0.0-20230503133300-8bbcb7ca7183 // indirect
5256
github.com/openshift/custom-resource-status v1.1.2 // indirect
5357
github.com/pkg/errors v0.9.1 // indirect
5458
github.com/pkg/sftp v1.13.5 // indirect
55-
github.com/prometheus/client_golang v1.15.1 // indirect
59+
github.com/prometheus/client_golang v1.20.5 // indirect
60+
github.com/prometheus/client_model v0.6.1 // indirect
5661
github.com/spf13/pflag v1.0.5 // indirect
57-
golang.org/x/net v0.17.0 // indirect
58-
golang.org/x/oauth2 v0.8.0 // indirect
59-
golang.org/x/sys v0.13.0 // indirect
60-
golang.org/x/term v0.13.0 // indirect
61-
golang.org/x/time v0.3.0 // indirect
62-
google.golang.org/appengine v1.6.7 // indirect
63-
google.golang.org/protobuf v1.31.0 // indirect
62+
github.com/stretchr/objx v0.5.2 // indirect
63+
github.com/x448/float16 v0.8.4 // indirect
64+
golang.org/x/net v0.35.0 // indirect
65+
golang.org/x/oauth2 v0.26.0 // indirect
66+
golang.org/x/sys v0.30.0 // indirect
67+
golang.org/x/term v0.29.0 // indirect
68+
golang.org/x/time v0.10.0 // indirect
69+
golang.org/x/tools v0.30.0 // indirect
70+
google.golang.org/protobuf v1.36.5 // indirect
71+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
6472
gopkg.in/inf.v0 v0.9.1 // indirect
65-
gopkg.in/yaml.v2 v2.4.0 // indirect
6673
k8s.io/apiextensions-apiserver v0.26.3 // indirect
67-
k8s.io/klog/v2 v2.100.1 // indirect
68-
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
69-
kubevirt.io/containerized-data-importer-api v1.57.0-alpha1 // indirect
74+
k8s.io/klog/v2 v2.130.1 // indirect
75+
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
76+
kubevirt.io/containerized-data-importer-api v1.61.1 // indirect
7077
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect
71-
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
72-
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
73-
sigs.k8s.io/yaml v1.3.0 // indirect
78+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
79+
sigs.k8s.io/structured-merge-diff/v4 v4.5.0 // indirect
80+
sigs.k8s.io/yaml v1.4.0 // indirect
7481
)

0 commit comments

Comments
 (0)