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

[IPVS] Implement GetServices(),GetService() and GetDestinations() #1770

Merged
merged 4 commits into from
May 25, 2017

Conversation

dhilipkumars
Copy link
Contributor

@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?

@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ 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.

Signed-off-by: dhilipkumars <dhilip.kumar.s@huawei.com>
@dhilipkumars
Copy link
Contributor Author

dhilipkumars commented May 20, 2017

Hi @mavenugo
This PR has the following

  1. Implements GetServices(), GetDestinations(*Services) and GetService(*Service)
  2. Has tests for all the new code written (the coverage is maintained 80%)
  3. Uses the newer APIs in the UT and hence removes the dependency from ipvsadm command.

@dhilipkumars dhilipkumars changed the title [IPVS] Initial Checkin GetServices and GetDestinations [IPVS] Implement GetServices(),GetService() and GetDestinations() May 21, 2017
…ependency from ipvsadm

Signed-off-by: dhilipkumars <dhilip.kumar.s@huawei.com>
ipvs/ipvs.go Outdated
return i.doGetDestinationsCmd(s, nil)
}

//GetService gets details of a specific IPVS services, useful in updating statisics etc.,

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

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.

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)

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)

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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

netlink

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

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

Copy link
Contributor Author

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)

@dhilipkumars
Copy link
Contributor Author

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.

@dhilipkumars
Copy link
Contributor Author

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")

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")

@fcrisciani
Copy link

just posted another 2 minor comments, rest looks good to me

@dhilipkumars
Copy link
Contributor Author

@fcrisciani Thanks again PTAL.

Signed-off-by: dhilipkumars <dhilip.kumar.s@huawei.com>
@fcrisciani
Copy link

LGTM

ipvs/netlink.go Outdated
for _, msg := range msgs {
srv, err := i.parseService(msg)
if err != nil {
return res, err
Copy link
Contributor

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
}

Copy link
Contributor

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 {

Copy link
Contributor

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
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor

@abhi abhi May 25, 2017

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
}

assert.Equal(t, protocol, parts[0])
assert.Equal(t, serviceAddress, parts[2])
assert.Equal(t, schedMethod, parts[3])
svcFound := false
Copy link
Contributor

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


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) {
Copy link
Contributor

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)

continue
}
func checkDestination(t *testing.T, i *Handle, s *Service, d *Destination, checkPresent bool) {
dstFound := false
Copy link
Contributor

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>
@dhilipkumars
Copy link
Contributor Author

@abhinandanpb PTAL.

@mavenugo
Copy link
Contributor

Thanks @dhilipkumars. LGTM.

@mavenugo mavenugo merged commit 6a0dfa1 into moby:master May 25, 2017
@dhilipkumars
Copy link
Contributor Author

Thanks for the quik merge

@abhi
Copy link
Contributor

abhi commented May 25, 2017

@dhilipkumars please squash your review fix commits from next time.

@dhilipkumars
Copy link
Contributor Author

Certainly. Thanks for being considerate this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants