From d052f0e1d0a69cd5233a375731c19f4f275fdd4b Mon Sep 17 00:00:00 2001 From: Inju Song Date: Wed, 24 Oct 2018 18:33:01 +0900 Subject: [PATCH 1/3] Add to set ip_vs_mh scheduler and flags Signed-off-by: Inju Song --- .../proxy/network_services_controller.go | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/pkg/controllers/proxy/network_services_controller.go b/pkg/controllers/proxy/network_services_controller.go index 047bbf5025..8a67be513c 100644 --- a/pkg/controllers/proxy/network_services_controller.go +++ b/pkg/controllers/proxy/network_services_controller.go @@ -44,12 +44,17 @@ const ( IFACE_HAS_ADDR = "file exists" IFACE_HAS_NO_ADDR = "cannot assign requested address" IPVS_SERVER_EXISTS = "file exists" + IPVS_MAGLEV_HASHING = "mh" + IPVS_SVC_F_SCHED1 = "flag-1" + IPVS_SVC_F_SCHED2 = "flag-2" + IPVS_SVC_F_SCHED3 = "flag-3" svcDSRAnnotation = "kube-router.io/service.dsr" svcSchedulerAnnotation = "kube-router.io/service.scheduler" svcHairpinAnnotation = "kube-router.io/service.hairpin" svcLocalAnnotation = "kube-router.io/service.local" svcSkipLbIpsAnnotation = "kube-router.io/service.skiplbips" + svcSchedFlagsAnnotation = "kube-router.io/service.schedflags" LeaderElectionRecordAnnotationKey = "control-plane.alpha.kubernetes.io/leader" ) @@ -234,6 +239,14 @@ type serviceInfo struct { externalIPs []string loadBalancerIPs []string local bool + flags schedFlags +} + +// IPVS scheduler flags +type schedFlags struct { + flag1 bool + flag2 bool + flag3 bool } // map of all services, with unique service id(namespace name, service name, port) as key @@ -1104,8 +1117,16 @@ func (nsc *NetworkServicesController) buildServicesInfo() serviceInfoMap { svcInfo.scheduler = ipvs.DestinationHashing } else if schedulingMethod == ipvs.SourceHashing { svcInfo.scheduler = ipvs.SourceHashing + } else if schedulingMethod == IPVS_MAGLEV_HASHING { + svcInfo.scheduler = IPVS_MAGLEV_HASHING } } + + flags, ok := svc.ObjectMeta.Annotations[svcSchedFlagsAnnotation] + if ok && svcInfo.scheduler == IPVS_MAGLEV_HASHING { + svcInfo.flags = parseSchedFlags(flags) + } + copy(svcInfo.externalIPs, svc.Spec.ExternalIPs) for _, lbIngress := range svc.Status.LoadBalancer.Ingress { if len(lbIngress.IP) > 0 { @@ -1127,6 +1148,32 @@ func (nsc *NetworkServicesController) buildServicesInfo() serviceInfoMap { return serviceMap } +func parseSchedFlags(value string) schedFlags { + var flag1, flag2, flag3 bool + + if len(value) < 1 { + return schedFlags{} + } + + flags := strings.Split(value, ",") + for flag := range flags { + switch strings.Trim(flag, " ") { + case IPVS_SVC_F_SCHED1: + flag1 = true + break + case IPVS_SVC_F_SCHED2: + flag2 = true + break + case IPVS_SVC_F_SCHED3: + flag3= true + break + default: + } + } + + return schedFlags{flag1, flag2, flag3} +} + func shuffle(endPoints []endpointsInfo) []endpointsInfo { for index1 := range endPoints { index2 := rand.Intn(index1 + 1) From 7c639de5c612085fa1148d51859836352c57e83d Mon Sep 17 00:00:00 2001 From: Inju Song Date: Wed, 24 Oct 2018 21:45:42 +0900 Subject: [PATCH 2/3] Use scheduler flags when adding or updating service Signed-off-by: Inju Song --- .../proxy/network_services_controller.go | 116 +++++++++++++++--- 1 file changed, 101 insertions(+), 15 deletions(-) diff --git a/pkg/controllers/proxy/network_services_controller.go b/pkg/controllers/proxy/network_services_controller.go index 8a67be513c..a3eeec9de0 100644 --- a/pkg/controllers/proxy/network_services_controller.go +++ b/pkg/controllers/proxy/network_services_controller.go @@ -66,7 +66,7 @@ var ( type ipvsCalls interface { ipvsNewService(ipvsSvc *ipvs.Service) error - ipvsAddService(svcs []*ipvs.Service, vip net.IP, protocol, port uint16, persistent bool, scheduler string) (*ipvs.Service, error) + ipvsAddService(svcs []*ipvs.Service, vip net.IP, protocol, port uint16, persistent bool, scheduler string, flags schedFlags) (*ipvs.Service, error) ipvsDelService(ipvsSvc *ipvs.Service) error ipvsUpdateService(ipvsSvc *ipvs.Service) error ipvsGetServices() ([]*ipvs.Service, error) @@ -75,7 +75,7 @@ type ipvsCalls interface { ipvsUpdateDestination(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination) error ipvsGetDestinations(ipvsSvc *ipvs.Service) ([]*ipvs.Destination, error) ipvsDelDestination(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination) error - ipvsAddFWMarkService(vip net.IP, protocol, port uint16, persistent bool, scheduler string) (*ipvs.Service, error) + ipvsAddFWMarkService(vip net.IP, protocol, port uint16, persistent bool, scheduler string, flags schedFlags) (*ipvs.Service, error) } type netlinkCalls interface { @@ -239,14 +239,14 @@ type serviceInfo struct { externalIPs []string loadBalancerIPs []string local bool - flags schedFlags + flags schedFlags } // IPVS scheduler flags type schedFlags struct { - flag1 bool - flag2 bool - flag3 bool + flag1 bool /* ipvs scheduler flag-1 */ + flag2 bool /* ipvs scheduler flag-2 */ + flag3 bool /* ipvs scheduler flag-3 */ } // map of all services, with unique service id(namespace name, service name, port) as key @@ -580,7 +580,7 @@ func (nsc *NetworkServicesController) syncIpvsServices(serviceInfoMap serviceInf } // create IPVS service for the service to be exposed through the cluster ip - ipvsClusterVipSvc, err := nsc.ln.ipvsAddService(ipvsSvcs, svc.clusterIP, protocol, uint16(svc.port), svc.sessionAffinity, svc.scheduler) + ipvsClusterVipSvc, err := nsc.ln.ipvsAddService(ipvsSvcs, svc.clusterIP, protocol, uint16(svc.port), svc.sessionAffinity, svc.scheduler, svc.flags) if err != nil { glog.Errorf("Failed to create ipvs service for cluster ip: %s", err.Error()) continue @@ -612,7 +612,7 @@ func (nsc *NetworkServicesController) syncIpvsServices(serviceInfoMap serviceInf nodeServiceIds = make([]string, len(addrs)) for i, addr := range addrs { - ipvsNodeportSvcs[i], err = nsc.ln.ipvsAddService(ipvsSvcs, addr.IP, protocol, uint16(svc.nodePort), svc.sessionAffinity, svc.scheduler) + ipvsNodeportSvcs[i], err = nsc.ln.ipvsAddService(ipvsSvcs, addr.IP, protocol, uint16(svc.nodePort), svc.sessionAffinity, svc.scheduler, svc.flags) if err != nil { glog.Errorf("Failed to create ipvs service for node port due to: %s", err.Error()) continue @@ -623,7 +623,7 @@ func (nsc *NetworkServicesController) syncIpvsServices(serviceInfoMap serviceInf } } else { ipvsNodeportSvcs = make([]*ipvs.Service, 1) - ipvsNodeportSvcs[0], err = nsc.ln.ipvsAddService(ipvsSvcs, nsc.nodeIP, protocol, uint16(svc.nodePort), svc.sessionAffinity, svc.scheduler) + ipvsNodeportSvcs[0], err = nsc.ln.ipvsAddService(ipvsSvcs, nsc.nodeIP, protocol, uint16(svc.nodePort), svc.sessionAffinity, svc.scheduler, svc.flags) if err != nil { glog.Errorf("Failed to create ipvs service for node port due to: %s", err.Error()) continue @@ -649,7 +649,7 @@ func (nsc *NetworkServicesController) syncIpvsServices(serviceInfoMap serviceInf for _, externalIP := range extIPSet.List() { var externalIpServiceId string if svc.directServerReturn && svc.directServerReturnMethod == "tunnel" { - ipvsExternalIPSvc, err := nsc.ln.ipvsAddFWMarkService(net.ParseIP(externalIP), protocol, uint16(svc.port), svc.sessionAffinity, svc.scheduler) + ipvsExternalIPSvc, err := nsc.ln.ipvsAddFWMarkService(net.ParseIP(externalIP), protocol, uint16(svc.port), svc.sessionAffinity, svc.scheduler, svc.flags) if err != nil { glog.Errorf("Failed to create ipvs service for External IP: %s due to: %s", externalIP, err.Error()) continue @@ -683,7 +683,7 @@ func (nsc *NetworkServicesController) syncIpvsServices(serviceInfoMap serviceInf } // create IPVS service for the service to be exposed through the external ip - ipvsExternalIPSvc, err := nsc.ln.ipvsAddService(ipvsSvcs, net.ParseIP(externalIP), protocol, uint16(svc.port), svc.sessionAffinity, svc.scheduler) + ipvsExternalIPSvc, err := nsc.ln.ipvsAddService(ipvsSvcs, net.ParseIP(externalIP), protocol, uint16(svc.port), svc.sessionAffinity, svc.scheduler, svc.flags) if err != nil { glog.Errorf("Failed to create ipvs service for external ip: %s due to %s", externalIP, err.Error()) continue @@ -1156,7 +1156,7 @@ func parseSchedFlags(value string) schedFlags { } flags := strings.Split(value, ",") - for flag := range flags { + for _, flag := range flags { switch strings.Trim(flag, " ") { case IPVS_SVC_F_SCHED1: flag1 = true @@ -1165,7 +1165,7 @@ func parseSchedFlags(value string) schedFlags { flag2 = true break case IPVS_SVC_F_SCHED3: - flag3= true + flag3 = true break default: } @@ -1483,6 +1483,18 @@ func ipvsServiceString(s *ipvs.Service) string { flags = flags + "[one-packet scheduling]" } + if s.Flags&0x0008 != 0 { + flags = flags + "[flag-1(fallback)]" + } + + if s.Flags&0x0010 != 0 { + flags = flags + "[flag-2(port)]" + } + + if s.Flags&0x0020 != 0 { + flags = flags + "[flag-3]" + } + return fmt.Sprintf("%s:%s:%v (Flags: %s)", protocol, s.Address, s.Port, flags) } @@ -1503,7 +1515,51 @@ func ipvsSetPersistence(svc *ipvs.Service, p bool) { } } -func (ln *linuxNetworking) ipvsAddService(svcs []*ipvs.Service, vip net.IP, protocol, port uint16, persistent bool, scheduler string) (*ipvs.Service, error) { +func ipvsSetSchedFlags(svc *ipvs.Service, s schedFlags) { + if s.flag1 { + svc.Flags |= 0x0008 + } else { + svc.Flags &^= 0x0008 + } + + if s.flag2 { + svc.Flags |= 0x0010 + } else { + svc.Flags &^= 0x0010 + } + + if s.flag3 { + svc.Flags |= 0x0020 + } else { + svc.Flags &^= 0x0020 + } + + /* Keep netmask which is set by ipvsSetPersistence() before */ + if (svc.Netmask&0xFFFFFFFF != 0) || (s.flag1 || s.flag2 || s.flag3) { + svc.Netmask |= 0xFFFFFFFF + } else { + svc.Netmask &^= 0xFFFFFFFF + } +} + +/* Compare service scheduler flags with ipvs service */ +func changedIpvsSchedFlags(svc *ipvs.Service, s schedFlags) bool { + if (s.flag1 && (svc.Flags&0x0008) == 0) || (!s.flag1 && (svc.Flags&0x0008) != 0) { + return true + } + + if (s.flag2 && (svc.Flags&0x0010) == 0) || (!s.flag2 && (svc.Flags&0x0010) != 0) { + return true + } + + if (s.flag3 && (svc.Flags&0x0020) == 0) || (!s.flag3 && (svc.Flags&0x0020) != 0) { + return true + } + + return false +} + +func (ln *linuxNetworking) ipvsAddService(svcs []*ipvs.Service, vip net.IP, protocol, port uint16, persistent bool, scheduler string, flags schedFlags) (*ipvs.Service, error) { var err error for _, svc := range svcs { @@ -1511,6 +1567,10 @@ func (ln *linuxNetworking) ipvsAddService(svcs []*ipvs.Service, vip net.IP, prot if (persistent && (svc.Flags&0x0001) == 0) || (!persistent && (svc.Flags&0x0001) != 0) { ipvsSetPersistence(svc, persistent) + if changedIpvsSchedFlags(svc, flags) { + ipvsSetSchedFlags(svc, flags) + } + err = ln.ipvsUpdateService(svc) if err != nil { return nil, err @@ -1518,6 +1578,16 @@ func (ln *linuxNetworking) ipvsAddService(svcs []*ipvs.Service, vip net.IP, prot glog.V(2).Infof("Updated persistence/session-affinity for service: %s", ipvsServiceString(svc)) } + if changedIpvsSchedFlags(svc, flags) { + ipvsSetSchedFlags(svc, flags) + + err = ln.ipvsUpdateService(svc) + if err != nil { + return nil, err + } + glog.V(2).Infof("Updated scheduler flags for service: %s", ipvsServiceString(svc)) + } + if scheduler != svc.SchedName { svc.SchedName = scheduler err = ln.ipvsUpdateService(svc) @@ -1543,6 +1613,7 @@ func (ln *linuxNetworking) ipvsAddService(svcs []*ipvs.Service, vip net.IP, prot } ipvsSetPersistence(&svc, persistent) + ipvsSetSchedFlags(&svc, flags) err = ln.ipvsNewService(&svc) if err != nil { @@ -1563,7 +1634,7 @@ func generateFwmark(ip, protocol, port string) uint32 { } // ipvsAddFWMarkService: creates a IPVS service using FWMARK -func (ln *linuxNetworking) ipvsAddFWMarkService(vip net.IP, protocol, port uint16, persistent bool, scheduler string) (*ipvs.Service, error) { +func (ln *linuxNetworking) ipvsAddFWMarkService(vip net.IP, protocol, port uint16, persistent bool, scheduler string, flags schedFlags) (*ipvs.Service, error) { var protocolStr string if protocol == syscall.IPPROTO_TCP { @@ -1587,6 +1658,10 @@ func (ln *linuxNetworking) ipvsAddFWMarkService(vip net.IP, protocol, port uint1 if (persistent && (svc.Flags&0x0001) == 0) || (!persistent && (svc.Flags&0x0001) != 0) { ipvsSetPersistence(svc, persistent) + if changedIpvsSchedFlags(svc, flags) { + ipvsSetSchedFlags(svc, flags) + } + err = ln.ipvsUpdateService(svc) if err != nil { return nil, err @@ -1594,6 +1669,16 @@ func (ln *linuxNetworking) ipvsAddFWMarkService(vip net.IP, protocol, port uint1 glog.V(2).Infof("Updated persistence/session-affinity for service: %s", ipvsServiceString(svc)) } + if changedIpvsSchedFlags(svc, flags) { + ipvsSetSchedFlags(svc, flags) + + err = ln.ipvsUpdateService(svc) + if err != nil { + return nil, err + } + glog.V(2).Infof("Updated scheduler flags for service: %s", ipvsServiceString(svc)) + } + if scheduler != svc.SchedName { svc.SchedName = scheduler err = ln.ipvsUpdateService(svc) @@ -1619,6 +1704,7 @@ func (ln *linuxNetworking) ipvsAddFWMarkService(vip net.IP, protocol, port uint1 } ipvsSetPersistence(&svc, persistent) + ipvsSetSchedFlags(&svc, flags) err = ln.ipvsNewService(&svc) if err != nil { From 614014a3d2aed9be4a1948eda408dba86b191eec Mon Sep 17 00:00:00 2001 From: Inju Song Date: Wed, 24 Oct 2018 21:49:47 +0900 Subject: [PATCH 3/3] Refactor with gofmt, generate moq file and fix test source Signed-off-by: Inju Song --- .../proxy/network_services_controller.go | 32 ++++----- .../proxy/network_services_controller_moq.go | 66 +++++++++++-------- .../proxy/network_services_controller_test.go | 6 +- 3 files changed, 58 insertions(+), 46 deletions(-) diff --git a/pkg/controllers/proxy/network_services_controller.go b/pkg/controllers/proxy/network_services_controller.go index a3eeec9de0..9a08e30a66 100644 --- a/pkg/controllers/proxy/network_services_controller.go +++ b/pkg/controllers/proxy/network_services_controller.go @@ -38,22 +38,22 @@ import ( ) const ( - KUBE_DUMMY_IF = "kube-dummy-if" - KUBE_TUNNEL_IF = "kube-tunnel-if" - IFACE_NOT_FOUND = "Link not found" - IFACE_HAS_ADDR = "file exists" - IFACE_HAS_NO_ADDR = "cannot assign requested address" - IPVS_SERVER_EXISTS = "file exists" - IPVS_MAGLEV_HASHING = "mh" - IPVS_SVC_F_SCHED1 = "flag-1" - IPVS_SVC_F_SCHED2 = "flag-2" - IPVS_SVC_F_SCHED3 = "flag-3" - - svcDSRAnnotation = "kube-router.io/service.dsr" - svcSchedulerAnnotation = "kube-router.io/service.scheduler" - svcHairpinAnnotation = "kube-router.io/service.hairpin" - svcLocalAnnotation = "kube-router.io/service.local" - svcSkipLbIpsAnnotation = "kube-router.io/service.skiplbips" + KUBE_DUMMY_IF = "kube-dummy-if" + KUBE_TUNNEL_IF = "kube-tunnel-if" + IFACE_NOT_FOUND = "Link not found" + IFACE_HAS_ADDR = "file exists" + IFACE_HAS_NO_ADDR = "cannot assign requested address" + IPVS_SERVER_EXISTS = "file exists" + IPVS_MAGLEV_HASHING = "mh" + IPVS_SVC_F_SCHED1 = "flag-1" + IPVS_SVC_F_SCHED2 = "flag-2" + IPVS_SVC_F_SCHED3 = "flag-3" + + svcDSRAnnotation = "kube-router.io/service.dsr" + svcSchedulerAnnotation = "kube-router.io/service.scheduler" + svcHairpinAnnotation = "kube-router.io/service.hairpin" + svcLocalAnnotation = "kube-router.io/service.local" + svcSkipLbIpsAnnotation = "kube-router.io/service.skiplbips" svcSchedFlagsAnnotation = "kube-router.io/service.schedflags" LeaderElectionRecordAnnotationKey = "control-plane.alpha.kubernetes.io/leader" diff --git a/pkg/controllers/proxy/network_services_controller_moq.go b/pkg/controllers/proxy/network_services_controller_moq.go index 4be6f689d8..09c5791ec7 100644 --- a/pkg/controllers/proxy/network_services_controller_moq.go +++ b/pkg/controllers/proxy/network_services_controller_moq.go @@ -1,4 +1,4 @@ -// Code generated by moq; DO NOT EDIT +// Code generated by moq; DO NOT EDIT. // github.com/matryer/moq package proxy @@ -49,13 +49,13 @@ var ( // ipAddrDelFunc: func(iface netlink.Link, ip string) error { // panic("TODO: mock out the ipAddrDel method") // }, -// ipvsAddFWMarkServiceFunc: func(vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string) (*ipvs.Service, error) { +// ipvsAddFWMarkServiceFunc: func(vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string, flags schedFlags) (*ipvs.Service, error) { // panic("TODO: mock out the ipvsAddFWMarkService method") // }, // ipvsAddServerFunc: func(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination, local bool, podCidr string) error { // panic("TODO: mock out the ipvsAddServer method") // }, -// ipvsAddServiceFunc: func(svcs []*ipvs.Service, vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string) (*ipvs.Service, error) { +// ipvsAddServiceFunc: func(svcs []*ipvs.Service, vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string, flags schedFlags) (*ipvs.Service, error) { // panic("TODO: mock out the ipvsAddService method") // }, // ipvsDelDestinationFunc: func(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination) error { @@ -111,13 +111,13 @@ type LinuxNetworkingMock struct { ipAddrDelFunc func(iface netlink.Link, ip string) error // ipvsAddFWMarkServiceFunc mocks the ipvsAddFWMarkService method. - ipvsAddFWMarkServiceFunc func(vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string) (*ipvs.Service, error) + ipvsAddFWMarkServiceFunc func(vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string, flags schedFlags) (*ipvs.Service, error) // ipvsAddServerFunc mocks the ipvsAddServer method. ipvsAddServerFunc func(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination, local bool, podCidr string) error // ipvsAddServiceFunc mocks the ipvsAddService method. - ipvsAddServiceFunc func(svcs []*ipvs.Service, vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string) (*ipvs.Service, error) + ipvsAddServiceFunc func(svcs []*ipvs.Service, vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string, flags schedFlags) (*ipvs.Service, error) // ipvsDelDestinationFunc mocks the ipvsDelDestination method. ipvsDelDestinationFunc func(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination) error @@ -196,6 +196,8 @@ type LinuxNetworkingMock struct { Persistent bool // Scheduler is the scheduler argument value. Scheduler string + // Flags is the flags argument value. + Flags schedFlags } // ipvsAddServer holds details about calls to the ipvsAddServer method. ipvsAddServer []struct { @@ -222,6 +224,8 @@ type LinuxNetworkingMock struct { Persistent bool // Scheduler is the scheduler argument value. Scheduler string + // Flags is the flags argument value. + Flags schedFlags } // ipvsDelDestination holds details about calls to the ipvsDelDestination method. ipvsDelDestination []struct { @@ -290,7 +294,7 @@ type LinuxNetworkingMock struct { // cleanupMangleTableRule calls cleanupMangleTableRuleFunc. func (mock *LinuxNetworkingMock) cleanupMangleTableRule(ip string, protocol string, port string, fwmark string) error { if mock.cleanupMangleTableRuleFunc == nil { - panic("moq: LinuxNetworkingMock.cleanupMangleTableRuleFunc is nil but LinuxNetworking.cleanupMangleTableRule was just called") + panic("LinuxNetworkingMock.cleanupMangleTableRuleFunc: method is nil but LinuxNetworking.cleanupMangleTableRule was just called") } callInfo := struct { IP string @@ -333,7 +337,7 @@ func (mock *LinuxNetworkingMock) cleanupMangleTableRuleCalls() []struct { // getKubeDummyInterface calls getKubeDummyInterfaceFunc. func (mock *LinuxNetworkingMock) getKubeDummyInterface() (netlink.Link, error) { if mock.getKubeDummyInterfaceFunc == nil { - panic("moq: LinuxNetworkingMock.getKubeDummyInterfaceFunc is nil but LinuxNetworking.getKubeDummyInterface was just called") + panic("LinuxNetworkingMock.getKubeDummyInterfaceFunc: method is nil but LinuxNetworking.getKubeDummyInterface was just called") } callInfo := struct { }{} @@ -359,7 +363,7 @@ func (mock *LinuxNetworkingMock) getKubeDummyInterfaceCalls() []struct { // ipAddrAdd calls ipAddrAddFunc. func (mock *LinuxNetworkingMock) ipAddrAdd(iface netlink.Link, ip string, addRoute bool) error { if mock.ipAddrAddFunc == nil { - panic("moq: LinuxNetworkingMock.ipAddrAddFunc is nil but LinuxNetworking.ipAddrAdd was just called") + panic("LinuxNetworkingMock.ipAddrAddFunc: method is nil but LinuxNetworking.ipAddrAdd was just called") } callInfo := struct { Iface netlink.Link @@ -398,7 +402,7 @@ func (mock *LinuxNetworkingMock) ipAddrAddCalls() []struct { // ipAddrDel calls ipAddrDelFunc. func (mock *LinuxNetworkingMock) ipAddrDel(iface netlink.Link, ip string) error { if mock.ipAddrDelFunc == nil { - panic("moq: LinuxNetworkingMock.ipAddrDelFunc is nil but LinuxNetworking.ipAddrDel was just called") + panic("LinuxNetworkingMock.ipAddrDelFunc: method is nil but LinuxNetworking.ipAddrDel was just called") } callInfo := struct { Iface netlink.Link @@ -431,9 +435,9 @@ func (mock *LinuxNetworkingMock) ipAddrDelCalls() []struct { } // ipvsAddFWMarkService calls ipvsAddFWMarkServiceFunc. -func (mock *LinuxNetworkingMock) ipvsAddFWMarkService(vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string) (*ipvs.Service, error) { +func (mock *LinuxNetworkingMock) ipvsAddFWMarkService(vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string, flags schedFlags) (*ipvs.Service, error) { if mock.ipvsAddFWMarkServiceFunc == nil { - panic("moq: LinuxNetworkingMock.ipvsAddFWMarkServiceFunc is nil but LinuxNetworking.ipvsAddFWMarkService was just called") + panic("LinuxNetworkingMock.ipvsAddFWMarkServiceFunc: method is nil but LinuxNetworking.ipvsAddFWMarkService was just called") } callInfo := struct { Vip net.IP @@ -441,17 +445,19 @@ func (mock *LinuxNetworkingMock) ipvsAddFWMarkService(vip net.IP, protocol uint1 Port uint16 Persistent bool Scheduler string + Flags schedFlags }{ Vip: vip, Protocol: protocol, Port: port, Persistent: persistent, Scheduler: scheduler, + Flags: flags, } lockLinuxNetworkingMockipvsAddFWMarkService.Lock() mock.calls.ipvsAddFWMarkService = append(mock.calls.ipvsAddFWMarkService, callInfo) lockLinuxNetworkingMockipvsAddFWMarkService.Unlock() - return mock.ipvsAddFWMarkServiceFunc(vip, protocol, port, persistent, scheduler) + return mock.ipvsAddFWMarkServiceFunc(vip, protocol, port, persistent, scheduler, flags) } // ipvsAddFWMarkServiceCalls gets all the calls that were made to ipvsAddFWMarkService. @@ -463,6 +469,7 @@ func (mock *LinuxNetworkingMock) ipvsAddFWMarkServiceCalls() []struct { Port uint16 Persistent bool Scheduler string + Flags schedFlags } { var calls []struct { Vip net.IP @@ -470,6 +477,7 @@ func (mock *LinuxNetworkingMock) ipvsAddFWMarkServiceCalls() []struct { Port uint16 Persistent bool Scheduler string + Flags schedFlags } lockLinuxNetworkingMockipvsAddFWMarkService.RLock() calls = mock.calls.ipvsAddFWMarkService @@ -480,7 +488,7 @@ func (mock *LinuxNetworkingMock) ipvsAddFWMarkServiceCalls() []struct { // ipvsAddServer calls ipvsAddServerFunc. func (mock *LinuxNetworkingMock) ipvsAddServer(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination, local bool, podCidr string) error { if mock.ipvsAddServerFunc == nil { - panic("moq: LinuxNetworkingMock.ipvsAddServerFunc is nil but LinuxNetworking.ipvsAddServer was just called") + panic("LinuxNetworkingMock.ipvsAddServerFunc: method is nil but LinuxNetworking.ipvsAddServer was just called") } callInfo := struct { IpvsSvc *ipvs.Service @@ -521,9 +529,9 @@ func (mock *LinuxNetworkingMock) ipvsAddServerCalls() []struct { } // ipvsAddService calls ipvsAddServiceFunc. -func (mock *LinuxNetworkingMock) ipvsAddService(svcs []*ipvs.Service, vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string) (*ipvs.Service, error) { +func (mock *LinuxNetworkingMock) ipvsAddService(svcs []*ipvs.Service, vip net.IP, protocol uint16, port uint16, persistent bool, scheduler string, flags schedFlags) (*ipvs.Service, error) { if mock.ipvsAddServiceFunc == nil { - panic("moq: LinuxNetworkingMock.ipvsAddServiceFunc is nil but LinuxNetworking.ipvsAddService was just called") + panic("LinuxNetworkingMock.ipvsAddServiceFunc: method is nil but LinuxNetworking.ipvsAddService was just called") } callInfo := struct { Svcs []*ipvs.Service @@ -532,6 +540,7 @@ func (mock *LinuxNetworkingMock) ipvsAddService(svcs []*ipvs.Service, vip net.IP Port uint16 Persistent bool Scheduler string + Flags schedFlags }{ Svcs: svcs, Vip: vip, @@ -539,11 +548,12 @@ func (mock *LinuxNetworkingMock) ipvsAddService(svcs []*ipvs.Service, vip net.IP Port: port, Persistent: persistent, Scheduler: scheduler, + Flags: flags, } lockLinuxNetworkingMockipvsAddService.Lock() mock.calls.ipvsAddService = append(mock.calls.ipvsAddService, callInfo) lockLinuxNetworkingMockipvsAddService.Unlock() - return mock.ipvsAddServiceFunc(svcs, vip, protocol, port, persistent, scheduler) + return mock.ipvsAddServiceFunc(svcs, vip, protocol, port, persistent, scheduler, flags) } // ipvsAddServiceCalls gets all the calls that were made to ipvsAddService. @@ -556,6 +566,7 @@ func (mock *LinuxNetworkingMock) ipvsAddServiceCalls() []struct { Port uint16 Persistent bool Scheduler string + Flags schedFlags } { var calls []struct { Svcs []*ipvs.Service @@ -564,6 +575,7 @@ func (mock *LinuxNetworkingMock) ipvsAddServiceCalls() []struct { Port uint16 Persistent bool Scheduler string + Flags schedFlags } lockLinuxNetworkingMockipvsAddService.RLock() calls = mock.calls.ipvsAddService @@ -574,7 +586,7 @@ func (mock *LinuxNetworkingMock) ipvsAddServiceCalls() []struct { // ipvsDelDestination calls ipvsDelDestinationFunc. func (mock *LinuxNetworkingMock) ipvsDelDestination(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination) error { if mock.ipvsDelDestinationFunc == nil { - panic("moq: LinuxNetworkingMock.ipvsDelDestinationFunc is nil but LinuxNetworking.ipvsDelDestination was just called") + panic("LinuxNetworkingMock.ipvsDelDestinationFunc: method is nil but LinuxNetworking.ipvsDelDestination was just called") } callInfo := struct { IpvsSvc *ipvs.Service @@ -609,7 +621,7 @@ func (mock *LinuxNetworkingMock) ipvsDelDestinationCalls() []struct { // ipvsDelService calls ipvsDelServiceFunc. func (mock *LinuxNetworkingMock) ipvsDelService(ipvsSvc *ipvs.Service) error { if mock.ipvsDelServiceFunc == nil { - panic("moq: LinuxNetworkingMock.ipvsDelServiceFunc is nil but LinuxNetworking.ipvsDelService was just called") + panic("LinuxNetworkingMock.ipvsDelServiceFunc: method is nil but LinuxNetworking.ipvsDelService was just called") } callInfo := struct { IpvsSvc *ipvs.Service @@ -640,7 +652,7 @@ func (mock *LinuxNetworkingMock) ipvsDelServiceCalls() []struct { // ipvsGetDestinations calls ipvsGetDestinationsFunc. func (mock *LinuxNetworkingMock) ipvsGetDestinations(ipvsSvc *ipvs.Service) ([]*ipvs.Destination, error) { if mock.ipvsGetDestinationsFunc == nil { - panic("moq: LinuxNetworkingMock.ipvsGetDestinationsFunc is nil but LinuxNetworking.ipvsGetDestinations was just called") + panic("LinuxNetworkingMock.ipvsGetDestinationsFunc: method is nil but LinuxNetworking.ipvsGetDestinations was just called") } callInfo := struct { IpvsSvc *ipvs.Service @@ -671,7 +683,7 @@ func (mock *LinuxNetworkingMock) ipvsGetDestinationsCalls() []struct { // ipvsGetServices calls ipvsGetServicesFunc. func (mock *LinuxNetworkingMock) ipvsGetServices() ([]*ipvs.Service, error) { if mock.ipvsGetServicesFunc == nil { - panic("moq: LinuxNetworkingMock.ipvsGetServicesFunc is nil but LinuxNetworking.ipvsGetServices was just called") + panic("LinuxNetworkingMock.ipvsGetServicesFunc: method is nil but LinuxNetworking.ipvsGetServices was just called") } callInfo := struct { }{} @@ -697,7 +709,7 @@ func (mock *LinuxNetworkingMock) ipvsGetServicesCalls() []struct { // ipvsNewDestination calls ipvsNewDestinationFunc. func (mock *LinuxNetworkingMock) ipvsNewDestination(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination) error { if mock.ipvsNewDestinationFunc == nil { - panic("moq: LinuxNetworkingMock.ipvsNewDestinationFunc is nil but LinuxNetworking.ipvsNewDestination was just called") + panic("LinuxNetworkingMock.ipvsNewDestinationFunc: method is nil but LinuxNetworking.ipvsNewDestination was just called") } callInfo := struct { IpvsSvc *ipvs.Service @@ -732,7 +744,7 @@ func (mock *LinuxNetworkingMock) ipvsNewDestinationCalls() []struct { // ipvsNewService calls ipvsNewServiceFunc. func (mock *LinuxNetworkingMock) ipvsNewService(ipvsSvc *ipvs.Service) error { if mock.ipvsNewServiceFunc == nil { - panic("moq: LinuxNetworkingMock.ipvsNewServiceFunc is nil but LinuxNetworking.ipvsNewService was just called") + panic("LinuxNetworkingMock.ipvsNewServiceFunc: method is nil but LinuxNetworking.ipvsNewService was just called") } callInfo := struct { IpvsSvc *ipvs.Service @@ -763,7 +775,7 @@ func (mock *LinuxNetworkingMock) ipvsNewServiceCalls() []struct { // ipvsUpdateDestination calls ipvsUpdateDestinationFunc. func (mock *LinuxNetworkingMock) ipvsUpdateDestination(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination) error { if mock.ipvsUpdateDestinationFunc == nil { - panic("moq: LinuxNetworkingMock.ipvsUpdateDestinationFunc is nil but LinuxNetworking.ipvsUpdateDestination was just called") + panic("LinuxNetworkingMock.ipvsUpdateDestinationFunc: method is nil but LinuxNetworking.ipvsUpdateDestination was just called") } callInfo := struct { IpvsSvc *ipvs.Service @@ -798,7 +810,7 @@ func (mock *LinuxNetworkingMock) ipvsUpdateDestinationCalls() []struct { // ipvsUpdateService calls ipvsUpdateServiceFunc. func (mock *LinuxNetworkingMock) ipvsUpdateService(ipvsSvc *ipvs.Service) error { if mock.ipvsUpdateServiceFunc == nil { - panic("moq: LinuxNetworkingMock.ipvsUpdateServiceFunc is nil but LinuxNetworking.ipvsUpdateService was just called") + panic("LinuxNetworkingMock.ipvsUpdateServiceFunc: method is nil but LinuxNetworking.ipvsUpdateService was just called") } callInfo := struct { IpvsSvc *ipvs.Service @@ -829,7 +841,7 @@ func (mock *LinuxNetworkingMock) ipvsUpdateServiceCalls() []struct { // prepareEndpointForDsr calls prepareEndpointForDsrFunc. func (mock *LinuxNetworkingMock) prepareEndpointForDsr(containerId string, endpointIP string, vip string) error { if mock.prepareEndpointForDsrFunc == nil { - panic("moq: LinuxNetworkingMock.prepareEndpointForDsrFunc is nil but LinuxNetworking.prepareEndpointForDsr was just called") + panic("LinuxNetworkingMock.prepareEndpointForDsrFunc: method is nil but LinuxNetworking.prepareEndpointForDsr was just called") } callInfo := struct { ContainerId string @@ -868,7 +880,7 @@ func (mock *LinuxNetworkingMock) prepareEndpointForDsrCalls() []struct { // setupPolicyRoutingForDSR calls setupPolicyRoutingForDSRFunc. func (mock *LinuxNetworkingMock) setupPolicyRoutingForDSR() error { if mock.setupPolicyRoutingForDSRFunc == nil { - panic("moq: LinuxNetworkingMock.setupPolicyRoutingForDSRFunc is nil but LinuxNetworking.setupPolicyRoutingForDSR was just called") + panic("LinuxNetworkingMock.setupPolicyRoutingForDSRFunc: method is nil but LinuxNetworking.setupPolicyRoutingForDSR was just called") } callInfo := struct { }{} @@ -894,7 +906,7 @@ func (mock *LinuxNetworkingMock) setupPolicyRoutingForDSRCalls() []struct { // setupRoutesForExternalIPForDSR calls setupRoutesForExternalIPForDSRFunc. func (mock *LinuxNetworkingMock) setupRoutesForExternalIPForDSR(in1 serviceInfoMap) error { if mock.setupRoutesForExternalIPForDSRFunc == nil { - panic("moq: LinuxNetworkingMock.setupRoutesForExternalIPForDSRFunc is nil but LinuxNetworking.setupRoutesForExternalIPForDSR was just called") + panic("LinuxNetworkingMock.setupRoutesForExternalIPForDSRFunc: method is nil but LinuxNetworking.setupRoutesForExternalIPForDSR was just called") } callInfo := struct { In1 serviceInfoMap diff --git a/pkg/controllers/proxy/network_services_controller_test.go b/pkg/controllers/proxy/network_services_controller_test.go index 0b6a5ce9b0..61a5f7d873 100644 --- a/pkg/controllers/proxy/network_services_controller_test.go +++ b/pkg/controllers/proxy/network_services_controller_test.go @@ -52,7 +52,7 @@ func (lnm *LinuxNetworkingMockImpl) ipAddrAdd(iface netlink.Link, addr string, a func (lnm *LinuxNetworkingMockImpl) ipvsAddServer(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination, local bool, podCidr string) error { return nil } -func (lnm *LinuxNetworkingMockImpl) ipvsAddService(svcs []*ipvs.Service, vip net.IP, protocol, port uint16, persistent bool, scheduler string) (*ipvs.Service, error) { +func (lnm *LinuxNetworkingMockImpl) ipvsAddService(svcs []*ipvs.Service, vip net.IP, protocol, port uint16, persistent bool, scheduler string, flags schedFlags) (*ipvs.Service, error) { svc := &ipvs.Service{ Address: vip, Protocol: protocol, @@ -179,8 +179,8 @@ var _ = Describe("NetworkServicesController", func() { }) JustBeforeEach(func() { // pre-inject some foo ipvs Service to verify its deletion - fooSvc1, _ = lnm.ipvsAddService(lnm.ipvsSvcs, net.ParseIP("1.2.3.4"), 6, 1234, false, "rr") - fooSvc2, _ = lnm.ipvsAddService(lnm.ipvsSvcs, net.ParseIP("5.6.7.8"), 6, 5678, false, "rr") + fooSvc1, _ = lnm.ipvsAddService(lnm.ipvsSvcs, net.ParseIP("1.2.3.4"), 6, 1234, false, "rr", schedFlags{}) + fooSvc2, _ = lnm.ipvsAddService(lnm.ipvsSvcs, net.ParseIP("5.6.7.8"), 6, 5678, false, "rr", schedFlags{true, true, false}) syncErr = nsc.syncIpvsServices(nsc.serviceMap, nsc.endpointsMap) }) It("Should have called syncIpvsServices OK", func() {