Skip to content

Commit 50d9dbd

Browse files
committed
network/kubevirt-ipam-controller: Add new net-attach-def resource
This resource does not belong to kubevirt-ipam-controller, but is currently piggy-backing this component in order to deploy the primary user-defined-network net-attach-def [0]. This net-attach-def is deployed on default namespace, as this way it will be available to all VMs that need to consume it. [0] https://kubevirt.io/user-guide/network/network_binding_plugins/#deployment Signed-off-by: Ram Lavi <[email protected]>
1 parent 624f9e9 commit 50d9dbd

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{ if .EnableNetworkAttachmentDefinition }}
2+
---
3+
apiVersion: "k8s.cni.cncf.io/v1"
4+
kind: NetworkAttachmentDefinition
5+
metadata:
6+
name: primary-user-defined-network
7+
namespace: default
8+
spec:
9+
config: '{
10+
"cniVersion": "1.0.0",
11+
"name": "primary-user-defined-network",
12+
"plugins": [
13+
{
14+
"type": "cni-passt-binding-plugin"
15+
}
16+
]
17+
}'
18+
{{ end }}

pkg/network/kubevirt_ipam_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func renderKubevirtIPAMController(conf *cnao.NetworkAddonsConfigSpec, manifestDi
4949
}
5050
data.Data["IsOpenshift"] = clusterInfo.OpenShift4
5151
data.Data["EnableSCC"] = clusterInfo.SCCAvailable
52+
data.Data["EnableNetworkAttachmentDefinition"] = clusterInfo.NetAttachDefAvailable
5253

5354
objs, err := render.RenderDir(filepath.Join(manifestDir, "kubevirt-ipam-controller"), &data)
5455
if err != nil {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package network
2+
3+
import (
4+
. "github.com/onsi/ginkgo/v2"
5+
. "github.com/onsi/gomega"
6+
7+
osv1 "github.com/openshift/api/operator/v1"
8+
v1 "k8s.io/api/core/v1"
9+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
10+
"k8s.io/apimachinery/pkg/runtime/schema"
11+
12+
cnao "github.com/kubevirt/cluster-network-addons-operator/pkg/apis/networkaddonsoperator/shared"
13+
)
14+
15+
var _ = Describe("Testing kubevirt ipam controller", func() {
16+
Context("Render KubevirtIpamController", func() {
17+
conf := &cnao.NetworkAddonsConfigSpec{ImagePullPolicy: v1.PullAlways, Multus: &cnao.Multus{}, KubevirtIpamController: &cnao.KubevirtIpamController{}, PlacementConfiguration: &cnao.PlacementConfiguration{Workloads: &cnao.Placement{}}}
18+
manifestDir := "../../data"
19+
openshiftNetworkConf := &osv1.Network{}
20+
clusterInfo := &ClusterInfo{SCCAvailable: true, OpenShift4: false}
21+
expectedGroupVersionKind := schema.GroupVersionKind{
22+
Group: "k8s.cni.cncf.io",
23+
Kind: "NetworkAttachmentDefinition",
24+
Version: "v1",
25+
}
26+
const expectedName = "primary-user-defined-network"
27+
28+
It("and NetAttachDefAvailable resource is available, should add the primary-udn network-attach-def obj", func() {
29+
clusterInfo.NetAttachDefAvailable = true
30+
objs, err := Render(conf, manifestDir, openshiftNetworkConf, clusterInfo)
31+
Expect(err).NotTo(HaveOccurred())
32+
Expect(objs).NotTo(BeEmpty())
33+
34+
Expect(objs).To(ContainElement(
35+
SatisfyAll(
36+
WithTransform(func(obj *unstructured.Unstructured) string {
37+
return obj.GetName()
38+
}, Equal(expectedName)),
39+
WithTransform(func(obj *unstructured.Unstructured) schema.GroupVersionKind {
40+
return obj.GetObjectKind().GroupVersionKind()
41+
}, Equal(expectedGroupVersionKind)),
42+
),
43+
))
44+
})
45+
It("and NetAttachDefAvailable resource is not available, should not add the primary-udn network-attach-def obj", func() {
46+
clusterInfo.NetAttachDefAvailable = false
47+
objs, err := Render(conf, manifestDir, openshiftNetworkConf, clusterInfo)
48+
Expect(err).NotTo(HaveOccurred())
49+
Expect(objs).NotTo(BeEmpty())
50+
51+
Expect(objs).ToNot(ContainElement(
52+
SatisfyAll(
53+
WithTransform(func(obj *unstructured.Unstructured) string {
54+
return obj.GetName()
55+
}, Equal(expectedName)),
56+
WithTransform(func(obj *unstructured.Unstructured) schema.GroupVersionKind {
57+
return obj.GetObjectKind().GroupVersionKind()
58+
}, Equal(expectedGroupVersionKind)),
59+
),
60+
))
61+
})
62+
})
63+
})

0 commit comments

Comments
 (0)