Skip to content

Commit

Permalink
Adding support of UDN usage
Browse files Browse the repository at this point in the history
Using --udn option create a UserDefinedNetwork object on the netperf ns
  • Loading branch information
capolrik committed Oct 31, 2024
1 parent 3771765 commit c7a7199
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
25 changes: 22 additions & 3 deletions cmd/k8s-netperf/k8s-netperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
netperf bool
iperf3 bool
uperf bool
udn string
acrossAZ bool
full bool
vm bool
Expand Down Expand Up @@ -151,19 +152,36 @@ var rootCmd = &cobra.Command{
os.Exit(1)
}

if vm {
s.VM = true
if len(udn) > 1 {
// s.udn = udn
// Create a dynamic client
dynClient, err := dynamic.NewForConfig(rconfig)
if err != nil {
log.Error(err)
}
s.DClient = dynClient
err = k8s.DeployUdn(dynClient, udn)
if err != nil {
log.Error(err)
os.Exit(1)
}
}

if vm {
s.VM = true
// Create a dynamic client
if s.DClient == nil {
dynClient, err := dynamic.NewForConfig(rconfig)
if err != nil {
log.Error(err)
}
s.DClient = dynClient
}
kclient, err := kubevirtv1.NewForConfig(rconfig)
if err != nil {
log.Error(err)
}
s.KClient = kclient
s.DClient = dynClient
}

// Build the SUT (Deployments)
Expand Down Expand Up @@ -481,6 +499,7 @@ func main() {
rootCmd.Flags().BoolVar(&acrossAZ, "across", false, "Place the client and server across availability zones")
rootCmd.Flags().BoolVar(&full, "all", false, "Run all tests scenarios - hostNet and podNetwork (if possible)")
rootCmd.Flags().BoolVar(&debug, "debug", false, "Enable debug log")
rootCmd.Flags().StringVar(&udn, "udn", "", "Create and use a UDN using this name if provided.")
rootCmd.Flags().StringVar(&promURL, "prom", "", "Prometheus URL")
rootCmd.Flags().StringVar(&id, "uuid", "", "User provided UUID")
rootCmd.Flags().StringVar(&searchURL, "search", "", "OpenSearch URL, if you have auth, pass in the format of https://user:pass@url:port")
Expand Down
36 changes: 36 additions & 0 deletions pkg/k8s/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import (
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/utils/pointer"
)
Expand Down Expand Up @@ -124,6 +127,39 @@ func BuildInfra(client *kubernetes.Clientset) error {
return nil
}

// Create a User Defined Network for the tests
func DeployUdn(dynamicClient *dynamic.DynamicClient, udnName string) error {
udn := &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "k8s.ovn.org/v1",
"kind": "UserDefinedNetwork",
"metadata": map[string]interface{}{
"name": udnName,
"namespace": "netperf",
},
"spec": map[string]interface{}{
"topology": "Layer2",
"layer2": map[string]interface{}{
"role": "Primary",
"subnets": []string{"10.0.0.0/24", "2001:db8::/60"},
},
},
},
}

// Specify the GVR for UDN
gvr := schema.GroupVersionResource{
Group: "k8s.ovn.org",
Version: "v1",
Resource: "userdefinednetworks",
}
_, err := dynamicClient.Resource(gvr).Namespace(namespace).Create(context.TODO(), udn, metav1.CreateOptions{})
if err != nil {
log.Fatalf("Failed to create UDN: %v", err)
}
return nil
}

// BuildSUT Build the k8s env to run network performance tests
func BuildSUT(client *kubernetes.Clientset, s *config.PerfScenarios) error {
var netperfDataPorts []int32
Expand Down

0 comments on commit c7a7199

Please sign in to comment.