Skip to content

Commit

Permalink
lint: make staticcheck happy
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Sep 10, 2021
1 parent 5a12637 commit 8dbe8f9
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ func (c *Controller) acquireAddress(pod *v1.Pod, podNet *kubeovnNet) (string, st
}
}
klog.Errorf("alloc address for %s failed, return NoAvailableAddress", key)
return "", "", "", ipam.NoAvailableError
return "", "", "", ipam.ErrNoAvailable
}

func generatePatchPayload(annotations map[string]string, op string) []byte {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/vpc_nat_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (c *Controller) handleInitVpcNatGw(key string) error {

if pod.Status.Phase != corev1.PodRunning {
time.Sleep(5 * 1000)
return fmt.Errorf("failed to init vpc nat gateway, pod is not ready.")
return fmt.Errorf("failed to init vpc nat gateway, pod is not ready")
}

if _, hasInit := pod.Annotations[util.VpcNatGatewayInitAnnotation]; hasInit {
Expand Down Expand Up @@ -768,7 +768,7 @@ func (c *Controller) getNatGwPod(name string) (*corev1.Pod, error) {
if err != nil {
return nil, err
} else if len(pods) != 1 {
return nil, fmt.Errorf("too many pod.")
return nil, fmt.Errorf("too many pod")
} else if pods[0].Status.Phase != "Running" {
return nil, fmt.Errorf("pod is not active now")
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
)

var (
OutOfRangeError = errors.New("AddressOutOfRange")
ConflictError = errors.New("AddressConflict")
NoAvailableError = errors.New("NoAvailableAddress")
InvalidCIDRError = errors.New("CIDRInvalid")
ErrOutOfRange = errors.New("AddressOutOfRange")
ErrConflict = errors.New("AddressConflict")
ErrNoAvailable = errors.New("NoAvailableAddress")
ErrInvalidCIDR = errors.New("CIDRInvalid")
)

type IPAM struct {
Expand All @@ -42,7 +42,7 @@ func (ipam *IPAM) GetRandomAddress(podName, subnetName string, skippedAddrs []st

subnet, ok := ipam.Subnets[subnetName]
if !ok {
return "", "", "", NoAvailableError
return "", "", "", ErrNoAvailable
}

v4IP, v6IP, mac, err := subnet.GetRandomAddress(podName, skippedAddrs)
Expand All @@ -54,7 +54,7 @@ func (ipam *IPAM) GetStaticAddress(podName, ip, mac, subnetName string, checkCon
ipam.mutex.RLock()
defer ipam.mutex.RUnlock()
if subnet, ok := ipam.Subnets[subnetName]; !ok {
return "", "", "", NoAvailableError
return "", "", "", ErrNoAvailable
} else {
var ips []IP
var err error
Expand Down Expand Up @@ -84,7 +84,7 @@ func (ipam *IPAM) GetStaticAddress(podName, ip, mac, subnetName string, checkCon
return string(ips[0]), string(ips[1]), mac, err
}
}
return "", "", "", NoAvailableError
return "", "", "", ErrNoAvailable
}

func checkAndAppendIpsForDual(ips []IP, podName string, subnet *Subnet) ([]IP, error) {
Expand Down Expand Up @@ -127,7 +127,7 @@ func (ipam *IPAM) AddOrUpdateSubnet(name, cidrStr string, excludeIps []string) e
var cidrs []*net.IPNet
for _, cidrBlock := range strings.Split(cidrStr, ",") {
if _, cidr, err := net.ParseCIDR(cidrBlock); err != nil {
return InvalidCIDRError
return ErrInvalidCIDR
} else {
cidrs = append(cidrs, cidr)
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/ipam/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewSubnet(name, cidrStr string, excludeIps []string) (*Subnet, error) {
var cidrs []*net.IPNet
for _, cidrBlock := range strings.Split(cidrStr, ",") {
if _, cidr, err := net.ParseCIDR(cidrBlock); err != nil {
return nil, InvalidCIDRError
return nil, ErrInvalidCIDR
} else {
cidrs = append(cidrs, cidr)
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func (subnet *Subnet) GetRandomMac(podName string) string {
func (subnet *Subnet) GetStaticMac(podName, mac string, checkConflict bool) error {
if checkConflict {
if p, ok := subnet.MacToPod[mac]; ok && p != podName {
return ConflictError
return ErrConflict
}
}
subnet.MacToPod[mac] = podName
Expand Down Expand Up @@ -183,7 +183,7 @@ func (subnet *Subnet) getV4RandomAddress(podName string, skippedAddrs []string)
}
if len(subnet.V4FreeIPList) == 0 {
if len(subnet.V4ReleasedIPList) == 0 {
return "", "", "", NoAvailableError
return "", "", "", ErrNoAvailable
}
subnet.V4FreeIPList = subnet.V4ReleasedIPList
subnet.V4ReleasedIPList = IPRangeList{}
Expand All @@ -204,7 +204,7 @@ func (subnet *Subnet) getV4RandomAddress(podName string, skippedAddrs []string)
}
}
if ip == "" {
return "", "", "", ConflictError
return "", "", "", ErrConflict
}

ipr := subnet.V4FreeIPList[idx]
Expand Down Expand Up @@ -233,7 +233,7 @@ func (subnet *Subnet) getV6RandomAddress(podName string, skippedAddrs []string)
}
if len(subnet.V6FreeIPList) == 0 {
if len(subnet.V6ReleasedIPList) == 0 {
return "", "", "", NoAvailableError
return "", "", "", ErrNoAvailable
}
subnet.V6FreeIPList = subnet.V6ReleasedIPList
subnet.V6ReleasedIPList = IPRangeList{}
Expand All @@ -254,7 +254,7 @@ func (subnet *Subnet) getV6RandomAddress(podName string, skippedAddrs []string)
}
}
if ip == "" {
return "", "", "", ConflictError
return "", "", "", ErrConflict
}

ipr := subnet.V6FreeIPList[idx]
Expand Down Expand Up @@ -285,10 +285,10 @@ func (subnet *Subnet) GetStaticAddress(podName string, ip IP, mac string, force
v6 = subnet.V6CIDR != nil
}
if v4 && !subnet.V4CIDR.Contains(net.ParseIP(string(ip))) {
return ip, mac, OutOfRangeError
return ip, mac, ErrOutOfRange
}
if v6 && !subnet.V6CIDR.Contains(net.ParseIP(string(ip))) {
return ip, mac, OutOfRangeError
return ip, mac, ErrOutOfRange
}

if mac == "" {
Expand All @@ -312,7 +312,7 @@ func (subnet *Subnet) GetStaticAddress(podName string, ip IP, mac string, force
subnet.V4IPToPod[ip] = fmt.Sprintf("%s,%s", subnet.V4IPToPod[ip], podName)
return ip, mac, nil
}
return ip, mac, ConflictError
return ip, mac, ErrConflict
}
if !force {
return ip, mac, nil
Expand Down Expand Up @@ -347,7 +347,7 @@ func (subnet *Subnet) GetStaticAddress(podName string, ip IP, mac string, force
subnet.V6IPToPod[ip] = fmt.Sprintf("%s,%s", subnet.V6IPToPod[ip], podName)
return ip, mac, nil
}
return ip, mac, ConflictError
return ip, mac, ErrConflict
}
if !force {
return ip, mac, nil
Expand All @@ -374,7 +374,7 @@ func (subnet *Subnet) GetStaticAddress(podName string, ip IP, mac string, force
}
}
}
return ip, mac, NoAvailableError
return ip, mac, ErrNoAvailable
}

func (subnet *Subnet) releaseAddr(podName string) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ovnmonitor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func getClusterInfo(direction, dbName string) (*OVNDBClusterStatus, error) {
cmd := exec.Command("sh", "-c", cmdstr)
output, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("Failed to retrieve cluster/status info for database %s: %v", dbName, err)
return nil, fmt.Errorf("failed to retrieve cluster/status info for database %s: %v", dbName, err)
}

for _, line := range strings.Split(string(output), "\n") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/speaker/bgpapiutil/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//nolint:staticcheck
package apiutil

import (
"errors"
"fmt"
"net"

// nolint:staticcheck
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
Expand Down
3 changes: 1 addition & 2 deletions pkg/speaker/bgpapiutil/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//nolint:staticcheck
package apiutil

import (
"fmt"

// nolint:staticcheck
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
Expand Down
1 change: 1 addition & 0 deletions pkg/speaker/bgpapiutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//nolint:staticcheck
package apiutil

import (
Expand Down
6 changes: 3 additions & 3 deletions pkg/speaker/subnet.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:staticcheck
package speaker

import (
Expand All @@ -8,7 +9,6 @@ import (
"strings"

"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
anypb "github.com/golang/protobuf/ptypes/any"
bgpapiutil "github.com/kubeovn/kube-ovn/pkg/speaker/bgpapiutil"
"github.com/kubeovn/kube-ovn/pkg/util"
Expand Down Expand Up @@ -174,7 +174,7 @@ func (c *Controller) addRoute(route string) error {
return nil
}

func (c *Controller) getNlriAndAttrs(route string) (*anypb.Any, []*any.Any, error) {
func (c *Controller) getNlriAndAttrs(route string) (*anypb.Any, []*anypb.Any, error) {
prefix, prefixLen, err := parseRoute(route)
if err != nil {
return nil, nil, err
Expand All @@ -189,7 +189,7 @@ func (c *Controller) getNlriAndAttrs(route string) (*anypb.Any, []*any.Any, erro
a2, _ := ptypes.MarshalAny(&bgpapi.NextHopAttribute{
NextHop: c.config.RouterId,
})
attrs := []*any.Any{a1, a2}
attrs := []*anypb.Any{a1, a2}
return nlri, attrs, err
}

Expand Down

0 comments on commit 8dbe8f9

Please sign in to comment.