Skip to content

Conversation

@jjo
Copy link
Contributor

@jjo jjo commented Mar 21, 2018

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

  • updated vendor/ deps for

    • github.com/onsi/ginkgo
    • github.com/onsi/gomega
  • 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", ...)

@jjo jjo force-pushed the jjo-network_services_controller_test-wip branch from 78c0b77 to 360658e Compare March 22, 2018 04:52
@jjo jjo changed the title [WIP] added network_services_controller testing [jjo] added network_services_controller ginkgo testing Mar 22, 2018
@jjo
Copy link
Contributor Author

jjo commented Mar 22, 2018

@murali-reddy appreciate review, time permits.

@jjo jjo force-pushed the jjo-network_services_controller_test-wip branch 4 times, most recently from b3cf545 to 9d367d5 Compare March 27, 2018 00:18
@jjo
Copy link
Contributor Author

jjo commented Mar 27, 2018

@murali-reddy updated to include PR #355 + network_services_controller test case for it.

@jjo jjo force-pushed the jjo-network_services_controller_test-wip branch from 30ae3e7 to 408d0a2 Compare April 4, 2018 17:21
@jjo
Copy link
Contributor Author

jjo commented Apr 4, 2018

@murali-reddy: rebased against latest master.

@andrewsykim
Copy link
Contributor

@jjo really excited about IPVS tests! Would it be possible to put all the vendor changes into 1 commit?

jjo added a commit to jjo/kube-router that referenced this pull request Apr 7, 2018
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 )
@jjo
Copy link
Contributor Author

jjo commented Apr 7, 2018

really excited about IPVS tests! Would it be possible to put all the vendor changes into 1 commit?

@andrewsykim thanks for the feedback :), just did it:
reworked changes into just 2 commits, 2nd one with glide.yaml + vendor/ additions.

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

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?

Copy link
Contributor Author

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

Choose a reason for hiding this comment

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

Group std imports together

Copy link
Contributor Author

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 ;)) .

Copy link
Contributor

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.

Copy link
Contributor Author

@jjo jjo Apr 9, 2018

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

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?

Copy link
Contributor Author

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

@andrewsykim
Copy link
Contributor

@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).

@jjo
Copy link
Contributor Author

jjo commented Apr 8, 2018

@andrewsykim wrote: 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!

@andrewsykim
Copy link
Contributor

@jjo thanks! I'll review it again tomorrow, do you mind rebasing it seems there are commits from other PRs here (ed34187)

@jjo jjo force-pushed the jjo-network_services_controller_test-wip branch from 588b642 to 845e4f9 Compare April 9, 2018 10:13
@jjo
Copy link
Contributor Author

jjo commented Apr 9, 2018

@andrewsykim wrote: ... I'll review it again tomorrow, do you mind rebasing it seems there are commits from other PRs here

Thanks @andrewsykim!, rebased.

@andrewsykim
Copy link
Contributor

LGTM! cc @murali-reddy for a final review

@murali-reddy murali-reddy merged commit ed0dc39 into cloudnativelabs:master Apr 9, 2018
@murali-reddy
Copy link
Member

LGTM as well. Thanks @jjo for the contribution.

@jjo
Copy link
Contributor Author

jjo commented Apr 9, 2018

w00T!, thank you @andrewsykim @murali-reddy for the support and reviews :)

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.

3 participants