Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated golangci-lint version, fixed linter errors #1208

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.35.0
version: v1.42.1
excludeFmtErrorf:
name: exclude fmt.Errorf
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions pkg/networkservice/chains/nsmgr/unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package nsmgr_test
Expand Down
1 change: 1 addition & 0 deletions pkg/networkservice/common/mechanisms/kernel/vlan/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

// Package vlan provides server chain element setting vlan id on the kernel mechanism
Expand Down
1 change: 1 addition & 0 deletions pkg/networkservice/common/mechanisms/recvfd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package recvfd
Expand Down
1 change: 1 addition & 0 deletions pkg/networkservice/common/mechanisms/recvfd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package recvfd
Expand Down
1 change: 1 addition & 0 deletions pkg/networkservice/common/mechanisms/recvfd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package recvfd
Expand Down
1 change: 1 addition & 0 deletions pkg/networkservice/common/mechanisms/recvfd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package recvfd_test
Expand Down
1 change: 1 addition & 0 deletions pkg/networkservice/common/mechanisms/sendfd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package sendfd
Expand Down
1 change: 1 addition & 0 deletions pkg/networkservice/common/mechanisms/sendfd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package sendfd
Expand Down
1 change: 1 addition & 0 deletions pkg/networkservice/common/mechanisms/sendfd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package sendfd
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkservice/common/roundrobin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *selectEndpointServer) Request(ctx context.Context, request *networkserv
request.GetConnection().NetworkServiceEndpointName = endpoint.Name
resp, err := next.Server(ctx).Request(ctx, request.Clone())
if err == nil {
return resp, err
return resp, nil
}
}
return nil, errors.Errorf("all candidates %#v fail", candidates)
Expand Down
13 changes: 7 additions & 6 deletions pkg/registry/common/dnsresolve/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net"
"net/url"
"strconv"

"github.com/pkg/errors"

Expand All @@ -45,27 +46,27 @@ type Resolver interface {
LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)
}

func parseIPPort(domain string) (ip, port interface{}) {
func parseIPPort(domain string) (ip net.IP, port string) {
u, err := url.Parse(domain)
if err != nil {
return nil, nil
return nil, ""
}

ip = net.ParseIP(u.Hostname())
if ip == nil {
return nil, nil
return nil, ""
}

if port = u.Port(); port == "" {
return nil, nil
return nil, ""
}

return ip, port
}

func resolveDomain(ctx context.Context, service, domain string, r Resolver) (*url.URL, error) {
ip, port := parseIPPort(domain)
if ip == nil || port == nil {
if ip == nil || port == "" {
serviceDomain := fmt.Sprintf("%v.%v", service, domain)

_, records, err := r.LookupSRV(ctx, "", "", serviceDomain)
Expand All @@ -75,7 +76,7 @@ func resolveDomain(ctx context.Context, service, domain string, r Resolver) (*ur
if len(records) == 0 {
return nil, errors.New("resolver.LookupSERV return empty result")
}
port = records[0].Port
port = strconv.Itoa(int(records[0].Port))

ips, err := r.LookupIPAddr(ctx, serviceDomain)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/registry/common/recvfd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package recvfd
Expand Down
1 change: 1 addition & 0 deletions pkg/registry/common/recvfd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

// Package recvfd provides an NSE registry server chain element that:
Expand Down
1 change: 1 addition & 0 deletions pkg/registry/common/recvfd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package recvfd_test
Expand Down
1 change: 1 addition & 0 deletions pkg/registry/common/sendfd/client_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

// Package sendfd provides a registry.NetworkServiceEndpointRegistryClient chain element to convert any unix file socket
Expand Down
3 changes: 2 additions & 1 deletion pkg/registry/common/sendfd/client_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//+build linux
//go:build linux
// +build linux

package sendfd_test

Expand Down
1 change: 1 addition & 0 deletions pkg/registry/common/sendfd/server_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package sendfd
Expand Down
3 changes: 2 additions & 1 deletion pkg/tools/fs/inode.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Cisco and/or its affiliates.
// Copyright (c) 2020-2021 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux || darwin || freebsd || netbsd || openbsd
// +build linux darwin freebsd netbsd openbsd

// Package fs provides common filesystem functions and utilities
Expand Down
1 change: 1 addition & 0 deletions pkg/tools/grpcfdutils/transceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

// Package grpcfdutils provides utilities for grpcfd library
Expand Down
2 changes: 1 addition & 1 deletion pkg/tools/opa/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func False(query string) CheckAccessFunc {
return func(result rego.ResultSet) (bool, error) {
b, err := t(result)
if err == nil {
return !b, err
return !b, nil
}
return b, err
}
Expand Down
14 changes: 11 additions & 3 deletions pkg/tools/prefixpool/prefixpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,9 @@ func extractPrefix(prefixes []string, prefixLen uint32) (retPrefix string, retLe
if prefixLen == uint32(parentLen) {
// We found required one.
resultPrefix := prefixes[idx]
resultPrefixes := append(prefixes[:idx], prefixes[idx+1:]...)
resultPrefixes := make([]string, 0, len(prefixes)-1)
resultPrefixes = append(resultPrefixes, prefixes[:idx]...)
resultPrefixes = append(resultPrefixes, prefixes[idx+1:]...)
// Lets remove from list and return
return resultPrefix, resultPrefixes, nil
} else if uint32(parentLen) < prefixLen && (parentLen > maxPrefix || maxPrefix == 0) {
Expand Down Expand Up @@ -450,7 +452,10 @@ func releasePrefixes(prefixes []string, released ...string) (remaining []string,
return prefixes, nil
}

allPrefixes := append(prefixes, released...)
allPrefixes := make([]string, 0, len(prefixes)+len(released))
allPrefixes = append(allPrefixes, prefixes...)
allPrefixes = append(allPrefixes, released...)

subnets, err := getSubnets(allPrefixes)
if err != nil {
return nil, err
Expand All @@ -473,7 +478,10 @@ func releasePrefixes(prefixes []string, released ...string) (remaining []string,
for basePrefix, value := range prefixByPrefixLen {
base := map[string]*net.IPNet{}

cvalue := append(newPrefixByPrefixLen[basePrefix], value...)
cvalue := make([]*net.IPNet, 0, len(newPrefixByPrefixLen[basePrefix])+len(value))
cvalue = append(cvalue, newPrefixByPrefixLen[basePrefix]...)
cvalue = append(cvalue, value...)

parentPrefix := []*net.IPNet{}
if len(cvalue) < 2 {
newPrefixByPrefixLen[basePrefix] = cvalue
Expand Down
1 change: 1 addition & 0 deletions pkg/tools/sandbox/grpc_utils_notwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !windows
// +build !windows

package sandbox
Expand Down