-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net binding plugin: Add binding sidecars to virt-launcher
Signed-off-by: Alona Paz <alkaplan@redhat.com>
- Loading branch information
1 parent
968fcc0
commit 274224f
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package services | ||
|
||
import ( | ||
"fmt" | ||
|
||
v1 "kubevirt.io/api/core/v1" | ||
|
||
"kubevirt.io/kubevirt/pkg/hooks" | ||
) | ||
|
||
func BindingPluginSidecarList(vmi *v1.VirtualMachineInstance, config *v1.KubeVirtConfiguration) (hooks.HookSidecarList, error) { | ||
var pluginSidecars hooks.HookSidecarList | ||
for _, iface := range vmi.Spec.Domain.Devices.Interfaces { | ||
if iface.Binding != nil { | ||
var exist bool | ||
var pluginInfo v1.InterfaceBindingPlugin | ||
if config.NetworkConfiguration != nil && config.NetworkConfiguration.Binding != nil { | ||
pluginInfo, exist = config.NetworkConfiguration.Binding[iface.Binding.Name] | ||
} | ||
|
||
if !exist { | ||
return nil, fmt.Errorf("couldn't find configuration for bindining: %s", iface.Binding.Name) | ||
} | ||
if pluginInfo.SidecarImage != "" { | ||
pluginSidecars = append(pluginSidecars, hooks.HookSidecar{Image: pluginInfo.SidecarImage}) | ||
} | ||
} | ||
} | ||
return pluginSidecars, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package services_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
v1 "kubevirt.io/api/core/v1" | ||
|
||
"kubevirt.io/kubevirt/pkg/hooks" | ||
"kubevirt.io/kubevirt/pkg/virt-controller/services" | ||
"kubevirt.io/kubevirt/tests/libvmi" | ||
) | ||
|
||
var _ = Describe("Network Binding", func() { | ||
const ( | ||
testNetworkName1 = "net1" | ||
testBindingName1 = "binding1" | ||
testSidecarImage1 = "image1" | ||
testNetworkName2 = "net2" | ||
testBindingName2 = "binding2" | ||
testSidecarImage2 = "image2" | ||
testNetworkName3 = "net1" | ||
|
||
shouldSucceed = true | ||
) | ||
|
||
BeforeEach(func() { | ||
|
||
}) | ||
Context("binding plugin sidecar list", func() { | ||
DescribeTable("should create the correct sidecars", func(vmi *v1.VirtualMachineInstance, bindings map[string]v1.InterfaceBindingPlugin, expectedSidecars hooks.HookSidecarList, shouldSucceed bool) { | ||
config := &v1.KubeVirtConfiguration{ | ||
NetworkConfiguration: &v1.NetworkConfiguration{ | ||
Binding: bindings, | ||
}, | ||
} | ||
sidecars, err := services.BindingPluginSidecarList(vmi, config) | ||
if shouldSucceed { | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(sidecars).To(Equal(expectedSidecars)) | ||
} else { | ||
Expect(err).To(HaveOccurred()) | ||
} | ||
}, | ||
Entry("VMI has binding plugin but config doesn't exist", | ||
libvmi.New(libvmi.WithInterface(v1.Interface{Name: testNetworkName1, Binding: &v1.PluggedBinding{Name: testBindingName1}}), | ||
libvmi.WithNetwork(&v1.Network{Name: testNetworkName1}), | ||
), | ||
nil, | ||
nil, | ||
!shouldSucceed), | ||
Entry("VMI has binding plugin but config image is empty", | ||
libvmi.New(libvmi.WithInterface(v1.Interface{Name: testNetworkName1, Binding: &v1.PluggedBinding{Name: testBindingName1}}), | ||
libvmi.WithNetwork(&v1.Network{Name: testNetworkName1}), | ||
), | ||
map[string]v1.InterfaceBindingPlugin{testBindingName1: {}}, | ||
nil, | ||
shouldSucceed), | ||
Entry("VMI has binding plugin and config image", | ||
libvmi.New(libvmi.WithInterface(v1.Interface{Name: testNetworkName1, Binding: &v1.PluggedBinding{Name: testBindingName1}}), | ||
libvmi.WithNetwork(&v1.Network{Name: testNetworkName1}), | ||
), | ||
map[string]v1.InterfaceBindingPlugin{testBindingName1: {SidecarImage: testSidecarImage1}}, | ||
hooks.HookSidecarList{{Image: testSidecarImage1}}, | ||
shouldSucceed), | ||
Entry("VMI has multiple plugin bindings", | ||
libvmi.New(libvmi.WithInterface(v1.Interface{Name: testNetworkName1, Binding: &v1.PluggedBinding{Name: testBindingName1}}), | ||
libvmi.WithNetwork(&v1.Network{Name: testNetworkName1}), | ||
libvmi.WithInterface(v1.Interface{Name: testNetworkName2, Binding: &v1.PluggedBinding{Name: testBindingName2}}), | ||
libvmi.WithNetwork(&v1.Network{Name: testNetworkName2}), | ||
libvmi.WithInterface(v1.Interface{Name: testNetworkName3, InterfaceBindingMethod: v1.InterfaceBindingMethod{SRIOV: &v1.InterfaceSRIOV{}}}), | ||
libvmi.WithNetwork(&v1.Network{Name: testNetworkName3}), | ||
), | ||
map[string]v1.InterfaceBindingPlugin{testBindingName1: {SidecarImage: testSidecarImage1}, testBindingName2: {SidecarImage: testSidecarImage2}}, | ||
hooks.HookSidecarList{{Image: testSidecarImage1}, {Image: testSidecarImage2}}, | ||
shouldSucceed), | ||
Entry("VMI has no plugin bindings", | ||
libvmi.New(libvmi.WithInterface(v1.Interface{Name: testNetworkName1, InterfaceBindingMethod: v1.InterfaceBindingMethod{SRIOV: &v1.InterfaceSRIOV{}}}), | ||
libvmi.WithNetwork(&v1.Network{Name: testNetworkName1}), | ||
), | ||
nil, | ||
nil, | ||
shouldSucceed), | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters