Skip to content

Commit

Permalink
feat: configure network binding through provider data instead.
Browse files Browse the repository at this point in the history
Signed-off-by: Niklas Voss <[email protected]>
  • Loading branch information
trevex committed Nov 11, 2024
1 parent 2f81c92 commit 4a9e6c6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
4 changes: 4 additions & 0 deletions cmd/omni-infra-provider-kubevirt/data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"type": "integer",
"minimum": 5,
"description": "In GB"
},
"network_binding": {
"enum": ["bridge", "passt"],
"default": "bridge"
}
},
"required": [
Expand Down
4 changes: 1 addition & 3 deletions 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, cfg.networkBinding)
provisioner := provider.NewProvisioner(k8sClient, cfg.namespace, cfg.dataVolumeMode)

ip, err := infra.NewProvider(meta.ProviderID, provisioner, infra.ProviderConfig{
Name: cfg.providerName,
Expand Down Expand Up @@ -126,7 +126,6 @@ var cfg struct {
kubeconfigFile string
namespace string
dataVolumeMode string
networkBinding string
insecureSkipVerify bool
}

Expand All @@ -153,6 +152,5 @@ 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")
}
9 changes: 5 additions & 4 deletions internal/pkg/provider/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ package provider

// Data is the provider custom machine config.
type Data struct {
Architecture string `yaml:"architecture"`
Cores int `yaml:"cores"`
DiskSize int `yaml:"disk_size"`
Memory uint64 `yaml:"memory"`
Architecture string `yaml:"architecture"`
Cores int `yaml:"cores"`
DiskSize int `yaml:"disk_size"`
Memory uint64 `yaml:"memory"`
NetworkBinding string `yaml:"network_binding,omitempty"`
}
37 changes: 18 additions & 19 deletions internal/pkg/provider/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,17 @@ import (

// Provisioner implements Talos emulator infra provider.
type Provisioner struct {
k8sClient client.Client
namespace string
volumeMode v1.PersistentVolumeMode
networkInterface kvv1.Interface
k8sClient client.Client
namespace string
volumeMode v1.PersistentVolumeMode
}

// NewProvisioner creates a new 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",
},
}
}
func NewProvisioner(k8sClient client.Client, namespace, volumeMode string) *Provisioner {
return &Provisioner{
k8sClient: k8sClient,
namespace: namespace,
volumeMode: v1.PersistentVolumeMode(volumeMode),
networkInterface: networkInterface,
k8sClient: k8sClient,
namespace: namespace,
volumeMode: v1.PersistentVolumeMode(volumeMode),
}
}

Expand Down Expand Up @@ -232,6 +221,16 @@ func (p *Provisioner) ProvisionSteps() []provision.Step[*resources.Machine] {
*kvv1.DefaultPodNetwork(),
}

networkInterface := *kvv1.DefaultBridgeNetworkInterface()
if data.NetworkBinding == "passt" {
networkInterface = kvv1.Interface{
Name: networkInterface.Name,
Binding: &kvv1.PluginBinding{
Name: "passt",
},
}
}

vm.Spec.Template.Spec.Domain.Devices = kvv1.Devices{
Disks: []kvv1.Disk{
{
Expand All @@ -245,7 +244,7 @@ func (p *Provisioner) ProvisionSteps() []provision.Step[*resources.Machine] {
},
},
Interfaces: []kvv1.Interface{
p.networkInterface,
networkInterface,
},
}

Expand Down

0 comments on commit 4a9e6c6

Please sign in to comment.