From bca1091d1b1ef9903eabd411ca8cd181baec3758 Mon Sep 17 00:00:00 2001 From: Niklas Voss Date: Wed, 30 Oct 2024 10:48:16 +0100 Subject: [PATCH] feat: allow specifying network binding via flag to be able to accommodate Passt in IPv6 environments Signed-off-by: Niklas Voss --- cmd/omni-infra-provider-kubevirt/main.go | 4 ++- internal/pkg/provider/provision.go | 32 ++++++++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cmd/omni-infra-provider-kubevirt/main.go b/cmd/omni-infra-provider-kubevirt/main.go index be2fb66..fe377b7 100644 --- a/cmd/omni-infra-provider-kubevirt/main.go +++ b/cmd/omni-infra-provider-kubevirt/main.go @@ -90,7 +90,7 @@ var rootCmd = &cobra.Command{ return fmt.Errorf("data-volume-mode flags should be one of %s", volumeOpts) } - provisioner := provider.NewProvisioner(k8sClient, cfg.namespace, cfg.dataVolumeMode) + provisioner := provider.NewProvisioner(k8sClient, cfg.namespace, cfg.dataVolumeMode, cfg.networkBinding) ip, err := infra.NewProvider(meta.ProviderID, provisioner, infra.ProviderConfig{ Name: cfg.providerName, @@ -126,6 +126,7 @@ var cfg struct { kubeconfigFile string namespace string dataVolumeMode string + networkBinding string insecureSkipVerify bool } @@ -152,5 +153,6 @@ func init() { rootCmd.Flags().StringVar(&cfg.kubeconfigFile, "kubeconfig-file", "~/.kube/config", "Kubeconfig file to use to connect to the cluster where KubeVirt is running") rootCmd.Flags().StringVar(&cfg.namespace, "namespace", "default", "Kubernetes namespace to use for the resources created by the provider") rootCmd.Flags().StringVar(&cfg.dataVolumeMode, "data-volume-mode", "", "DataVolume PVC type to use (Block|Filesystem)") + rootCmd.Flags().StringVar(&cfg.networkBinding, "kubevirt-network-binding", "bridge", "Which network binding to use for VM primary interface (bridge|passt)") rootCmd.Flags().BoolVar(&cfg.insecureSkipVerify, "insecure-skip-verify", false, "ignores untrusted certs on Omni side") } diff --git a/internal/pkg/provider/provision.go b/internal/pkg/provider/provision.go index 4072d9d..542bad6 100644 --- a/internal/pkg/provider/provision.go +++ b/internal/pkg/provider/provision.go @@ -33,17 +33,28 @@ import ( // Provisioner implements Talos emulator infra provider. type Provisioner struct { - k8sClient client.Client - namespace string - volumeMode v1.PersistentVolumeMode + k8sClient client.Client + namespace string + volumeMode v1.PersistentVolumeMode + networkInterface kvv1.Interface } // NewProvisioner creates a new provisioner. -func NewProvisioner(k8sClient client.Client, namespace, volumeMode string) *Provisioner { +func NewProvisioner(k8sClient client.Client, namespace, volumeMode, networkBinding string) *Provisioner { + networkInterface := *kvv1.DefaultBridgeNetworkInterface() + if networkBinding == "passt" { + networkInterface = kvv1.Interface{ + Name: networkInterface.Name, + Binding: &kvv1.PluginBinding{ + Name: "passt", + }, + } + } return &Provisioner{ - k8sClient: k8sClient, - namespace: namespace, - volumeMode: v1.PersistentVolumeMode(volumeMode), + k8sClient: k8sClient, + namespace: namespace, + volumeMode: v1.PersistentVolumeMode(volumeMode), + networkInterface: networkInterface, } } @@ -217,6 +228,10 @@ func (p *Provisioner) ProvisionSteps() []provision.Step[*resources.Machine] { vm.Spec.Template.Spec.Domain.Resources.Requests[v1.ResourceMemory] = *resource.NewQuantity(int64(data.Memory)*1024*1024, resource.DecimalSI) + vm.Spec.Template.Spec.Networks = []kvv1.Network{ + *kvv1.DefaultPodNetwork(), + } + vm.Spec.Template.Spec.Domain.Devices = kvv1.Devices{ Disks: []kvv1.Disk{ { @@ -229,6 +244,9 @@ func (p *Provisioner) ProvisionSteps() []provision.Step[*resources.Machine] { }, }, }, + Interfaces: []kvv1.Interface{ + p.networkInterface, + }, } vm.Spec.Template.Spec.Volumes = []kvv1.Volume{