Skip to content

Commit

Permalink
operands/kubevirt: Set Kubevirt CR new primary UDN Binding plugin
Browse files Browse the repository at this point in the history
The ability to register network bindings to Kubevirt VMs was proposed
[0] in order to allow Kubevirt VMs to connect to network bindings and
gain advanced user defined network capabilities.
The configuration is added to the kubevirt CR (kubevirt feature gate* +
configuring the binding parameters + adding the appropriate NAD).

This commit deploys and registers a primary user-defined-network (UDN)
binding to the kubevirt CR, so it could be used by kubevirt users.

* enabling the `NetworkBindingPlugins` kubevirt
feature-gate on kubevirt CR is not needed as it is already set by
default by HCO [1].

[0] kubevirt/community#280
[1]
kubevirt#2603

Signed-off-by: Ram Lavi <[email protected]>
  • Loading branch information
RamLavi committed Jul 31, 2024
1 parent 0ffa143 commit cf13462
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions controllers/operands/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"maps"
"os"
"path"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -45,6 +46,12 @@ const (
DefaultARM64EmulatedMachines = "virt*"
)

const (
// Needs to align with the NAD that will be deployed by CNAO
primaryUDNNetworkBindingName = "primaryUserDefinedNetwork"
primaryUDNNetworkBindingNamespace = "default"
)

var (
useKVMEmulation = false
)
Expand Down Expand Up @@ -421,6 +428,19 @@ func getKVConfig(hc *hcov1beta1.HyperConverged) (*kubevirtcorev1.KubeVirtConfigu

seccompConfig := getKVSeccompConfig()

if hc.Spec.FeatureGates.PrimaryUserDefinedNetworkBinding != nil && *hc.Spec.FeatureGates.PrimaryUserDefinedNetworkBinding {
if hc.Spec.NetworkBinding == nil {
hc.Spec.NetworkBinding = make(map[string]kubevirtcorev1.InterfaceBindingPlugin)
}

var sidecarImage string
var ok bool
if sidecarImage, ok = os.LookupEnv(hcoutil.PrimaryUDNImageEnvV); !ok {
return nil, errors.New("failed to get primary UDN image env Var")
}
hc.Spec.NetworkBinding[primaryUDNNetworkBindingName] = primaryUserDefinedNetworkBinding(sidecarImage)
}

config := &kubevirtcorev1.KubeVirtConfiguration{
DeveloperConfiguration: devConfig,
NetworkConfiguration: &kubevirtcorev1.NetworkConfiguration{
Expand Down Expand Up @@ -509,7 +529,6 @@ func getKVConfig(hc *hcov1beta1.HyperConverged) (*kubevirtcorev1.KubeVirtConfigu
if hc.Spec.ResourceRequirements != nil {
config.AutoCPULimitNamespaceLabelSelector = hc.Spec.ResourceRequirements.AutoCPULimitNamespaceLabelSelector.DeepCopy()
}

return config, nil
}

Expand Down Expand Up @@ -736,6 +755,21 @@ func getKVDevConfig(hc *hcov1beta1.HyperConverged) *kubevirtcorev1.DeveloperConf
return devConf
}

func primaryUserDefinedNetworkBinding(sidecarImage string) kubevirtcorev1.InterfaceBindingPlugin {
return kubevirtcorev1.InterfaceBindingPlugin{
NetworkAttachmentDefinition: path.Join(primaryUDNNetworkBindingNamespace, primaryUDNNetworkBindingName),
SidecarImage: sidecarImage,
Migration: &kubevirtcorev1.InterfaceBindingMigration{
Method: kubevirtcorev1.LinkRefresh,
},
ComputeResourceOverhead: &corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("500Mi"),
},
},
}
}

// Static for now, could be configured in the HCO CR in the future
func getKVSeccompConfig() *kubevirtcorev1.SeccompConfiguration {
return &kubevirtcorev1.SeccompConfiguration{
Expand Down Expand Up @@ -811,7 +845,6 @@ func getFeatureGateChecks(featureGates *hcov1beta1.HyperConvergedFeatureGates) [
if featureGates.AutoResourceLimits != nil && *featureGates.AutoResourceLimits {
fgs = append(fgs, kvAutoResourceLimits)
}

if featureGates.AlignCPUs != nil && *featureGates.AlignCPUs {
fgs = append(fgs, kvAlignCPUs)
}
Expand Down

0 comments on commit cf13462

Please sign in to comment.