Skip to content

Commit 6301936

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. Note that for CI, KubevirtIpamController will not be able to deploy without Multus (that deploys the net-attach-def CRD) alongside it, or the net-attach-def deployment will fail, with error: `could not apply (k8s.cni.cncf.io/v1, Kind=NetworkAttachmentDefinition) default/primary-user-defined-network: could not retrieve existing (k8s.cni.cncf.io/v1, Kind=NetworkAttachmentDefinition) default/primary-user-defined-network: no matches for kind "NetworkAttachmentDefinition" in version "k8s.cni.cncf.io/v1"` [0] https://kubevirt.io/user-guide/network/network_binding_plugins/#deployment Signed-off-by: Ram Lavi <[email protected]>
1 parent 49ff436 commit 6301936

File tree

7 files changed

+101
-8
lines changed

7 files changed

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

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/go-git/go-git/v5 v5.11.0
1616
github.com/gobwas/glob v0.2.3
1717
github.com/google/go-github/v32 v32.1.0
18+
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.3.0
1819
github.com/kubevirt/monitoring/pkg/metrics/parser v0.0.0-20231024120544-6a3ba1a680b4
1920
github.com/machadovilaca/operator-observability v0.0.19-0.20240326121036-9f2e5a31675f
2021
github.com/onsi/ginkgo/v2 v2.11.0
@@ -142,7 +143,6 @@ require (
142143
github.com/josharian/intern v1.0.0 // indirect
143144
github.com/jpillora/backoff v1.0.0 // indirect
144145
github.com/json-iterator/go v1.1.12 // indirect
145-
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.3.0 // indirect
146146
github.com/kevinburke/rest v0.0.0-20210506044642-5611499aa33c // indirect
147147
github.com/kevinburke/ssh_config v1.2.0 // indirect
148148
github.com/klauspost/compress v1.16.0 // indirect

hack/components/bump-kubevirt-ipam-controller.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ echo 'Adjust kubevirt-ipam-controller to CNAO'
148148

149149
echo 'Copy manifests'
150150
shopt -s extglob
151-
rm -rf data/kubevirt-ipam-controller/!(002-rbac.yaml)
151+
rm -rf data/kubevirt-ipam-controller/!(002-rbac.yaml|004-primary-udn-networkattachdef.yaml)
152152

153153
# CRD
154154
crd_manifest="https://raw.githubusercontent.com/k8snetworkplumbingwg/ipamclaims/${IPAMCLAIMS_CRD_VERSION}/artifacts/k8s.cni.cncf.io_ipamclaims.yaml"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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{}
21+
expectedGroupVersionKind := schema.GroupVersionKind{
22+
Group: "k8s.cni.cncf.io",
23+
Version: "v1",
24+
Kind: "NetworkAttachmentDefinition",
25+
}
26+
const expectedName = "primary-user-defined-network"
27+
28+
It("should add the primary-udn network-attach-def obj", func() {
29+
objs, err := Render(conf, manifestDir, openshiftNetworkConf, clusterInfo)
30+
Expect(err).NotTo(HaveOccurred())
31+
Expect(objs).NotTo(BeEmpty())
32+
33+
Expect(objs).To(ContainElement(
34+
SatisfyAll(
35+
WithTransform(func(obj *unstructured.Unstructured) string {
36+
return obj.GetName()
37+
}, Equal(expectedName)),
38+
WithTransform(func(obj *unstructured.Unstructured) schema.GroupVersionKind {
39+
return obj.GetObjectKind().GroupVersionKind()
40+
}, Equal(expectedGroupVersionKind)),
41+
),
42+
))
43+
})
44+
})
45+
})

test/check/check.go

+29
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
. "github.com/onsi/gomega"
1414

1515
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
16+
k8snetworkplumbingwgv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
1617
testenv "github.com/kubevirt/cluster-network-addons-operator/test/env"
1718
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
1819
securityapi "github.com/openshift/origin/pkg/security/apis/security"
@@ -346,6 +347,10 @@ func checkForComponent(component *Component) error {
346347
errsAppend(checkForPrometheusRule(component.PrometheusRule))
347348
}
348349

