Skip to content

Commit 4b3d1a3

Browse files
author
Murali Reddy
committed
re-use ipvs handle for add/delete ipvs service, servers and listing services and server
using ipvslib New() is causing system thread leak resulting in hitting GOLANG 10000 thread limit Fixes #19, #24
1 parent 3524a2a commit 4b3d1a3

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

app/controllers/network_services_controller.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ const (
2929
IPVS_SERVER_EXISTS = "file exists"
3030
)
3131

32+
var (
33+
h libipvs.IPVSHandle
34+
)
35+
3236
// Network services controller enables local node as network service proxy through IPVS/LVS.
3337
// Support only Kuberntes network services of type NodePort, ClusterIP. For each service a
3438
// IPVS service is created and for each service endpoint a server is added to the IPVS service.
@@ -247,10 +251,6 @@ func (nsc *NetworkServicesController) syncIpvsServices(serviceInfoMap serviceInf
247251

248252
// cleanup stale ipvs service and servers
249253
glog.Infof("Cleaning up if any, old ipvs service and servers which are no longer needed")
250-
h, err := libipvs.New()
251-
if err != nil {
252-
panic(err)
253-
}
254254
ipvsSvcs, err := h.ListServices()
255255
if err != nil {
256256
panic(err)
@@ -392,10 +392,6 @@ func deleteMasqueradeIptablesRule() error {
392392
}
393393

394394
func ipvsAddService(vip net.IP, protocol, port uint16, persistent bool) (*libipvs.Service, error) {
395-
h, err := libipvs.New()
396-
if err != nil {
397-
panic(err)
398-
}
399395
svcs, err := h.ListServices()
400396
if err != nil {
401397
panic(err)
@@ -431,12 +427,8 @@ func ipvsAddService(vip net.IP, protocol, port uint16, persistent bool) (*libipv
431427
}
432428

433429
func ipvsAddServer(service *libipvs.Service, dest *libipvs.Destination) error {
434-
h, err := libipvs.New()
435-
if err != nil {
436-
panic(err)
437-
}
438430

439-
err = h.NewDestination(service, dest)
431+
err := h.NewDestination(service, dest)
440432
if err == nil {
441433
glog.Infof("Successfully added destination %s:%s to the service %s:%s:%s", dest.Address,
442434
strconv.Itoa(int(dest.Port)), service.Address, service.Protocol, strconv.Itoa(int(service.Port)))
@@ -485,12 +477,8 @@ func getKubeDummyInterface() netlink.Link {
485477
func (nsc *NetworkServicesController) Cleanup() {
486478

487479
// cleanup ipvs rules by flush
488-
h, err := libipvs.New()
489-
if err != nil {
490-
panic(err)
491-
}
492480
glog.Infof("Cleaning up IPVS configuration permanently")
493-
err = h.Flush()
481+
err := h.Flush()
494482
if err != nil {
495483
glog.Errorf("Failed to cleanup ipvs rules: ", err.Error())
496484
return
@@ -521,6 +509,12 @@ func (nsc *NetworkServicesController) Cleanup() {
521509

522510
func NewNetworkServicesController(clientset *kubernetes.Clientset, config *options.KubeRouterConfig) (*NetworkServicesController, error) {
523511

512+
handle, err := libipvs.New()
513+
if err != nil {
514+
panic(err)
515+
}
516+
h = handle
517+
524518
nsc := NetworkServicesController{}
525519
nsc.syncPeriod = config.IpvsSyncPeriod
526520

0 commit comments

Comments
 (0)