-
Notifications
You must be signed in to change notification settings - Fork 485
[jjo] added network_services_controller ginkgo testing #348
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
[jjo] added network_services_controller ginkgo testing #348
Conversation
78c0b77 to
360658e
Compare
|
@murali-reddy appreciate review, time permits. |
b3cf545 to
9d367d5
Compare
|
@murali-reddy updated to include PR #355 + network_services_controller test case for it. |
30ae3e7 to
408d0a2
Compare
|
@murali-reddy: rebased against latest master. |
|
@jjo really excited about IPVS tests! Would it be possible to put all the vendor changes into 1 commit? |
FYI no new functionality, but just golang interface hooks,
to be able to do BDD network_services_controller testing.
* created a shim/mostly-nil LinuxNetworking go interface,
(to be able to replace it with mocks for testing)
hooked all linux networking subsys calls thru it
`@reviewer`: note that `network_services_controller.go`
modifications to existing code are indeed e.g.
replacing:
~~~
ipvsClusterVipSvc, err := ipvsAddService(...)
~~~
by:
~~~
ipvsClusterVipSvc, err := nsc.ln.ipvsAddService(...)
~~~
* added `network_services_controller_moq.go` autogenerated
with `moq`
* using `ginkgo`, created `network_services_controller_test.go`
and other autogenerated supporting files
* added `network_services_controller_test.go` testing for:
- Context("service no endpoints with externalIPs", ...)
- Context("service no endpoints with loadbalancer IPs with annotation", ...)
- Context("service no endpoints with loadbalancer IPs without annotation", ...)
- Context("service no endpoints with loadbalancer without IPs", ...)
- Context("node has endpoints for service", ...)
* updated `vendor/` deps for
- github.com/onsi/ginkgo
- github.com/onsi/gomega
( in separated, next commit )
@andrewsykim thanks for the feedback :), just did it: |
| vip := &netlink.Addr{IPNet: &net.IPNet{IP: svc.clusterIP, Mask: net.IPv4Mask(255, 255, 255, 255)}, Scope: syscall.RT_SCOPE_LINK} | ||
| err := netlink.AddrAdd(dummyVipInterface, vip) | ||
| if err != nil && err.Error() != IFACE_HAS_ADDR { | ||
| glog.Errorf("Failed to assign cluster ip %s to dummy interface %s", svc.clusterIP.String(), err.Error()) |
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.
glog.Errorf line was removed, was that on purpose?
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.
Note that 4 lines construct (i.e. ipAddrAdd() + error check + glog ) was moved
to func (ln *linuxNetworking) ipAddrAdd(iface netlink.Link, ip string) error
at network_services_controller.go:102 interface method
(ditto ipAddrDel()), to de-dup it from the ~3 places it was previously present.
FWIW if you check linuxNetworking object methods there, above two
are the only ones "reworked" a bit (other ones being just stubbed thru
LinuxNetworking interface).
| package controllers | ||
|
|
||
| import ( | ||
| "fmt" |
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.
Group std imports together
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.
go fmt is sorting them that way (and there's a check at Makefile I
want to obey ;)) .
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.
gofmt doesn't account for how imports are grouped so gofmt still passes if you group stdlib separately, example: https://github.com/cloudnativelabs/kube-router/blob/master/app/controllers/network_routes_controller.go#L4-L15. The grouping is just good practice since it's easier to find packages that way.
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.
Gotcha, done.
| "time" | ||
| ) | ||
|
|
||
| type LinuxNetworkingMocker interface { |
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 seems like a duplicate of LinuxNetworking can we just use that?
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 catch, done ( fwiw I had slightly preferred explicitly having there
the *Mock() methods as a way to document~ish what subset has
been mocked).
|
@jjo PR looks good, just had some minor comments. It would be great if you can document how the mock code was generated (ideally a make command). |
Good point -- added to Makefile w/some docs about it. @andrewsykim PTAL, thanks! |
…only these in vendor/
588b642 to
845e4f9
Compare
Thanks @andrewsykim!, rebased. |
|
LGTM! cc @murali-reddy for a final review |
|
LGTM as well. Thanks @jjo for the contribution. |
|
w00T!, thank you @andrewsykim @murali-reddy for the support and reviews :) |
FYI no new functionality, but just golang interface hooks,
to be able to do BDD network_services_controller testing.
created a shim/mostly-nil LinuxNetworking go interface,
(to be able to replace it with mocks for testing)
hooked all linux networking subsys calls thru it
@reviewer: note thatnetwork_services_controller.gomodifications to existing code are indeed e.g.
replacing:
by:
added
network_services_controller_moq.goautogeneratedwith
moqusing
ginkgo, creatednetwork_services_controller_test.goand other autogenerated supporting files
updated
vendor/deps foradded
network_services_controller_test.gotesting for: