Skip to content

Commit

Permalink
Adding support of UDN l2 primary using VMs
Browse files Browse the repository at this point in the history
Needed to be run on 4.18 and above, support l2bridge or passt binding method
  • Loading branch information
capolrik committed Jan 21, 2025
1 parent c952ec5 commit 97f6868
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 30 deletions.
52 changes: 28 additions & 24 deletions cmd/k8s-netperf/k8s-netperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,30 @@ const index = "k8s-netperf"
const retry = 3

var (
cfgfile string
nl bool
clean bool
netperf bool
iperf3 bool
uperf bool
udn bool
acrossAZ bool
full bool
vm bool
vmimage string
debug bool
bridge string
bridgeNetwork string
promURL string
id string
searchURL string
showMetrics bool
tcpt float64
json bool
version bool
csvArchive bool
searchIndex string
cfgfile string
nl bool
clean bool
netperf bool
iperf3 bool
uperf bool
udn bool
udnPluginBinding string
acrossAZ bool
full bool
vm bool
vmimage string
debug bool
bridge string
bridgeNetwork string
promURL string
id string
searchURL string
showMetrics bool
tcpt float64
json bool
version bool
csvArchive bool
searchIndex string
)

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -198,6 +199,9 @@ var rootCmd = &cobra.Command{
log.Error(err)
}
}
if udn {
s.UdnPluginBinding = udnPluginBinding
}
}

// Build the SUT (Deployments)
Expand Down Expand Up @@ -468,7 +472,6 @@ func executeWorkload(nc config.Config,
//when using a bridge
} else if s.BridgeServerNetwork != "" {
serverIP = strings.Split(s.BridgeServerNetwork, "/")[0]

} else {
if hostNet {
serverIP = s.ServerHost.Items[0].Status.PodIP
Expand Down Expand Up @@ -568,6 +571,7 @@ func main() {
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().BoolVar(&udn, "udn", false, "Create and use a UDN called 'udn-l2-primary' as primary network.")
rootCmd.Flags().StringVar(&udnPluginBinding, "udnPluginBinding", "passt", "UDN with VMs only - the binding method of the UDN interface, select 'passt' or 'l2bridge'")
rootCmd.Flags().StringVar(&bridge, "bridge", "", "Name of the NNCP to be used for creating bridge interface - VM only.")
rootCmd.Flags().StringVar(&bridgeNetwork, "bridgeNetwork", "bridgeNetwork.json", "Json file for the network defined by the bridge interface - bridge should be enabled")
rootCmd.Flags().StringVar(&promURL, "prom", "", "Prometheus URL")
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type PerfScenarios struct {
VMImage string
VMHost string
Udn bool
UdnPluginBinding string
BridgeServerNetwork string
BridgeClientNetwork string
ServerNodeInfo metrics.NodeInfo
Expand Down
10 changes: 6 additions & 4 deletions pkg/k8s/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ func DeployL2Udn(dynamicClient *dynamic.DynamicClient) error {
"spec": map[string]interface{}{
"topology": "Layer2",
"layer2": map[string]interface{}{
"role": "Primary",
"subnets": []string{"10.0.0.0/24", "2001:db8::/60"},
"role": "Primary",
"subnets": []string{"10.0.0.0/24"},
"ipamLifecycle": "Persistent",
},
},
},
Expand Down Expand Up @@ -587,14 +588,15 @@ func ExtractUdnIp(s config.PerfScenarios) (string, error) {

// launchServerVM will create the ServerVM with the specific node and pod affinity.
func launchServerVM(perf *config.PerfScenarios, name string, podAff *corev1.PodAntiAffinity, nodeAff *corev1.NodeAffinity) error {
_, err := CreateVMServer(perf.KClient, serverRole, serverRole, *podAff, *nodeAff, perf.VMImage, perf.BridgeServerNetwork)
_, err := CreateVMServer(perf.KClient, serverRole, serverRole, *podAff, *nodeAff, perf.VMImage, perf.BridgeServerNetwork, perf.Udn, perf.UdnPluginBinding)
if err != nil {
return err
}
err = WaitForVMI(perf.KClient, serverRole)
if err != nil {
return err
}

if strings.Contains(name, "host") {
perf.ServerHost, err = GetPods(perf.ClientSet, fmt.Sprintf("app=%s", serverRole))
if err != nil {
Expand All @@ -612,7 +614,7 @@ func launchServerVM(perf *config.PerfScenarios, name string, podAff *corev1.PodA

// launchClientVM will create the ClientVM with the specific node and pod affinity.
func launchClientVM(perf *config.PerfScenarios, name string, podAff *corev1.PodAntiAffinity, nodeAff *corev1.NodeAffinity) error {
host, err := CreateVMClient(perf.KClient, perf.ClientSet, perf.DClient, name, podAff, nodeAff, perf.VMImage, perf.BridgeClientNetwork)
host, err := CreateVMClient(perf.KClient, perf.ClientSet, perf.DClient, name, podAff, nodeAff, perf.VMImage, perf.BridgeClientNetwork, perf.Udn, perf.UdnPluginBinding)
if err != nil {
return err
}
Expand Down
47 changes: 45 additions & 2 deletions pkg/k8s/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func exposeService(client *kubernetes.Clientset, dynamicClient *dynamic.DynamicC

// CreateVMClient takes in the affinity rules and deploys the VMI
func CreateVMClient(kclient *kubevirtv1.KubevirtV1Client, client *kubernetes.Clientset,
dyn *dynamic.DynamicClient, name string, podAff *corev1.PodAntiAffinity, nodeAff *corev1.NodeAffinity, vmimage string, bridgeNetwork string) (string, error) {
dyn *dynamic.DynamicClient, name string, podAff *corev1.PodAntiAffinity, nodeAff *corev1.NodeAffinity, vmimage string, bridgeNetwork string, udn bool, udnPluginBinding string) (string, error) {
label := map[string]string{
"app": name,
"role": name,
Expand Down Expand Up @@ -232,6 +232,27 @@ runcmd:
ethernets:
eth1:
addresses: [ %s ]`, bridgeNetwork)
} else if udn {
interfaces = []v1.Interface{
{
Name: "primary-l2-net",
Binding: &v1.PluginBinding{
Name: udnPluginBinding,
},
},
}
networks = []v1.Network{
{
Name: "primary-l2-net",
NetworkSource: v1.NetworkSource{
Pod: &v1.PodNetwork{},
},
},
}
netData = `version: 2
ethernets:
eth0:
dhcp4: true`
}
_, err = CreateVMI(kclient, name, label, b64.StdEncoding.EncodeToString([]byte(data)), *podAff, *nodeAff, vmimage, interfaces, networks, b64.StdEncoding.EncodeToString([]byte(netData)))
if err != nil {
Expand All @@ -250,7 +271,7 @@ ethernets:

// CreateVMServer will take the pod and node affinity and deploy the VMI
func CreateVMServer(client *kubevirtv1.KubevirtV1Client, name string, role string, podAff corev1.PodAntiAffinity,
nodeAff corev1.NodeAffinity, vmimage string, bridgeNetwork string) (*v1.VirtualMachineInstance, error) {
nodeAff corev1.NodeAffinity, vmimage string, bridgeNetwork string, udn bool, udnPluginBinding string) (*v1.VirtualMachineInstance, error) {
label := map[string]string{
"app": name,
"role": role,
Expand All @@ -275,6 +296,7 @@ ssh_deletekeys: false
password: fedora
chpasswd: { expire: False }
runcmd:
- export HOME=/home/fedora
- dnf install -y --nodocs uperf iperf3 git ethtool
- dnf install -y --nodocs automake gcc bc lksctp-tools-devel texinfo --enablerepo=*
- git clone https://github.com/HewlettPackard/netperf.git
Expand Down Expand Up @@ -325,6 +347,27 @@ runcmd:
ethernets:
eth1:
addresses: [ %s ]`, bridgeNetwork)
} else if udn {
interfaces = []v1.Interface{
{
Name: "primary-l2-net",
Binding: &v1.PluginBinding{
Name: udnPluginBinding,
},
},
}
networks = []v1.Network{
{
Name: "primary-l2-net",
NetworkSource: v1.NetworkSource{
Pod: &v1.PodNetwork{},
},
},
}
netData = `version: 2
ethernets:
eth0:
dhcp4: true`
}
return CreateVMI(client, name, label, b64.StdEncoding.EncodeToString([]byte(data)), podAff, nodeAff, vmimage, interfaces, networks, b64.StdEncoding.EncodeToString([]byte(netData)))
}
Expand Down

0 comments on commit 97f6868

Please sign in to comment.