Merge pull request #111172 from falser101/feature/cleanup

fix:handle error and remove Redundant type conversion
This commit is contained in:
Kubernetes Prow Robot 2022-07-22 02:59:38 -07:00 committed by GitHub
commit 8e14585d87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 19 deletions

View File

@ -86,7 +86,7 @@ func Exists(execer exec.Interface) bool {
// https://github.com/kubernetes/kubernetes/issues/31983
func ClearEntriesForPort(execer exec.Interface, port int, isIPv6 bool, protocol v1.Protocol) error {
if port <= 0 {
return fmt.Errorf("Wrong port number. The port number must be greater than zero")
return fmt.Errorf("wrong port number. The port number must be greater than zero")
}
parameters := parametersWithFamily(isIPv6, "-D", "-p", protoStr(protocol), "--dport", strconv.Itoa(port))
err := Exec(execer, parameters...)
@ -117,7 +117,7 @@ func ClearEntriesForNAT(execer exec.Interface, origin, dest string, protocol v1.
// https://github.com/kubernetes/kubernetes/issues/59368
func ClearEntriesForPortNAT(execer exec.Interface, dest string, port int, protocol v1.Protocol) error {
if port <= 0 {
return fmt.Errorf("Wrong port number. The port number must be greater than zero")
return fmt.Errorf("wrong port number. The port number must be greater than zero")
}
parameters := parametersWithFamily(utilnet.IsIPv6String(dest), "-D", "-p", protoStr(protocol), "--dport", strconv.Itoa(port), "--dst-nat", dest)
err := Exec(execer, parameters...)

View File

@ -275,7 +275,7 @@ func (t RegisterWithTaintsVar) Set(s string) error {
}
var taints []v1.Taint
for _, ct := range corev1Taints {
taints = append(taints, v1.Taint{Key: ct.Key, Value: ct.Value, Effect: v1.TaintEffect(ct.Effect)})
taints = append(taints, v1.Taint{Key: ct.Key, Value: ct.Value, Effect: ct.Effect})
}
*t.Value = taints
return nil

View File

@ -28,13 +28,13 @@ const (
// that GoroutineMap will refuse to allow another operation to start with
// the same target (if exponentialBackOffOnError is enabled). Each
// successive error results in a wait 2x times the previous.
initialDurationBeforeRetry time.Duration = 500 * time.Millisecond
initialDurationBeforeRetry = 500 * time.Millisecond
// maxDurationBeforeRetry is the maximum amount of time that
// durationBeforeRetry will grow to due to exponential backoff.
// Value is slightly offset from 2 minutes to make timeouts due to this
// constant recognizable.
maxDurationBeforeRetry time.Duration = 2*time.Minute + 2*time.Second
maxDurationBeforeRetry = 2*time.Minute + 2*time.Second
)
// ExponentialBackoff contains the last occurrence of an error and the duration

View File

@ -45,8 +45,14 @@ func TestSetEntry(t *testing.T) {
}
// add two entries
fake.AddEntry("192.168.1.1,tcp:8080", set, true)
fake.AddEntry("192.168.1.2,tcp:8081", set, true)
err = fake.AddEntry("192.168.1.1,tcp:8080", set, true)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
err = fake.AddEntry("192.168.1.2,tcp:8081", set, true)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
entries, err := fake.ListEntries(set.Name)
if err != nil {
t.Errorf("Unexpected error: %v", err)

View File

@ -79,7 +79,7 @@ func toRealServerKey(rs *utilipvs.RealServer) *RealServerKey {
//AddVirtualServer is a fake implementation, it simply adds the VirtualServer into the cache store.
func (f *FakeIPVS) AddVirtualServer(serv *utilipvs.VirtualServer) error {
if serv == nil {
return fmt.Errorf("Failed to add virtual server, error: virtual server can't be nil")
return fmt.Errorf("failed to add virtual server, error: virtual server can't be nil")
}
key := toServiceKey(serv)
f.Services[key] = serv
@ -91,7 +91,7 @@ func (f *FakeIPVS) AddVirtualServer(serv *utilipvs.VirtualServer) error {
//UpdateVirtualServer is a fake implementation, it updates the VirtualServer in the cache store.
func (f *FakeIPVS) UpdateVirtualServer(serv *utilipvs.VirtualServer) error {
if serv == nil {
return fmt.Errorf("Failed to update service, service can't be nil")
return fmt.Errorf("failed to update service, service can't be nil")
}
key := toServiceKey(serv)
f.Services[key] = serv
@ -101,7 +101,7 @@ func (f *FakeIPVS) UpdateVirtualServer(serv *utilipvs.VirtualServer) error {
//DeleteVirtualServer is a fake implementation, it simply deletes the VirtualServer from the cache store.
func (f *FakeIPVS) DeleteVirtualServer(serv *utilipvs.VirtualServer) error {
if serv == nil {
return fmt.Errorf("Failed to delete service: service can't be nil")
return fmt.Errorf("failed to delete service: service can't be nil")
}
key := toServiceKey(serv)
delete(f.Services, key)
@ -113,14 +113,14 @@ func (f *FakeIPVS) DeleteVirtualServer(serv *utilipvs.VirtualServer) error {
//GetVirtualServer is a fake implementation, it tries to find a specific VirtualServer from the cache store.
func (f *FakeIPVS) GetVirtualServer(serv *utilipvs.VirtualServer) (*utilipvs.VirtualServer, error) {
if serv == nil {
return nil, fmt.Errorf("Failed to get service: service can't be nil")
return nil, fmt.Errorf("failed to get service: service can't be nil")
}
key := toServiceKey(serv)
svc, found := f.Services[key]
if found {
return svc, nil
}
return nil, fmt.Errorf("Not found serv: %v", key.String())
return nil, fmt.Errorf("not found serv: %v", key.String())
}
//GetVirtualServers is a fake implementation, it simply returns all VirtualServers in the cache store.
@ -143,11 +143,11 @@ func (f *FakeIPVS) Flush() error {
//AddRealServer is a fake implementation, it simply creates a RealServer for a VirtualServer in the cache store.
func (f *FakeIPVS) AddRealServer(serv *utilipvs.VirtualServer, dest *utilipvs.RealServer) error {
if serv == nil || dest == nil {
return fmt.Errorf("Failed to add destination for service, neither service nor destination shouldn't be nil")
return fmt.Errorf("failed to add destination for service, neither service nor destination shouldn't be nil")
}
key := toServiceKey(serv)
if _, ok := f.Services[key]; !ok {
return fmt.Errorf("Failed to add destination for service %v, service not found", key.String())
return fmt.Errorf("failed to add destination for service %v, service not found", key.String())
}
dests := f.Destinations[key]
if dests == nil {
@ -161,11 +161,11 @@ func (f *FakeIPVS) AddRealServer(serv *utilipvs.VirtualServer, dest *utilipvs.Re
//GetRealServers is a fake implementation, it simply returns all RealServers in the cache store.
func (f *FakeIPVS) GetRealServers(serv *utilipvs.VirtualServer) ([]*utilipvs.RealServer, error) {
if serv == nil {
return nil, fmt.Errorf("Failed to get destination for nil service")
return nil, fmt.Errorf("failed to get destination for nil service")
}
key := toServiceKey(serv)
if _, ok := f.Services[key]; !ok {
return nil, fmt.Errorf("Failed to get destinations for service %v, service not found", key.String())
return nil, fmt.Errorf("failed to get destinations for service %v, service not found", key.String())
}
return f.Destinations[key], nil
}
@ -173,11 +173,11 @@ func (f *FakeIPVS) GetRealServers(serv *utilipvs.VirtualServer) ([]*utilipvs.Rea
//DeleteRealServer is a fake implementation, it deletes the real server in the cache store.
func (f *FakeIPVS) DeleteRealServer(serv *utilipvs.VirtualServer, dest *utilipvs.RealServer) error {
if serv == nil || dest == nil {
return fmt.Errorf("Failed to delete destination, neither service nor destination can't be nil")
return fmt.Errorf("failed to delete destination, neither service nor destination can't be nil")
}
key := toServiceKey(serv)
if _, ok := f.Services[key]; !ok {
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]
exist := false
@ -191,7 +191,7 @@ func (f *FakeIPVS) DeleteRealServer(serv *utilipvs.VirtualServer, dest *utilipvs
}
// Not Found
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())
}
return nil
}