350+
if component.NetworkAttachmentDefinition != "" {
351+
errsAppend(checkForNetworkAttachmentDefinition(component.NetworkAttachmentDefinition))
352+
}
353+
349354
return errsToErr(errs)
350355
}
351356

@@ -389,6 +394,10 @@ func checkForComponentRemoval(component *Component) error {
389394
errsAppend(checkForPrometheusRuleRemoval(component.PrometheusRule))
390395
}
391396

397+
if component.NetworkAttachmentDefinition != "" {
398+
errsAppend(checkForNetworkAttachmentDefinitionRemoval(component.NetworkAttachmentDefinition))
399+
}
400+
392401
return errsToErr(errs)
393402
}
394403

@@ -649,6 +658,21 @@ func checkForPrometheusRule(name string) error {
649658
return nil
650659
}
651660

661+
func checkForNetworkAttachmentDefinition(name string) error {
662+
networkAttachmentDefinition := k8snetworkplumbingwgv1.NetworkAttachmentDefinition{}
663+
err := testenv.Client.Get(context.Background(), types.NamespacedName{Name: name, Namespace: corev1.NamespaceDefault}, &networkAttachmentDefinition)
664+
if err != nil {
665+
return err
666+
}
667+
668+
err = checkRelationshipLabels(networkAttachmentDefinition.GetLabels(), "NetworkAttachmentDefinition", name)
669+
if err != nil {
670+
return err
671+
}
672+
673+
return nil
674+
}
675+
652676
func checkRelationshipLabels(labels map[string]string, kind, name string) error {
653677
expectedValues := map[string]string{
654678
names.COMPONENT_LABEL_KEY: names.COMPONENT_LABEL_DEFAULT_VALUE,
@@ -708,6 +732,11 @@ func checkForPrometheusRuleRemoval(name string) error {
708732
return isNotFound("PrometheusRule", name, err)
709733
}
710734

735+
func checkForNetworkAttachmentDefinitionRemoval(name string) error {
736+
err := testenv.Client.Get(context.Background(), types.NamespacedName{Name: name, Namespace: corev1.NamespaceDefault}, &k8snetworkplumbingwgv1.NetworkAttachmentDefinition{})
737+
return isNotFound("NetworkAttachmentDefinition", name, err)
738+
}
739+
711740
func getMonitoringEndpoint() (*corev1.Endpoints, error) {
712741
By("Finding CNAO prometheus endpoint")
713742
endpoint := &corev1.Endpoints{}

test/check/components.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type Component struct {
2020
Service string
2121
ServiceMonitor string
2222
PrometheusRule string
23+
NetworkAttachmentDefinition string
2324
}
2425

2526
var (
@@ -87,11 +88,12 @@ var (
8788
Deployments: []string{"secondary-dns"},
8889
}
8990
KubevirtIpamController = Component{
90-
ComponentName: "KubevirtIpamController",
91-
ClusterRole: "kubevirt-ipam-controller-manager-role",
92-
ClusterRoleBinding: "kubevirt-ipam-controller-manager-rolebinding",
93-
Deployments: []string{"kubevirt-ipam-controller-manager"},
94-
DaemonSets: []string{"passt-binding-cni"},
91+
ComponentName: "KubevirtIpamController",
92+
ClusterRole: "kubevirt-ipam-controller-manager-role",
93+
ClusterRoleBinding: "kubevirt-ipam-controller-manager-rolebinding",
94+
Deployments: []string{"kubevirt-ipam-controller-manager"},
95+
DaemonSets: []string{"passt-binding-cni"},
96+
NetworkAttachmentDefinition: "primary-user-defined-network",
9597
}
9698
AllComponents = []Component{
9799
KubeMacPoolComponent,

test/e2e/workflow/deployment_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ var _ = Describe("NetworkAddonsConfig", func() {
9191
Entry(
9292
KubevirtIpamController.ComponentName,
9393
cnao.NetworkAddonsConfigSpec{
94+
Multus: &cnao.Multus{},
9495
KubevirtIpamController: &cnao.KubevirtIpamController{},
9596
},
96-
[]Component{KubevirtIpamController},
97+
[]Component{MultusComponent, KubevirtIpamController},
9798
),
9899
)
99100
It("should deploy prometheus if NetworkAddonsConfigSpec is not empty", func() {

0 commit comments

Comments
 (0)