Skip to content
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

Preserve user defined annotations on SriovNetworks #775

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions controllers/generic_network_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars"
)

Expand Down Expand Up @@ -168,9 +169,9 @@ func (r *genericNetworkReconciler) Reconcile(ctx context.Context, req ctrl.Reque
reqLogger.Error(err, "Couldn't create NetworkAttachmentDefinition CR", "Namespace", netAttDef.Namespace, "Name", netAttDef.Name)
return reconcile.Result{}, err
}
anno := map[string]string{sriovnetworkv1.LASTNETWORKNAMESPACE: netAttDef.Namespace}
instance.SetAnnotations(anno)
if err := r.Update(ctx, instance); err != nil {

err = utils.AnnotateObject(ctx, instance, sriovnetworkv1.LASTNETWORKNAMESPACE, netAttDef.Namespace, r.Client)
if err != nil {
return reconcile.Result{}, err
}
} else {
Expand Down
28 changes: 28 additions & 0 deletions controllers/sriovnetwork_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,34 @@ var _ = Describe("SriovNetwork Controller", Ordered, func() {
})
})

It("should preserve user defined annotations", func() {
cr := sriovnetworkv1.SriovNetwork{
ObjectMeta: metav1.ObjectMeta{
Name: "test-annotations",
Namespace: testNamespace,
Annotations: map[string]string{"foo": "bar"},
},
Spec: sriovnetworkv1.SriovNetworkSpec{
NetworkNamespace: "default",
},
}

err := k8sClient.Create(ctx, &cr)
Expect(err).NotTo(HaveOccurred())
DeferCleanup(k8sClient.Delete, ctx, &cr)

Eventually(func(g Gomega) {
network := &sriovnetworkv1.SriovNetwork{}
err = k8sClient.Get(ctx, types.NamespacedName{Name: cr.GetName(), Namespace: testNamespace}, network)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(network.Annotations).To(HaveKeyWithValue("foo", "bar"))
g.Expect(network.Annotations).To(HaveKeyWithValue("operator.sriovnetwork.openshift.io/last-network-namespace", "default"))
}).
WithPolling(100 * time.Millisecond).
WithTimeout(5 * time.Second).
MustPassRepeatedly(10).
Should(Succeed())
})
})
})

Expand Down
Loading