Skip to content

Commit

Permalink
feat: allow specifying network binding via flag to be able to
Browse files Browse the repository at this point in the history
accommodate Passt in IPv6 environments

Signed-off-by: Niklas Voss <[email protected]>
  • Loading branch information
trevex committed Nov 4, 2024
1 parent deb6fcc commit bca1091
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
4 changes: 3 additions & 1 deletion cmd/omni-infra-provider-kubevirt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -126,6 +126,7 @@ var cfg struct {
kubeconfigFile string
namespace string
dataVolumeMode string
networkBinding string
insecureSkipVerify bool
}

Expand All @@ -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")
}
32 changes: 25 additions & 7 deletions internal/pkg/provider/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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{
{
Expand All @@ -229,6 +244,9 @@ func (p *Provisioner) ProvisionSteps() []provision.Step[*resources.Machine] {
},
},
},
Interfaces: []kvv1.Interface{
p.networkInterface,
},
}

vm.Spec.Template.Spec.Volumes = []kvv1.Volume{
Expand Down

0 comments on commit bca1091

Please sign in to comment.