-
Notifications
You must be signed in to change notification settings - Fork 789
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
bridge: Extract some netlink operations code to file #998
base: main
Are you sure you want to change the base?
Conversation
2f3559d
to
34e5f3e
Compare
/cc @EdDev @AlonaKaplan |
pkg/link/opstate.go
Outdated
} | ||
|
||
if idx == len(retries)-1 { | ||
return nil, fmt.Errorf("timeout waiting for %q state up", linkName) |
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.
nit: please say what state the link is currently in.
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.
Done
pkg/link/opstate.go
Outdated
func SetUp(linkName string) error { | ||
link, err := netlink.LinkByName(linkName) | ||
if err != nil { | ||
return fmt.Errorf("failed to retrieve link: %v", err) |
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.
nit: please use %w
to wrap errors everywhere.
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.
I didn't saw error being unwrapped in the bridge plugin code, also we didnt wrapped them before this change 🙂
Why is it necessary to wrap them 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.
because all of this code was written before %w
was a thing :-).
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.
Done
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.
A few small nits, then this looks good!
34e5f3e
to
ad9910e
Compare
@squeed thanks for the review 🙂 , please take another look. |
|
||
link, err = netlink.LinkByName(linkName) | ||
if err != nil { | ||
return nil, err |
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.
let's be consistent and return here fmt.Errorf("failed to retrieve link: %v", err) as in SetUp
if err := netns.Do(func(_ ns.NetNS) error { | ||
link, err := netlink.LinkByName(args.IfName) |
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.
Why do you want a function for this? I understand the one for retries which includes some logic with the for loop but this is simple and not used anywhere else.
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.
My intent was to improve readability, even though there is no much of logic its less code to read, and may reduce some cognitive load (I dont need to know we need to fetch the link in order to bring it down).
Also, with #997 changes, it makes the code read better:
...
else if !disableContIface {
link.SetUp(ifaceName)
}
...
WDYT?
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.
no, I think this is simple enough. If you want to improve readability, then abstract all the logic inside if layer3 branch, then in your other pr, you can do
if !disableContIface {
if layer {
layer3func()
} else {
thiscode
}
WaitOperStateUp()
}
This is a small refactoring around netlink operations logic. Setting link state up and waiting for link oper state code is moved to link package. Signed-off-by: Or Mergi <[email protected]>
ad9910e
to
4720e51
Compare
This is a small refactoring around netlink operations logic.
Setting link state up and waiting for link oper state code is moved to link package.