-
Notifications
You must be signed in to change notification settings - Fork 128
networks: Add Owner annotation to NetAttachDefs #897
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
networks: Add Owner annotation to NetAttachDefs #897
Conversation
|
Thanks for your PR,
To skip the vendors CIs, Maintainers can use one of:
|
e17f485 to
1a0d77d
Compare
Pull Request Test Coverage Report for Build 17434124856Details
💛 - Coveralls |
1a0d77d to
25d4188
Compare
| instance.SetFinalizers(append(instanceFinalizers, sriovnetworkv1.NETATTDEFFINALIZERNAME)) | ||
| if err := r.Update(ctx, instance); err != nil { | ||
| return err | ||
| obj, namespace, name, err := sriovnetworkv1.StringToOwnerRef(owner) |
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.
should we limit the cleanup to specific object kind ? according to the object returned in the controller.GetObject() ?
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.
good idea. The problem is that I didn't find a nice way to check that two pointers have the same underlying type.
The only one I found is
func isType(a, b interface{}) bool {
return fmt.Sprintf("%T", a) == fmt.Sprintf("%T", b)
}
https://stackoverflow.com/questions/34820469/can-i-compare-variable-types-with-type-in-golang
which is not really nice :(
df7f95b to
525a0e4
Compare
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.
Pull Request Overview
This PR implements owner annotation functionality for NetworkAttachmentDefinitions to prevent conflicts when network objects exist in different namespaces. The change replaces the previous finalizer-based ownership approach with an annotation-based system that can work across namespace boundaries.
- Adds owner annotation to NetworkAttachmentDefinitions to track ownership relationships
- Implements garbage collection for orphaned NetworkAttachmentDefinitions
- Removes finalizer-based ownership system and migrates existing resources
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/consts/constants.go | Adds new owner annotation constant |
| controllers/suite_test.go | Updates test setup to skip name validation |
| controllers/sriovnetwork_controller_test.go | Adds test for finalizer removal during migration |
| controllers/generic_network_controller_test.go | Comprehensive tests for owner annotation functionality |
| controllers/generic_network_controller.go | Main controller logic changes for annotation-based ownership |
| bindata/manifests/cni-config/ | Updates templates to include owner annotations |
| api/v1/testdata/ | Updates test expectations for owner annotations |
| api/v1/helper_test.go | Improves test assertions and adds metadata |
| api/v1/helper.go | Implements owner reference string conversion functions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
525a0e4 to
915cb47
Compare
| // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers. | ||
| // Return and don't requeue | ||
| return reconcile.Result{}, nil | ||
| return reconcile.Result{}, r.garbageCollect(ctx) |
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.
for network CR instances that are in the operator namespace and point to a different namespace, are we relying on garbageCollect to clean them ?
i think the approach is problematic, since we are removing finalizers at L97, once the object is deleted, it will be removed from k8s API. if for some reason garbage collect fails and controller is restarted we will never retry.
then we rely on the next delete event to trigger garbage collect (which might take a while or never come ?)
i wonder if we should just keep finalizers on network CR instances or at least for those in the operator namespace then we explicitly delete what we need.
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.
sounds good. The first commit is about adding the owner-ref annotation and ensure 2 NetworkObject are not clashing on the same NetAttachDef. The second commit is about using the owner-ref annotation on the netattachdef instead of networkobject's finalizers, which I was a sort of bonus change.
I'm dropping the second commit to focus this PR on having the owner-ref annotation. We can discuss about dropping the finalizers later, if needed
NetworkattachmentDefiitions are usually created in namespaces that are different
than the Sriov{Ib,OVS}Networks, so the OwnerReference object field can't be
used to endorse the ownership reference.
Add a `sriovnetwork.openshift.io/owner` annotation to put on the NetAttachDef
to avoid multiple {Sriov,SriovIb,OVS}Network objects does not override changes.
Signed-off-by: Andrea Panattoni <[email protected]>
915cb47 to
f4307b0
Compare
SchSeba
left a comment
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.
LGTM
just a small nit, not blocking
api/v1/helper.go
Outdated
| return &OVSNetwork{}, namespace, name, nil | ||
| } | ||
|
|
||
| return nil, "", "", fmt.Errorf("unknown ownerRef groupKind %s", groupKind) |
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.
just nit we can use default here instead of the return right?
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.
this commit has been dropped:
#897 (comment)
it was about replacing finalizers delete flow with another based on garbage collecting. Now this PR only avoids multiple network objects overrides the same netAttachDef
|
|
||
| // Note for the future: the `foundOwner != ""` condition can be removed to make the operator not touching the NetworkAttachmentDefinition created | ||
| // by the user. | ||
| if foundOwner != "" && foundOwner != expectedOwner { |
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.
just a quick question if we have !equality.Semantic.DeepEqual(found.GetAnnotations(), netAttDef.GetAnnotations() below do we still need this validation here?
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.
yes, we do:
in case we have:
kind: NetworkAttachmentDefinition
metadata:
name: foo
namespace: foo-ns
annotations:
owner-ref: SriovNetwork/sriov-operator-ns/foo
spec:
<sriov cni config>
which comes from an SriovNetwork in the sriov-operator-ns namespace
when reconciling another network object:
kind: SriovNetwork
metadata:
name: foo
namespace: foo-ns
spec: ...
the generated net-attach-def has owner-ref: SriovNetwork/foo-ns/foo, which would make the condition !equality.Semantic.DeepEqual(found.GetAnnotations(), netAttDef.GetAnnotations() true and the netAttachDef woudl be overridden.
The policy, as of now, is the first reconciler networkobject is the owner
|
Great work! Merging this one |
depends on:
NetworkattachmentDefinitions are usually created in namespaces that are different
than the {Sriov,SriovIb,OVS}Networks, so the OwnerReference object field can't be
used to endorse the ownership reference.
Add a
sriovnetwork.openshift.io/ownerannotation to put on the NetAttachDefto avoid multiple {Sriov,SriovIb,OVS}Network objects does not override changes.