-
Notifications
You must be signed in to change notification settings - Fork 878
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
[IPVS] Implement GetServices(),GetService() and GetDestinations() #1770
Conversation
Please sign your commits following these rules: $ git clone -b "ipvs-getServices-dev" git@github.com:dhilipkumars/libnetwork.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -f Amending updates the existing PR. You DO NOT need to open a new one. |
1e5f110
to
a82c3f4
Compare
Signed-off-by: dhilipkumars <dhilip.kumar.s@huawei.com>
Hi @mavenugo
|
…ependency from ipvsadm Signed-off-by: dhilipkumars <dhilip.kumar.s@huawei.com>
246b5dd
to
ce0066b
Compare
ipvs/ipvs.go
Outdated
return i.doGetDestinationsCmd(s, nil) | ||
} | ||
|
||
//GetService gets details of a specific IPVS services, useful in updating statisics etc., |
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.
all the comments will start with a space
ipvs/ipvs.go
Outdated
return nil, err | ||
} | ||
|
||
//We are looking for exactly one service otherwise error out |
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.
same here
ipvs/netlink.go
Outdated
@@ -19,6 +19,8 @@ import ( | |||
"github.com/vishvananda/netns" | |||
) | |||
|
|||
//For Quick Reference IPVS related netlink message is described at the end of this file. |
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.
same here, remove extra line below
ipvs/netlink.go
Outdated
@@ -72,6 +74,7 @@ func setup() { | |||
|
|||
func fillService(s *Service) nl.NetlinkRequestData { | |||
cmdAttr := nl.NewRtAttr(ipvsCmdAttrService, nil) | |||
|
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 saw around other extra spaces, are they needed?
ipvs/netlink.go
Outdated
case syscall.AF_INET6: | ||
resIP = (net.IP)(ip[:16]) | ||
default: | ||
return resIP, fmt.Errorf("parseIP Error ip=%v", ip) |
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.
nil maybe is better?
ipvs/netlink.go
Outdated
return nil, err | ||
} | ||
if len(NetLinkAttrs) == 0 { | ||
return nil, fmt.Errorf("Error No valid net link message found while Parsing service record") |
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.
netlink
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.
spelling: netlink is with no space.
We are usually also starting the error messages with the lowercase so in this case:
fmt.Errorf("error no valid netlink message found while Parsing service record")
ipvs/netlink.go
Outdated
} | ||
|
||
//IPVS related netlink message format explained | ||
|
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.
Nice section below, even though this is the generic netlink data structure (looks like ipvs does not have a custom netlink message structure), it will be useful to have it here for other developers
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 if we could keep them it would be helpful for future developers, i spent a nice few hours to figure it out (as im new to netlink format)
Hi @fcrisciani , all the comments have been addressed PTAL. Please let us know if you have more comments. we will fix it ASAP. Thanks in Advance, we would love to help to get this PR merged ASAP. |
BTW, Thanks for the quick review |
ipvs/netlink.go
Outdated
return nil, err | ||
} | ||
if len(NetLinkAttrs) == 0 { | ||
return nil, fmt.Errorf("Error No valid netlink message found while Parsing service record") |
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.
fmt.Errorf("error no valid netlink message found while Parsing service record")
just posted another 2 minor comments, rest looks good to me |
@fcrisciani Thanks again PTAL. |
Signed-off-by: dhilipkumars <dhilip.kumar.s@huawei.com>
7da9af5
to
635b898
Compare
LGTM |
ipvs/netlink.go
Outdated
for _, msg := range msgs { | ||
srv, err := i.parseService(msg) | ||
if err != nil { | ||
return res, 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.
should this be return nil, err
ipvs/netlink.go
Outdated
@@ -217,6 +235,7 @@ done: | |||
if m.Header.Type == syscall.NLMSG_DONE { | |||
break 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.
white space
ipvs/netlink.go
Outdated
@@ -208,6 +225,7 @@ done: | |||
return nil, err | |||
} | |||
for _, m := range msgs { | |||
|
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.
white space
|
||
return | ||
if svc.Protocol == s.Protocol && svc.Address.String() == s.Address.String() && svc.Port == s.Port { | ||
svcFound = true |
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.
can't we just error/return here instead of additional switch statement below ?
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.
The tests sometimes expect the service to be present and sometimes expect the service to be absent. We error out based on that expectation. I dont think we can take that decision inside the loop? we have to loop all the elements to figure out the service is not available.
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 just that we could have avoided svcFound flag.
If the service was found {
if !checkPresent{
//error
}
//implicit else
return
}
//outside the loop
if checkPresent{
//error
}
ipvs/ipvs_test.go
Outdated
assert.Equal(t, protocol, parts[0]) | ||
assert.Equal(t, serviceAddress, parts[2]) | ||
assert.Equal(t, schedMethod, parts[3]) | ||
svcFound := false |
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.
better convention would be var svcFound bool
ipvs/ipvs_test.go
Outdated
|
||
realServers = append(realServers, o) | ||
for _, dst := range dstArray { | ||
if dst.Address.String() == d.Address.String() && dst.Port == d.Port && lookupFwMethod(dst.ConnectionFlags) == lookupFwMethod(d.ConnectionFlags) { |
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.
we can just use net.Equal(dst,d)
ipvs/ipvs_test.go
Outdated
continue | ||
} | ||
func checkDestination(t *testing.T, i *Handle, s *Service, d *Destination, checkPresent bool) { | ||
dstFound := false |
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.
var dstFound bool
Signed-off-by: dhilipkumars <dhilip.kumar.s@huawei.com>
@abhinandanpb PTAL. |
Thanks @dhilipkumars. LGTM. |
Thanks for the quik merge |
@dhilipkumars please squash your review fix commits from next time. |
Certainly. Thanks for being considerate this time. |
@mavenugo This is an Inital checkin to get the approach validated. If you are okay with this i will improve/add coverage for the package.
Also i though we could introduce a file utils.go in ipvs package and moave all the utility related funcs there? what do you think?