Merge pull request #52015 from m1093782566/flush-ipvs

Automatic merge from submit-queue (batch tested with PRs 51929, 52015, 51906, 52069, 51542). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>..

Support IPVS Flush API

**What this PR does / why we need it**:

Currently, we implement IPVS flush API by deleting IPVS services one by one, which is inefficient.

**Which issue this PR fixes**: 

fixes #52070

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2017-09-23 06:16:09 -07:00 committed by GitHub
commit 4d5bcda664
4 changed files with 16 additions and 14 deletions

3
Godeps/Godeps.json generated
View File

@ -1089,8 +1089,7 @@
},
{
"ImportPath": "github.com/docker/libnetwork/ipvs",
"Comment": "v0.8.0-dev.2-908-gd5c82231",
"Rev": "d5c822319097cc01cc9bd5ffedd74c7ce7c894f2"
"Rev": "ba46b928444931e6865d8618dc03622cac79aa6f"
},
{
"ImportPath": "github.com/docker/libtrust",

View File

@ -142,18 +142,7 @@ func (runner *runner) GetVirtualServers() ([]*VirtualServer, error) {
// Flush is part of Interface. Currently we delete IPVS services one by one
func (runner *runner) Flush() error {
vss, err := runner.GetVirtualServers()
if err != nil {
return err
}
for _, vs := range vss {
err := runner.DeleteVirtualServer(vs)
// TODO: aggregate errors?
if err != nil {
return err
}
}
return nil
return runner.ipvsHandle.Flush()
}
// AddRealServer is part of Interface.

View File

@ -116,6 +116,13 @@ func (i *Handle) DelService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdDelService)
}
// Flush deletes all existing services in the passed
// handle.
func (i *Handle) Flush() error {
_, err := i.doCmdWithoutAttr(ipvsCmdFlush)
return err
}
// NewDestination creates a new real server in the passed ipvs
// service which should already be existing in the passed handle.
func (i *Handle) NewDestination(s *Service, d *Destination) error {

View File

@ -402,6 +402,13 @@ func (i *Handle) doGetServicesCmd(svc *Service) ([]*Service, error) {
return res, nil
}
// doCmdWithoutAttr a simple wrapper of netlink socket execute command
func (i *Handle) doCmdWithoutAttr(cmd uint8) ([][]byte, error) {
req := newIPVSRequest(cmd)
req.Seq = atomic.AddUint32(&i.seq, 1)
return execute(i.sock, req, 0)
}
func assembleDestination(attrs []syscall.NetlinkRouteAttr) (*Destination, error) {
var d Destination