Skip to content

Commit

Permalink
Merge pull request #1185 from XudongLiuHarold/fix-static-check
Browse files Browse the repository at this point in the history
⚙️  Fix golang static check
  • Loading branch information
k8s-ci-robot authored Aug 19, 2024
2 parents 00669c1 + ed9dc77 commit 89a46d8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package config

import (
"encoding/json"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -75,39 +76,39 @@ func (lbc *LBConfigINI) validateConfig() error {
if lbc.LoadBalancer.LBServiceID == "" && lbc.LoadBalancer.Tier1GatewayPath == "" {
msg := "either load balancer service id or T1 gateway path required"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
if lbc.LoadBalancer.TCPAppProfileName == "" && lbc.LoadBalancer.TCPAppProfilePath == "" {
msg := "either load balancer TCP application profile name or path required"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
if lbc.LoadBalancer.UDPAppProfileName == "" && lbc.LoadBalancer.UDPAppProfilePath == "" {
msg := "either load balancer UDP application profile name or path required"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
if !LoadBalancerSizes.Has(lbc.LoadBalancer.Size) {
msg := fmt.Sprintf("load balancer size is invalid. Valid values are: %s", strings.Join(LoadBalancerSizes.List(), ","))
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
if lbc.LoadBalancer.IPPoolID == "" && lbc.LoadBalancer.IPPoolName == "" {
class, ok := lbc.LoadBalancerClass[DefaultLoadBalancerClass]
if !ok {
msg := "no default load balancer class defined"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
} else if class.IPPoolName == "" && class.IPPoolID == "" {
msg := "default load balancer class: ipPoolName and ipPoolID is empty"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
} else {
if lbc.LoadBalancer.IPPoolName != "" && lbc.LoadBalancer.IPPoolID != "" {
msg := "either load balancer ipPoolName or ipPoolID can be set"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
}
return nil
Expand Down
15 changes: 8 additions & 7 deletions pkg/cloudprovider/vsphere/loadbalancer/config/config_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package config

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -73,39 +74,39 @@ func (lbc *LBConfigYAML) validateConfig() error {
if lbc.LoadBalancer.LBServiceID == "" && lbc.LoadBalancer.Tier1GatewayPath == "" {
msg := "either load balancer service id or T1 gateway path required"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
if lbc.LoadBalancer.TCPAppProfileName == "" && lbc.LoadBalancer.TCPAppProfilePath == "" {
msg := "either load balancer TCP application profile name or path required"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
if lbc.LoadBalancer.UDPAppProfileName == "" && lbc.LoadBalancer.UDPAppProfilePath == "" {
msg := "either load balancer UDP application profile name or path required"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
if !LoadBalancerSizes.Has(lbc.LoadBalancer.Size) {
msg := fmt.Sprintf("load balancer size is invalid. Valid values are: %s", strings.Join(LoadBalancerSizes.List(), ","))
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
if lbc.LoadBalancer.IPPoolID == "" && lbc.LoadBalancer.IPPoolName == "" {
class, ok := lbc.LoadBalancerClass[DefaultLoadBalancerClass]
if !ok {
msg := "no default load balancer class defined"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
} else if class.IPPoolName == "" && class.IPPoolID == "" {
msg := "default load balancer class: ipPoolName and ipPoolID is empty"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
} else {
if lbc.LoadBalancer.IPPoolName != "" && lbc.LoadBalancer.IPPoolID != "" {
msg := "either load balancer ipPoolName or ipPoolID can be set"
klog.Errorf(msg)
return fmt.Errorf(msg)
return errors.New(msg)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/vsphere/loadbalancer/nsxt_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,5 +408,5 @@ func nicerVapiErrorData(errorMsg string, apiErrorDataValue *data.StructValue, me
details += fmt.Sprintf("%s (code %v)", *relatedErr.ErrorMessage, relatedErr.ErrorCode)
}
}
return fmt.Errorf(details)
return errors.New(details)
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ func TestProcessIPPoolCreateOrUpdate(t *testing.T) {
}

if err := updateIPPoolCIDRAndVerifyNodeCIDR(tc.subnetAllocated, c); err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

if err := updateIPPoolCIDRAndVerifyNodeCIDR(tc.subnetAfterRevoked, c); err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

// verify the number of patch request to nodes to update cidr section
Expand Down
5 changes: 3 additions & 2 deletions pkg/cloudprovider/vsphereparavirtual/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package vsphereparavirtual

import (
"context"
"errors"
"fmt"
"testing"

Expand Down Expand Up @@ -232,14 +233,14 @@ func TestEnsureLoadBalancer(t *testing.T) {
{
name: "when VMService is created but IP not found",
createFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
return true, &vmopv1alpha1.VirtualMachineService{}, fmt.Errorf(vmservice.ErrVMServiceIPNotFound.Error())
return true, &vmopv1alpha1.VirtualMachineService{}, errors.New(vmservice.ErrVMServiceIPNotFound.Error())
},
expectErr: vmservice.ErrVMServiceIPNotFound,
},
{
name: "when VMService creation failed",
createFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
return true, &vmopv1alpha1.VirtualMachineService{}, fmt.Errorf(vmservice.ErrCreateVMService.Error())
return true, &vmopv1alpha1.VirtualMachineService{}, errors.New(vmservice.ErrCreateVMService.Error())
},
expectErr: vmservice.ErrCreateVMService,
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/cloudprovider/vsphereparavirtual/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package vsphereparavirtual

import (
"context"
"fmt"
"errors"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestListRoutes(t *testing.T) {
func TestListRoutesFailed(t *testing.T) {
r, fcw, _ := initRouteTest()
fcw.ListFunc = func(ctx context.Context, opts metav1.ListOptions) (result *t1networkingapis.RouteSetList, err error) {
return nil, fmt.Errorf(helper.ErrListRouteCR.Error())
return nil, errors.New(helper.ErrListRouteCR.Error())
}

routes, err := r.ListRoutes(context.TODO(), testClustername)
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestDeleteRouteFailed(t *testing.T) {
assert.NotEqual(t, routeSetCR, nil)

fcw.DeleteFunc = func(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return fmt.Errorf(helper.ErrDeleteRouteCR.Error())
return errors.New(helper.ErrDeleteRouteCR.Error())
}
err = r.DeleteRoute(context.TODO(), testClustername, &route)
if err != nil {
Expand Down

0 comments on commit 89a46d8

Please sign in to comment.