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 // https://github.com/kubernetes/kubernetes/issues/31983
func ClearEntriesForPort(execer exec.Interface, port int, isIPv6 bool, protocol v1.Protocol) error { func ClearEntriesForPort(execer exec.Interface, port int, isIPv6 bool, protocol v1.Protocol) error {
if port <= 0 { 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)) parameters := parametersWithFamily(isIPv6, "-D", "-p", protoStr(protocol), "--dport", strconv.Itoa(port))
err := Exec(execer, parameters...) 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 // https://github.com/kubernetes/kubernetes/issues/59368
func ClearEntriesForPortNAT(execer exec.Interface, dest string, port int, protocol v1.Protocol) error { func ClearEntriesForPortNAT(execer exec.Interface, dest string, port int, protocol v1.Protocol) error {
if port <= 0 { 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) parameters := parametersWithFamily(utilnet.IsIPv6String(dest), "-D", "-p", protoStr(protocol), "--dport", strconv.Itoa(port), "--dst-nat", dest)
err := Exec(execer, parameters...) err := Exec(execer, parameters...)

View File

@ -275,7 +275,7 @@ func (t RegisterWithTaintsVar) Set(s string) error {
} }
var taints []v1.Taint var taints []v1.Taint
for _, ct := range corev1Taints { 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 *t.Value = taints
return nil return nil

View File

@ -28,13 +28,13 @@ const (
// that GoroutineMap will refuse to allow another operation to start with // that GoroutineMap will refuse to allow another operation to start with
// the same target (if exponentialBackOffOnError is enabled). Each // the same target (if exponentialBackOffOnError is enabled). Each
// successive error results in a wait 2x times the previous. // 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 // maxDurationBeforeRetry is the maximum amount of time that
// durationBeforeRetry will grow to due to exponential backoff. // durationBeforeRetry will grow to due to exponential backoff.
// Value is slightly offset from 2 minutes to make timeouts due to this // Value is slightly offset from 2 minutes to make timeouts due to this
// constant recognizable. // 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 // 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 // add two entries
fake.AddEntry("192.168.1.1,tcp:8080", set, true) err = fake.AddEntry("192.168.1.1,tcp:8080", set, true)
fake.AddEntry("192.168.1.2,tcp:8081", 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) entries, err := fake.ListEntries(set.Name)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) 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. //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 {
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) key := toServiceKey(serv)
f.Services[key] = 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. //UpdateVirtualServer is a fake implementation, it updates the VirtualServer in the cache store.
func (f *FakeIPVS) UpdateVirtualServer(serv *utilipvs.VirtualServer) error { func (f *FakeIPVS) UpdateVirtualServer(serv *utilipvs.VirtualServer) error {
if serv == nil { 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) key := toServiceKey(serv)
f.Services[key] = 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. //DeleteVirtualServer is a fake implementation, it simply deletes the VirtualServer from the cache store.
func (f *FakeIPVS) DeleteVirtualServer(serv *utilipvs.VirtualServer) error { func (f *FakeIPVS) DeleteVirtualServer(serv *utilipvs.VirtualServer) error {
if serv == nil { 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) key := toServiceKey(serv)
delete(f.Services, key) 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. //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) { func (f *FakeIPVS) GetVirtualServer(serv *utilipvs.VirtualServer) (*utilipvs.VirtualServer, error) {
if serv == nil { 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) key := toServiceKey(serv)
svc, found := f.Services[key] svc, found := f.Services[key]
if found { if found {
return svc, nil 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. //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. //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 { func (f *FakeIPVS) AddRealServer(serv *utilipvs.VirtualServer, dest *utilipvs.RealServer) error {
if serv == nil || dest == nil { 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) key := toServiceKey(serv)
if _, ok := f.Services[key]; !ok { 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] dests := f.Destinations[key]
if dests == nil { 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. //GetRealServers is a fake implementation, it simply returns all RealServers in the cache store.
func (f *FakeIPVS) GetRealServers(serv *utilipvs.VirtualServer) ([]*utilipvs.RealServer, error) { func (f *FakeIPVS) GetRealServers(serv *utilipvs.VirtualServer) ([]*utilipvs.RealServer, error) {
if serv == nil { 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) key := toServiceKey(serv)
if _, ok := f.Services[key]; !ok { 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 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. //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 { func (f *FakeIPVS) DeleteRealServer(serv *utilipvs.VirtualServer, dest *utilipvs.RealServer) error {
if serv == nil || dest == nil { 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) key := toServiceKey(serv)
if _, ok := f.Services[key]; !ok { 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] dests := f.Destinations[key]
exist := false exist := false
@ -191,7 +191,7 @@ func (f *FakeIPVS) DeleteRealServer(serv *utilipvs.VirtualServer, dest *utilipvs
} }
// Not Found // Not Found
if !exist { 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 return nil
} }