mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Modify ipvs real server equal
This commit is contained in:
parent
18758f502c
commit
b842f008fc
@ -18,6 +18,8 @@ package testing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
utilipvs "k8s.io/kubernetes/pkg/util/ipvs"
|
utilipvs "k8s.io/kubernetes/pkg/util/ipvs"
|
||||||
)
|
)
|
||||||
@ -39,6 +41,15 @@ func (s *serviceKey) String() string {
|
|||||||
return fmt.Sprintf("%s:%d/%s", s.IP, s.Port, s.Protocol)
|
return fmt.Sprintf("%s:%d/%s", s.IP, s.Port, s.Protocol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type realServerKey struct {
|
||||||
|
Address net.IP
|
||||||
|
Port uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *realServerKey) String() string {
|
||||||
|
return net.JoinHostPort(r.Address.String(), strconv.Itoa(int(r.Port)))
|
||||||
|
}
|
||||||
|
|
||||||
//NewFake creates a fake ipvs implementation - a cache store.
|
//NewFake creates a fake ipvs implementation - a cache store.
|
||||||
func NewFake() *FakeIPVS {
|
func NewFake() *FakeIPVS {
|
||||||
return &FakeIPVS{
|
return &FakeIPVS{
|
||||||
@ -55,6 +66,13 @@ func toServiceKey(serv *utilipvs.VirtualServer) serviceKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toRealServerKey(rs *utilipvs.RealServer) *realServerKey {
|
||||||
|
return &realServerKey{
|
||||||
|
Address: rs.Address,
|
||||||
|
Port: rs.Port,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//AddVirtualServer is a fake implementation, it simply adds the VirtualServer into the cache store.
|
//AddVirtualServer is a fake implementation, it simply adds the VirtualServer into the cache store.
|
||||||
func (f *FakeIPVS) AddVirtualServer(serv *utilipvs.VirtualServer) error {
|
func (f *FakeIPVS) AddVirtualServer(serv *utilipvs.VirtualServer) error {
|
||||||
if serv == nil {
|
if serv == nil {
|
||||||
@ -159,18 +177,19 @@ func (f *FakeIPVS) DeleteRealServer(serv *utilipvs.VirtualServer, dest *utilipvs
|
|||||||
return fmt.Errorf("Failed to delete destination for service %v, service not found", key.String())
|
return fmt.Errorf("Failed to delete destination for service %v, service not found", key.String())
|
||||||
}
|
}
|
||||||
dests := f.Destinations[key]
|
dests := f.Destinations[key]
|
||||||
var i int
|
exist := false
|
||||||
for i = range dests {
|
for i := range dests {
|
||||||
if dests[i].Equal(dest) {
|
if toRealServerKey(dests[i]).String() == toRealServerKey(dest).String() {
|
||||||
|
// Delete one element
|
||||||
|
f.Destinations[key] = append(f.Destinations[key][:i], f.Destinations[key][i+1:]...)
|
||||||
|
exist = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Not Found
|
// Not Found
|
||||||
if i >= len(f.Destinations[key]) {
|
if !exist {
|
||||||
return fmt.Errorf("Failed to delete real server for service %v, real server not found", key.String())
|
return fmt.Errorf("Failed to delete real server for service %v, real server not found", key.String())
|
||||||
}
|
}
|
||||||
// Delete one element
|
|
||||||
f.Destinations[key] = append(f.Destinations[key][:i], f.Destinations[key][i+1:]...)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user