|
| 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