Skip to content

Commit

Permalink
fix linter issues after update golangci-lint version
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Tingaikin <[email protected]>
  • Loading branch information
denis-tingaikin committed Sep 12, 2022
1 parent aef323e commit 91b1778
Show file tree
Hide file tree
Showing 92 changed files with 533 additions and 420 deletions.
2 changes: 1 addition & 1 deletion pkg/networkservice/chains/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

// NewClient - returns case NSM client.
// - ctx - context for the lifecycle of the *Client* itself. Cancel when discarding the client.
// - ctx - context for the lifecycle of the *Client* itself. Cancel when discarding the client.
func NewClient(ctx context.Context, clientOpts ...Option) networkservice.NetworkServiceClient {
var opts = &clientOptions{
name: "client-" + uuid.New().String(),
Expand Down
6 changes: 4 additions & 2 deletions pkg/networkservice/chains/endpoint/combine.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2021 Doc.ai and/or its affiliates.
//
// Copyright (c) 2022 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,8 +23,8 @@ import "github.com/networkservicemesh/api/pkg/api/networkservice"
// Combine returns a new combined endpoint:
// * networkservice.NetworkServiceServer created by combineFun(eps)
// * networkservice.MonitorConnectionServer part is managed in the following way:
// * networkservice.ConnectionEventType_INITIAL_STATE_TRANSFER is merged to single event from all endpoints
// * rest events just go with no changes from all endpoints
// - networkservice.ConnectionEventType_INITIAL_STATE_TRANSFER is merged to single event from all endpoints
// - rest events just go with no changes from all endpoints
func Combine(combineFun func(servers []networkservice.NetworkServiceServer) networkservice.NetworkServiceServer, eps ...Endpoint) Endpoint {
var servers []networkservice.NetworkServiceServer
monitorServers := make(map[networkservice.MonitorConnectionServer]int)
Expand Down
4 changes: 2 additions & 2 deletions pkg/networkservice/chains/endpoint/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ import (
)

// Endpoint - aggregates the APIs:
// - networkservice.NetworkServiceServer
// - networkservice.MonitorConnectionServer
// - networkservice.NetworkServiceServer
// - networkservice.MonitorConnectionServer
type Endpoint interface {
networkservice.NetworkServiceServer
networkservice.MonitorConnectionServer
Expand Down
5 changes: 3 additions & 2 deletions pkg/networkservice/chains/nsmgr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ func WithURL(u string) Option {
var _ Nsmgr = (*nsmgrServer)(nil)

// NewServer - Creates a new Nsmgr
// tokenGenerator - authorization token generator
// options - a set of Nsmgr options.
//
// tokenGenerator - authorization token generator
// options - a set of Nsmgr options.
func NewServer(ctx context.Context, tokenGenerator token.GeneratorFunc, options ...Option) Nsmgr {
opts := &serverOptions{
authorizeServer: authorize.NewServer(authorize.Any()),
Expand Down
14 changes: 7 additions & 7 deletions pkg/networkservice/chains/nsmgrproxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (

// TestNSMGR_InterdomainUseCase covers simple interdomain scenario:
//
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy2 -> nsmgr2 ->forwarder2 -> nsmgr2 -> nse3
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy2 -> nsmgr2 ->forwarder2 -> nsmgr2 -> nse3
func TestNSMGR_InterdomainUseCase(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

Expand Down Expand Up @@ -246,8 +246,8 @@ func Test_NSEMovedFromInterdomainToFloatingUseCase(t *testing.T) {

// TestNSMGR_Interdomain_TwoNodesNSEs covers scenarion with connection from the one client to two endpoints from diffrenret clusters.
//
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy2 -> nsmgr2 ->forwarder2 -> nsmgr2 -> nse2
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy3 -> nsmgr3 ->forwarder3 -> nsmgr3 -> nse3
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy2 -> nsmgr2 ->forwarder2 -> nsmgr2 -> nse2
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy3 -> nsmgr3 ->forwarder3 -> nsmgr3 -> nse3
func TestNSMGR_Interdomain_TwoNodesNSEs(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

Expand Down Expand Up @@ -351,7 +351,7 @@ func TestNSMGR_Interdomain_TwoNodesNSEs(t *testing.T) {

// TestNSMGR_FloatingInterdomainUseCase covers simple interdomain scenario with resolving endpoint from floating registry:
//
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy2 -> nsmgr2 ->forwarder2 -> nsmgr2 -> nse3
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy2 -> nsmgr2 ->forwarder2 -> nsmgr2 -> nse3
func TestNSMGR_FloatingInterdomainUseCase(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

Expand Down Expand Up @@ -446,7 +446,7 @@ func TestNSMGR_FloatingInterdomainUseCase(t *testing.T) {
//
// registration: {"name": "[email protected]", "networkservice_names": ["[email protected]"]}
//
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy2 -> nsmgr2 ->forwarder2 -> nsmgr2 -> nse3
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy2 -> nsmgr2 ->forwarder2 -> nsmgr2 -> nse3
func TestNSMGR_FloatingInterdomainUseCase_FloatingNetworkServiceNameRegistration(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

Expand Down Expand Up @@ -528,8 +528,8 @@ func TestNSMGR_FloatingInterdomainUseCase_FloatingNetworkServiceNameRegistration
// TestNSMGR_FloatingInterdomain_FourClusters covers scenarion with connection from the one client to two endpoints
// from diffrenret clusters using floating registry for resolving endpoints.
//
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy2 -> nsmgr2 ->forwarder2 -> nsmgr2 -> nse2
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy3 -> nsmgr3 ->forwarder3 -> nsmgr3 -> nse3
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy2 -> nsmgr2 ->forwarder2 -> nsmgr2 -> nse2
// nsc -> nsmgr1 -> forwarder1 -> nsmgr1 -> nsmgr-proxy1 -> nsmg-proxy3 -> nsmgr3 ->forwarder3 -> nsmgr3 -> nse3
func TestNSMGR_FloatingInterdomain_FourClusters(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

Expand Down
28 changes: 15 additions & 13 deletions pkg/networkservice/common/begin/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Cisco and/or its affiliates.
// Copyright (c) 2021-2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -19,24 +19,24 @@ Package begin provides a chain element that can be put at the beginning of the c
but before any chain elements that would mutate the Connection on the return path.
the begin.New{Client,Server}() guarantee:
Scope
# Scope
All Request() or Close() events are scoped to a particular Connection, uniquely identified by its Connection.Id
# All Request() or Close() events are scoped to a particular Connection, uniquely identified by its Connection.Id
Exclusivity
# Exclusivity
Only one event is processed for a Connection.Id at a time
# Only one event is processed for a Connection.Id at a time
Order
# Order
Events for a given Connection.Id are processed in the order in which they are received
# Events for a given Connection.Id are processed in the order in which they are received
Close Correctness
# Close Correctness
When a Close(Connection) event is received, begin will replace the Connection provided with the last Connection
successfully returned from the chain for Connection.Id
Midchain Originated Events
# Midchain Originated Events
A midchain element may originate a Request() or Close() event to be processed
from the beginning of the chain (Timeout, Refresh,Heal):
Expand All @@ -58,7 +58,7 @@ Optionally you may use the CancelContext(context.Context) option:
If cancelContext is canceled prior to the processing of the event, the event processing will be skipped,
and the errCh returned simply closed.
Midchain Originated Request Event
# Midchain Originated Request Event
Example:
Expand All @@ -68,18 +68,19 @@ will use the networkservice.NetworkServiceRequest from the chain's last successf
with networkservice.NetworkServiceRequest.Connection replaced with the Connection returned by the chain's last
successfully completed Request() event
Chain Placement
# Chain Placement
begin.New{Server/Client} should always proceed any chain element which:
- Maintains state
- Mutates the Connection object along the return path of processing a Request() event.
Reasoning
# Reasoning
networkservice.NetworkService{Client,Server} processes two kinds of events:
- Request()
- Close()
Each Request() or Close() event is scoped to a networkservice.Connection, which can be uniquely identified by its Connection.Id
# Each Request() or Close() event is scoped to a networkservice.Connection, which can be uniquely identified by its Connection.Id
For a given Connection.Id, at most one event can be processed at a time (exclusivity).
For a given Connection.Id, events must be processed in the order they were received (order).
Expand All @@ -95,6 +96,7 @@ in the middle of the chain, but processed from the beginning of the chain. Exam
- A server timing out an expired Connection
- A client refreshing a Connection so that it does not expire
- A client healing from a lost Connection
In all of these cases, the Request() or Close() event should be processed starting at the beginning of the chain, to ensure
that all of the proper side effects occur within the chain.
*/
Expand Down
13 changes: 7 additions & 6 deletions pkg/networkservice/common/begin/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import (
)

// mergeConnection - preforms the three way merge of the returnedConnection, requestedConnection and connection
// returnedConnection - the Connection last returned from the begin.Request(...)
// requestedConnection - the Connection passed in to the begin.Request(...)
// currentConnection - the last value for the Connection in EventFactory. Since Refreshes, Heals, etc
// can result in changes that have *not* been returned from begin.Request(...) because
// they originated in events internal to the chain (instead of external via calls to
// begin.Request(...)) it is possible that connection differs from returnedConnection
//
// returnedConnection - the Connection last returned from the begin.Request(...)
// requestedConnection - the Connection passed in to the begin.Request(...)
// currentConnection - the last value for the Connection in EventFactory. Since Refreshes, Heals, etc
// can result in changes that have *not* been returned from begin.Request(...) because
// they originated in events internal to the chain (instead of external via calls to
// begin.Request(...)) it is possible that connection differs from returnedConnection
func mergeConnection(returnedConnection, requestedConnection, currentConnection *networkservice.Connection) *networkservice.Connection {
if returnedConnection == nil || currentConnection == nil {
return requestedConnection
Expand Down
4 changes: 2 additions & 2 deletions pkg/networkservice/common/clusterinfo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package clusterinfo

import (
"context"
"io/ioutil"
"os"

"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/networkservice"
Expand Down Expand Up @@ -50,7 +50,7 @@ func (n *clusterinfoServer) Request(ctx context.Context, request *networkservice

var m = make(map[string]string)

if b, err := ioutil.ReadFile(n.configPath); err == nil {
if b, err := os.ReadFile(n.configPath); err == nil {
_ = yaml.Unmarshal(b, &m)
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/networkservice/common/clusterinfo/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package clusterinfo_test

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -34,7 +33,7 @@ func TestReadClusterName(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

var path = filepath.Join(t.TempDir(), "clusterinfo.yaml")
require.NoError(t, ioutil.WriteFile(path, []byte("CLUSTER_NAME: my-cluster1"), os.ModePerm))
require.NoError(t, os.WriteFile(path, []byte("CLUSTER_NAME: my-cluster1"), os.ModePerm))

var s = clusterinfo.NewServer(clusterinfo.WithConfigPath(path))

Expand Down
8 changes: 5 additions & 3 deletions pkg/networkservice/common/discover/context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Cisco Systems, Inc.
// Copyright (c) 2020-2022 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -38,7 +38,8 @@ type NetworkServiceCandidates struct {
}

// WithCandidates -
// Wraps 'parent' in a new Context that has the Candidates
//
// Wraps 'parent' in a new Context that has the Candidates
func WithCandidates(parent context.Context, candidates []*registry.NetworkServiceEndpoint, service *registry.NetworkService) context.Context {
if parent == nil {
panic("cannot create context from nil parent")
Expand All @@ -50,7 +51,8 @@ func WithCandidates(parent context.Context, candidates []*registry.NetworkServic
}

// Candidates -
// Returns the Candidates
//
// Returns the Candidates
func Candidates(ctx context.Context) *NetworkServiceCandidates {
if rv, ok := ctx.Value(candidatesKey).(*NetworkServiceCandidates); ok {
return rv
Expand Down
3 changes: 2 additions & 1 deletion pkg/networkservice/common/discover/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ type discoverCandidatesServer struct {
}

// NewServer - creates a new NetworkServiceServer that can discover possible candidates for providing a requested
// Network Service and add it to the context.Context where it can be retrieved by Candidates(ctx)
//
// Network Service and add it to the context.Context where it can be retrieved by Candidates(ctx)
func NewServer(nsClient registry.NetworkServiceRegistryClient, nseClient registry.NetworkServiceEndpointRegistryClient) networkservice.NetworkServiceServer {
return &discoverCandidatesServer{
nseClient: nseClient,
Expand Down
15 changes: 7 additions & 8 deletions pkg/networkservice/common/excludedprefixes/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package excludedprefixes_test
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -50,7 +49,7 @@ func TestNewExcludedPrefixesService(t *testing.T) {
require.NoError(t, os.MkdirAll(dir, os.ModePerm))
testConfig := strings.Join(append([]string{"prefixes:"}, prefixes...), "\n- ")
configPath := filepath.Join(dir, defaultPrefixesFileName)
require.NoError(t, ioutil.WriteFile(configPath, []byte(testConfig), os.ModePerm))
require.NoError(t, os.WriteFile(configPath, []byte(testConfig), os.ModePerm))

server := chain.NewNetworkServiceServer(excludedprefixes.NewServer(context.Background(), excludedprefixes.WithConfigPath(configPath)), checkrequest.NewServer(t, func(t *testing.T, request *networkservice.NetworkServiceRequest) {
require.Equal(t, request.Connection.Context.IpContext.ExcludedPrefixes, prefixes)
Expand All @@ -70,14 +69,14 @@ func TestCheckReloadedPrefixes(t *testing.T) {

testConfig := strings.Join(append([]string{"prefixes:"}, prefixes...), "\n- ")
configPath := filepath.Join(dir, defaultPrefixesFileName)
require.NoError(t, ioutil.WriteFile(configPath, []byte(""), os.ModePerm))
require.NoError(t, os.WriteFile(configPath, []byte(""), os.ModePerm))

defer func() { _ = os.Remove(configPath) }()

server := chain.NewNetworkServiceServer(excludedprefixes.NewServer(context.Background(), excludedprefixes.WithConfigPath(configPath)))
req := request()

err := ioutil.WriteFile(configPath, []byte(testConfig), 0o600)
err := os.WriteFile(configPath, []byte(testConfig), 0o600)
require.NoError(t, err)

require.Eventually(t, func() bool {
Expand Down Expand Up @@ -114,7 +113,7 @@ func TestUniqueRequestPrefixes(t *testing.T) {

testConfig := strings.Join(append([]string{"prefixes:"}, prefixes...), "\n- ")
configPath := filepath.Join(dir, defaultPrefixesFileName)
require.NoError(t, ioutil.WriteFile(configPath, []byte(testConfig), os.ModePerm))
require.NoError(t, os.WriteFile(configPath, []byte(testConfig), os.ModePerm))
defer func() { _ = os.Remove(configPath) }()

server := chain.NewNetworkServiceServer(excludedprefixes.NewServer(context.Background(), excludedprefixes.WithConfigPath(configPath)), checkrequest.NewServer(t, func(t *testing.T, request *networkservice.NetworkServiceRequest) {
Expand Down Expand Up @@ -146,7 +145,7 @@ func TestFilePrefixesChanged(t *testing.T) {

testConfig := strings.Join(append([]string{"prefixes:"}, filePrefixes...), "\n- ")
configPath := filepath.Join(dir, defaultPrefixesFileName)
require.NoError(t, ioutil.WriteFile(configPath, []byte(testConfig), os.ModePerm))
require.NoError(t, os.WriteFile(configPath, []byte(testConfig), os.ModePerm))
defer func() { _ = os.Remove(configPath) }()

var prefixesAfterServer []string
Expand Down Expand Up @@ -176,7 +175,7 @@ func TestFilePrefixesChanged(t *testing.T) {

_, err := server.Request(context.Background(), req)

require.NoError(t, ioutil.WriteFile(configPath, []byte(strings.Join(append([]string{"prefixes:"}, newFilePrefixes...), "\n- ")), os.ModePerm))
require.NoError(t, os.WriteFile(configPath, []byte(strings.Join(append([]string{"prefixes:"}, newFilePrefixes...), "\n- ")), os.ModePerm))

require.Eventually(t, func() bool {
_, err = server.Request(context.Background(), req)
Expand Down Expand Up @@ -204,7 +203,7 @@ func testWaitForFile(t *testing.T, filePath string) {
require.NoError(t, err)
require.Empty(t, req.GetConnection().GetContext().GetIpContext().GetExcludedPrefixes())

require.NoError(t, ioutil.WriteFile(filePath, []byte(testConfig), os.ModePerm))
require.NoError(t, os.WriteFile(filePath, []byte(testConfig), os.ModePerm))

defer func() { _ = os.Remove(filePath) }()
require.Eventually(t, func() bool {
Expand Down
5 changes: 3 additions & 2 deletions pkg/networkservice/common/externalips/server_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
//
// Copyright (c) 2022 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,7 +20,6 @@ package externalips_test

import (
"context"
"io/ioutil"
"net"
"os"
"path"
Expand Down Expand Up @@ -96,7 +97,7 @@ func TestExternalIPsServer_NoFile(t *testing.T) {
}))
_, err := checkChain.Request(context.Background(), &networkservice.NetworkServiceRequest{})
require.NoError(t, err)
err = ioutil.WriteFile(filePath, []byte(internalIP.String()+": "+externalIP.String()), os.ModePerm)
err = os.WriteFile(filePath, []byte(internalIP.String()+": "+externalIP.String()), os.ModePerm)
require.NoError(t, err)
require.Eventually(t, func() bool {
var result bool
Expand Down
3 changes: 3 additions & 0 deletions pkg/networkservice/common/journal/server_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
//
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,6 +15,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package journal_test

import (
Expand Down
Loading

0 comments on commit 91b1778

Please sign in to comment.