-
Notifications
You must be signed in to change notification settings - Fork 128
Support namespaced {Sriov,SriovIB,OVS}Networks #894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,10 @@ import ( | |
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/client-go/util/retry" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| dynclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
|
|
@@ -342,6 +344,89 @@ var _ = Describe("SriovNetwork Controller", Ordered, func() { | |
| MustPassRepeatedly(10). | ||
| Should(Succeed()) | ||
| }) | ||
|
|
||
| Context("When the SriovNetwork namespace is not equal to the operator one", func() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a case where the user requests to create nad in a different ns than the current one ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added! |
||
| BeforeAll(func() { | ||
| nsBlue := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "ns-blue"}} | ||
| Expect(k8sClient.Create(context.Background(), nsBlue)).ToNot(HaveOccurred()) | ||
| }) | ||
|
|
||
| AfterEach(func() { | ||
| cleanNetworksInNamespace("ns-blue") | ||
| }) | ||
|
|
||
| It("should create the NetAttachDefinition in the same namespace", func() { | ||
| cr := sriovnetworkv1.SriovNetwork{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "sriovnet-blue", | ||
| Namespace: "ns-blue", | ||
| }, | ||
| Spec: sriovnetworkv1.SriovNetworkSpec{ | ||
| ResourceName: "resource_x", | ||
| }, | ||
| } | ||
|
|
||
| err := k8sClient.Create(ctx, &cr) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| netAttDef := &netattdefv1.NetworkAttachmentDefinition{} | ||
| err = util.WaitForNamespacedObject(netAttDef, k8sClient, "ns-blue", cr.GetName(), util.RetryInterval, util.Timeout) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| expectedOwnerReference := metav1.OwnerReference{ | ||
| Kind: "SriovNetwork", | ||
| APIVersion: sriovnetworkv1.GroupVersion.String(), | ||
| UID: cr.UID, | ||
| Name: cr.Name, | ||
| } | ||
| Expect(netAttDef.GetAnnotations()["k8s.v1.cni.cncf.io/resourceName"]).To(Equal("openshift.io/resource_x")) | ||
|
|
||
| Expect(netAttDef.ObjectMeta.OwnerReferences).To(ContainElement(expectedOwnerReference)) | ||
SchSeba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Patch the SriovNetwork | ||
| original := cr.DeepCopy() | ||
| cr.Spec.ResourceName = "resource_y" | ||
| err = k8sClient.Patch(ctx, &cr, dynclient.MergeFrom(original)) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| // Check that the OwnerReference persists | ||
| netAttDef = &netattdefv1.NetworkAttachmentDefinition{} | ||
|
|
||
| Eventually(func(g Gomega) { | ||
| netAttDef = &netattdefv1.NetworkAttachmentDefinition{} | ||
| g.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: cr.GetName(), Namespace: "ns-blue"}, netAttDef)).To(Succeed()) | ||
| g.Expect(netAttDef.GetAnnotations()["k8s.v1.cni.cncf.io/resourceName"]).To(Equal("openshift.io/resource_y")) | ||
| g.Expect(netAttDef.ObjectMeta.OwnerReferences).To(ContainElement(expectedOwnerReference)) | ||
| }).WithPolling(100 * time.Millisecond).WithTimeout(5 * time.Second).Should(Succeed()) | ||
|
|
||
| // Delete the SriovNetwork | ||
| err = k8sClient.Delete(ctx, &cr) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets wait for the underlying net-attach-def to be deleted ? |
||
| }) | ||
|
|
||
| It("should not create the NetAttachDefinition if the NetworkNamespace field is not empty", func() { | ||
| cr := sriovnetworkv1.SriovNetwork{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "sriovnet-blue", | ||
| Namespace: "ns-blue", | ||
| }, | ||
| Spec: sriovnetworkv1.SriovNetworkSpec{ | ||
| NetworkNamespace: "default", | ||
| ResourceName: "resource_x", | ||
| }, | ||
| } | ||
|
|
||
| err := k8sClient.Create(ctx, &cr) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| Consistently(func(g Gomega) { | ||
| netAttDef := &netattdefv1.NetworkAttachmentDefinition{} | ||
| err := k8sClient.Get(ctx, types.NamespacedName{Name: cr.GetName(), Namespace: "default"}, netAttDef) | ||
| g.Expect(err).To(HaveOccurred()) | ||
| g.Expect(errors.IsNotFound(err)).To(BeTrue()) | ||
| }).WithPolling(100 * time.Millisecond).WithTimeout(1 * time.Second).Should(Succeed()) | ||
| }) | ||
|
|
||
| }) | ||
| }) | ||
| }) | ||
|
|
||
|
|
@@ -390,3 +475,24 @@ func generateExpectedNetConfig(cr *sriovnetworkv1.SriovNetwork) string { | |
| } | ||
| return configStr | ||
| } | ||
|
|
||
| func cleanNetworksInNamespace(namespace string) { | ||
| ctx := context.Background() | ||
| EventuallyWithOffset(1, func(g Gomega) { | ||
| err := k8sClient.DeleteAllOf(ctx, &sriovnetworkv1.SriovNetwork{}, client.InNamespace(namespace)) | ||
| g.Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| k8sClient.DeleteAllOf(ctx, &netattdefv1.NetworkAttachmentDefinition{}, client.InNamespace(namespace)) | ||
| g.Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| sriovNetworks := &sriovnetworkv1.SriovNetworkList{} | ||
| err = k8sClient.List(ctx, sriovNetworks, client.InNamespace(namespace)) | ||
| g.Expect(err).NotTo(HaveOccurred()) | ||
| g.Expect(sriovNetworks.Items).To(BeEmpty()) | ||
|
|
||
| netAttachDefs := &netattdefv1.NetworkAttachmentDefinitionList{} | ||
| err = k8sClient.List(ctx, netAttachDefs, client.InNamespace(namespace)) | ||
| g.Expect(err).NotTo(HaveOccurred()) | ||
| g.Expect(netAttachDefs.Items).To(BeEmpty()) | ||
| }).WithPolling(100 * time.Millisecond).WithTimeout(10 * time.Second).Should(Succeed()) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to add error field into
*NetworkStatusobjects?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good idea, but I would discuss it after
Maybe the conditions on CRDs are enough. What do you think?