diff --git a/pkg/networkservice/chains/client/client.go b/pkg/networkservice/chains/client/client.go index 394a55122..2d84d198a 100644 --- a/pkg/networkservice/chains/client/client.go +++ b/pkg/networkservice/chains/client/client.go @@ -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(), diff --git a/pkg/networkservice/chains/endpoint/combine.go b/pkg/networkservice/chains/endpoint/combine.go index 56d98f644..67f08c190 100644 --- a/pkg/networkservice/chains/endpoint/combine.go +++ b/pkg/networkservice/chains/endpoint/combine.go @@ -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"); @@ -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) diff --git a/pkg/networkservice/chains/endpoint/server.go b/pkg/networkservice/chains/endpoint/server.go index 480cc6e80..59b8694c6 100644 --- a/pkg/networkservice/chains/endpoint/server.go +++ b/pkg/networkservice/chains/endpoint/server.go @@ -47,8 +47,8 @@ import ( ) // Endpoint - aggregates the APIs: -// - networkservice.NetworkServiceServer -// - networkservice.MonitorConnectionServer +// - networkservice.NetworkServiceServer +// - networkservice.MonitorConnectionServer type Endpoint interface { networkservice.NetworkServiceServer networkservice.MonitorConnectionServer diff --git a/pkg/networkservice/chains/nsmgr/server.go b/pkg/networkservice/chains/nsmgr/server.go index 856f46f22..f0c6557c7 100644 --- a/pkg/networkservice/chains/nsmgr/server.go +++ b/pkg/networkservice/chains/nsmgr/server.go @@ -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()), diff --git a/pkg/networkservice/chains/nsmgrproxy/server_test.go b/pkg/networkservice/chains/nsmgrproxy/server_test.go index 88122df76..1253adc34 100644 --- a/pkg/networkservice/chains/nsmgrproxy/server_test.go +++ b/pkg/networkservice/chains/nsmgrproxy/server_test.go @@ -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) }) @@ -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) }) @@ -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) }) @@ -446,7 +446,7 @@ func TestNSMGR_FloatingInterdomainUseCase(t *testing.T) { // // registration: {"name": "nse@floating.domain", "networkservice_names": ["my-service-interdomain@floating.domain"]} // -// 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) }) @@ -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) }) diff --git a/pkg/networkservice/common/begin/doc.go b/pkg/networkservice/common/begin/doc.go index fde651f1e..cbc069855 100644 --- a/pkg/networkservice/common/begin/doc.go +++ b/pkg/networkservice/common/begin/doc.go @@ -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 // @@ -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): @@ -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: @@ -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). @@ -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. */ diff --git a/pkg/networkservice/common/begin/merge.go b/pkg/networkservice/common/begin/merge.go index 54395ef89..de007e9ee 100644 --- a/pkg/networkservice/common/begin/merge.go +++ b/pkg/networkservice/common/begin/merge.go @@ -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 diff --git a/pkg/networkservice/common/clusterinfo/server.go b/pkg/networkservice/common/clusterinfo/server.go index 7871506c5..5c22887c1 100644 --- a/pkg/networkservice/common/clusterinfo/server.go +++ b/pkg/networkservice/common/clusterinfo/server.go @@ -19,7 +19,7 @@ package clusterinfo import ( "context" - "io/ioutil" + "os" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" @@ -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) } diff --git a/pkg/networkservice/common/clusterinfo/server_test.go b/pkg/networkservice/common/clusterinfo/server_test.go index 0c9e3da2e..45805a15c 100644 --- a/pkg/networkservice/common/clusterinfo/server_test.go +++ b/pkg/networkservice/common/clusterinfo/server_test.go @@ -18,7 +18,6 @@ package clusterinfo_test import ( "context" - "io/ioutil" "os" "path/filepath" "testing" @@ -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)) diff --git a/pkg/networkservice/common/discover/context.go b/pkg/networkservice/common/discover/context.go index e6820ee92..d151da086 100644 --- a/pkg/networkservice/common/discover/context.go +++ b/pkg/networkservice/common/discover/context.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco Systems, Inc. +// Copyright (c) 2020-2022 Cisco Systems, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -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") @@ -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 diff --git a/pkg/networkservice/common/discover/server.go b/pkg/networkservice/common/discover/server.go index 89b3a22d4..46ff375b5 100644 --- a/pkg/networkservice/common/discover/server.go +++ b/pkg/networkservice/common/discover/server.go @@ -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, diff --git a/pkg/networkservice/common/excludedprefixes/server_test.go b/pkg/networkservice/common/excludedprefixes/server_test.go index 4c9b4df79..d0efe34fb 100644 --- a/pkg/networkservice/common/excludedprefixes/server_test.go +++ b/pkg/networkservice/common/excludedprefixes/server_test.go @@ -21,7 +21,6 @@ package excludedprefixes_test import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -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) @@ -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 { @@ -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) { @@ -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 @@ -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) @@ -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 { diff --git a/pkg/networkservice/common/externalips/server_test.go b/pkg/networkservice/common/externalips/server_test.go index 96ddf00a4..f25b0cb5d 100644 --- a/pkg/networkservice/common/externalips/server_test.go +++ b/pkg/networkservice/common/externalips/server_test.go @@ -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"); @@ -18,7 +20,6 @@ package externalips_test import ( "context" - "io/ioutil" "net" "os" "path" @@ -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 diff --git a/pkg/networkservice/common/journal/server_test.go b/pkg/networkservice/common/journal/server_test.go index 472ef8a3a..155ac8b34 100644 --- a/pkg/networkservice/common/journal/server_test.go +++ b/pkg/networkservice/common/journal/server_test.go @@ -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"); @@ -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 ( diff --git a/pkg/networkservice/common/mechanisms/checkmechanism/check_client_sets_mechanism_preferences.go b/pkg/networkservice/common/mechanisms/checkmechanism/check_client_sets_mechanism_preferences.go index 5f31c05c6..a9f459883 100644 --- a/pkg/networkservice/common/mechanisms/checkmechanism/check_client_sets_mechanism_preferences.go +++ b/pkg/networkservice/common/mechanisms/checkmechanism/check_client_sets_mechanism_preferences.go @@ -37,13 +37,14 @@ type checkClientSetsMechanismPreferences struct { } // CheckClientSetsMechanismPreferences - returns a NetworkServiceClient that will check to make sure that the -// clientUnderTest correctly sets the MechanismPreferences to include -// a mechanism of type mechanismType -// t - *testing.T for checking -// clientUnderTest - client we are testing -// mechanismType - Mechanism.Type implemented by clientUnderTest -// mechanismCheck - function to check for any parameters that should be present in -// the MechanismPreference +// +// clientUnderTest correctly sets the MechanismPreferences to include +// a mechanism of type mechanismType +// t - *testing.T for checking +// clientUnderTest - client we are testing +// mechanismType - Mechanism.Type implemented by clientUnderTest +// mechanismCheck - function to check for any parameters that should be present in +// the MechanismPreference func CheckClientSetsMechanismPreferences(t *testing.T, clientUnderTest networkservice.NetworkServiceClient, mechanismType string, mechanismCheck func(*testing.T, *networkservice.Mechanism)) networkservice.NetworkServiceClient { rv := &checkClientSetsMechanismPreferences{} rv.NetworkServiceClient = chain.NewNetworkServiceClient( diff --git a/pkg/networkservice/common/mechanisms/checkmechanism/check_context.go b/pkg/networkservice/common/mechanisms/checkmechanism/check_context.go index 9278c886a..fa34d69bf 100644 --- a/pkg/networkservice/common/mechanisms/checkmechanism/check_context.go +++ b/pkg/networkservice/common/mechanisms/checkmechanism/check_context.go @@ -31,11 +31,12 @@ import ( ) // CheckClientContextOnReturn - returns a NetworkServiceClient that will check the state of the context.Context -// after the clientUnderTest has returned -// t - *testing.T for checks -// clientUnderTest - client we are testing - presumed to implement a mechanism -// mechanismType - Mechanism.Type implemented by the clientUnderTest -// check - function to check the state of the context.Context after the clientUnderTest has returned +// +// after the clientUnderTest has returned +// t - *testing.T for checks +// clientUnderTest - client we are testing - presumed to implement a mechanism +// mechanismType - Mechanism.Type implemented by the clientUnderTest +// check - function to check the state of the context.Context after the clientUnderTest has returned func CheckClientContextOnReturn(t *testing.T, clientUnderTest networkservice.NetworkServiceClient, mechanismType string, check func(*testing.T, context.Context)) networkservice.NetworkServiceClient { return chain.NewNetworkServiceClient( checkcontextonreturn.NewClient(t, check), @@ -48,14 +49,15 @@ func CheckClientContextOnReturn(t *testing.T, clientUnderTest networkservice.Net } // CheckClientContextAfter - returns a NetworkServiceClient that will check the state of the context.Context after it has left -// the clientUnderTest. Note: it should almost always be the case that there are no side effects -// related to implementing the Mechanism at this point, as the clientUnderTest can't know what to -// do until after the elements after it have returned a fully complete Connection. -// t - *testing.T for checks -// clientUnderTest - client we are testing - presumed to implement a mechanism -// mechanismType - Mechanism.Type implemented by the clientUnderTest -// check - function to check that the clientUnderTest has not taken action to implement the Mechanism -// (as it cannot know what to do at this stage) +// +// the clientUnderTest. Note: it should almost always be the case that there are no side effects +// related to implementing the Mechanism at this point, as the clientUnderTest can't know what to +// do until after the elements after it have returned a fully complete Connection. +// t - *testing.T for checks +// clientUnderTest - client we are testing - presumed to implement a mechanism +// mechanismType - Mechanism.Type implemented by the clientUnderTest +// check - function to check that the clientUnderTest has not taken action to implement the Mechanism +// (as it cannot know what to do at this stage) func CheckClientContextAfter(t *testing.T, client networkservice.NetworkServiceClient, mechanismType string, check func(*testing.T, context.Context)) networkservice.NetworkServiceClient { return chain.NewNetworkServiceClient( client, @@ -68,12 +70,13 @@ func CheckClientContextAfter(t *testing.T, client networkservice.NetworkServiceC } // CheckContextAfterServer - returns a NetworkServiceServer that will check the state of the context.Context after it has -// left the serverUnderTest. At this time the context.Context should contain any side effects needed -// to implement the Mechanism, as it should have a complete Connection to work with. -// t - *testing.T for checks -// serverUnderTest - server we are testing - presumed to implement a mechanism -// mechanismType - Mechanism.Type implemented by the serverUnderTest -// check - function to check that the serverUnderTest has taken action to implement the Mechanism +// +// left the serverUnderTest. At this time the context.Context should contain any side effects needed +// to implement the Mechanism, as it should have a complete Connection to work with. +// t - *testing.T for checks +// serverUnderTest - server we are testing - presumed to implement a mechanism +// mechanismType - Mechanism.Type implemented by the serverUnderTest +// check - function to check that the serverUnderTest has taken action to implement the Mechanism func CheckContextAfterServer(t *testing.T, serverUnderTest networkservice.NetworkServiceServer, mechanismType string, check func(*testing.T, context.Context)) networkservice.NetworkServiceServer { return chain.NewNetworkServiceServer( mechanisms.NewServer( diff --git a/pkg/networkservice/common/mechanisms/checkmechanism/client_suite.go b/pkg/networkservice/common/mechanisms/checkmechanism/client_suite.go index b783b45b2..f3d21b834 100644 --- a/pkg/networkservice/common/mechanisms/checkmechanism/client_suite.go +++ b/pkg/networkservice/common/mechanisms/checkmechanism/client_suite.go @@ -42,17 +42,18 @@ type ClientSuite struct { } // NewClientSuite - returns a ClientTestSuite -// clientUnderTest - the client we are testing to make sure it correctly implements a Mechanism -// configureContext - a function that is applied to context.Background to make sure anything -// needed by the clientUnderTest is present in the context.Context -// mechanismType - Mechanism.Type implemented by the clientUnderTest -// mechanismCheck - function to check that the clientUnderTest has properly added Mechanism.Parameters -// to the Mechanism it has appended to MechanismPreferences -// contextOnReturnCheck - function to check that the context.Context *after* clientUnderTest has returned are correct -// contextCheck - function to check that the clientUnderTest introduces no side effects to the context.Context -// before calling the next element in the chain -// request - NetworkServiceRequest to be used for testing -// connClose - Connection to be used for testing Close(...) +// +// clientUnderTest - the client we are testing to make sure it correctly implements a Mechanism +// configureContext - a function that is applied to context.Background to make sure anything +// needed by the clientUnderTest is present in the context.Context +// mechanismType - Mechanism.Type implemented by the clientUnderTest +// mechanismCheck - function to check that the clientUnderTest has properly added Mechanism.Parameters +// to the Mechanism it has appended to MechanismPreferences +// contextOnReturnCheck - function to check that the context.Context *after* clientUnderTest has returned are correct +// contextCheck - function to check that the clientUnderTest introduces no side effects to the context.Context +// before calling the next element in the chain +// request - NetworkServiceRequest to be used for testing +// connClose - Connection to be used for testing Close(...) func NewClientSuite( clientUnderTest networkservice.NetworkServiceClient, configureContext func(ctx context.Context) context.Context, @@ -95,7 +96,8 @@ func (m *ClientSuite) TestPropogatesOpts() { } // TestSetsMechanismPreference - test that the clientUnderTest correctly sets MechanismPreferences for the Mechanism it implements -// before calling the next element in the chain +// +// before calling the next element in the chain func (m *ClientSuite) TestSetsMechanismPreference() { check := CheckClientSetsMechanismPreferences(m.T(), m.clientUnderTest, diff --git a/pkg/networkservice/common/mechanisms/checkmechanism/server_suite.go b/pkg/networkservice/common/mechanisms/checkmechanism/server_suite.go index 031bd9f39..9b0284d71 100644 --- a/pkg/networkservice/common/mechanisms/checkmechanism/server_suite.go +++ b/pkg/networkservice/common/mechanisms/checkmechanism/server_suite.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -43,14 +43,15 @@ type ServerSuite struct { } // NewServerSuite - returns a ServerSuite -// serverUnderTest - the server being tested to make sure it correctly implements a Mechanism -// configureContext - a function that is applied to context.Background to make sure anything -// needed by the serverUnderTest is present in the context.Context -// mechanismType - Mechanism.Type implemented by the serverUnderTest -// contextCheck - function to check that the serverUnderTest introduces all needed side effects to the context.Context -// before calling the next element in the chain -// request - NetworkServiceRequest to be used for testing -// connClose - Connection to be used for testing Close(...) +// +// serverUnderTest - the server being tested to make sure it correctly implements a Mechanism +// configureContext - a function that is applied to context.Background to make sure anything +// needed by the serverUnderTest is present in the context.Context +// mechanismType - Mechanism.Type implemented by the serverUnderTest +// contextCheck - function to check that the serverUnderTest introduces all needed side effects to the context.Context +// before calling the next element in the chain +// request - NetworkServiceRequest to be used for testing +// connClose - Connection to be used for testing Close(...) func NewServerSuite( serverUnderTest networkservice.NetworkServiceServer, configureContext func(ctx context.Context) context.Context, @@ -94,7 +95,8 @@ func (m *ServerSuite) TestContextAfter() { } // TestMechanismAfter - test to make sure that any changes the server should have made to the Request.Connection.Mechanism -// before calling the next chain element have been made +// +// before calling the next chain element have been made func (m *ServerSuite) TestMechanismAfter() { contract := chain.NewNetworkServiceServer( mechanisms.NewServer( diff --git a/pkg/networkservice/common/mechanisms/server.go b/pkg/networkservice/common/mechanisms/server.go index 3d14ce495..96d786f1b 100644 --- a/pkg/networkservice/common/mechanisms/server.go +++ b/pkg/networkservice/common/mechanisms/server.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020-2021 Cisco and/or its affiliates. -// // Copyright (c) 2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,11 +35,12 @@ type mechanismsServer struct { } // NewServer - returns new NetworkServiceServer chain element that will attempt to meet the request.MechanismPreferences using -// the provided maps of MechanismType to NetworkServiceServer -// - mechanisms -// key: mechanismType -// value: NetworkServiceServer that only handles the work for the specified mechanismType -// Note: Supplied NetworkServiceServer elements should not call next.Server(ctx).{Request,Close} themselves +// +// the provided maps of MechanismType to NetworkServiceServer +// - mechanisms +// key: mechanismType +// value: NetworkServiceServer that only handles the work for the specified mechanismType +// Note: Supplied NetworkServiceServer elements should not call next.Server(ctx).{Request,Close} themselves func NewServer(mechanisms map[string]networkservice.NetworkServiceServer) networkservice.NetworkServiceServer { rv := &mechanismsServer{ mechanisms: make(map[string]networkservice.NetworkServiceServer), diff --git a/pkg/networkservice/common/monitor/server.go b/pkg/networkservice/common/monitor/server.go index f56c32a90..b88e619c6 100644 --- a/pkg/networkservice/common/monitor/server.go +++ b/pkg/networkservice/common/monitor/server.go @@ -41,14 +41,14 @@ type monitorServer struct { } // NewServer - creates a NetworkServiceServer chain element that will properly update a MonitorConnectionServer -// - monitorServerPtr - *networkservice.MonitorConnectionServer. Since networkservice.MonitorConnectionServer is an interface -// (and thus a pointer) *networkservice.MonitorConnectionServer is a double pointer. Meaning it -// points to a place that points to a place that implements networkservice.MonitorConnectionServer -// This is done so that we can preserve the return of networkservice.NetworkServer and use -// NewServer(...) as any other chain element constructor, but also get back a -// networkservice.MonitorConnectionServer that can be used either standalone or in a -// networkservice.MonitorConnectionServer chain -// chainCtx - context for lifecycle management +// - monitorServerPtr - *networkservice.MonitorConnectionServer. Since networkservice.MonitorConnectionServer is an interface +// (and thus a pointer) *networkservice.MonitorConnectionServer is a double pointer. Meaning it +// points to a place that points to a place that implements networkservice.MonitorConnectionServer +// This is done so that we can preserve the return of networkservice.NetworkServer and use +// NewServer(...) as any other chain element constructor, but also get back a +// networkservice.MonitorConnectionServer that can be used either standalone or in a +// networkservice.MonitorConnectionServer chain +// chainCtx - context for lifecycle management func NewServer(chainCtx context.Context, monitorServerPtr *networkservice.MonitorConnectionServer) networkservice.NetworkServiceServer { *monitorServerPtr = newMonitorConnectionServer(chainCtx) return &monitorServer{ diff --git a/pkg/networkservice/common/null/client.go b/pkg/networkservice/common/null/client.go index 7293e9514..f4315b23c 100644 --- a/pkg/networkservice/common/null/client.go +++ b/pkg/networkservice/common/null/client.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. -// // Copyright (c) 2020 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2022 Cisco Systems, Inc. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,7 +34,8 @@ import ( type nullClient struct{} // NewClient - returns a new null client that does nothing but call next.Client(ctx).{Request/Close} and return the result -// This is very useful in testing +// +// This is very useful in testing func NewClient() networkservice.NetworkServiceClient { return &nullClient{} } diff --git a/pkg/networkservice/common/null/server.go b/pkg/networkservice/common/null/server.go index a9bb5824c..ab516004c 100644 --- a/pkg/networkservice/common/null/server.go +++ b/pkg/networkservice/common/null/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -28,7 +28,8 @@ import ( type nullServer struct{} // NewServer - returns a new null NetworkServiceServer that does nothing but call next.Server(ctx).{Request/Close} -// and return the response +// +// and return the response func NewServer() networkservice.NetworkServiceServer { return &nullServer{} } diff --git a/pkg/networkservice/common/policyroute/server_test.go b/pkg/networkservice/common/policyroute/server_test.go index 4f11301fd..f0501f347 100644 --- a/pkg/networkservice/common/policyroute/server_test.go +++ b/pkg/networkservice/common/policyroute/server_test.go @@ -18,7 +18,6 @@ package policyroute_test import ( "context" - "io/ioutil" "os" "path/filepath" "sync/atomic" @@ -107,7 +106,7 @@ func TestCheckReloadedPolicies(t *testing.T) { require.NoError(t, os.MkdirAll(dir, os.ModePerm)) configBytes, _ := yaml.Marshal(policies) configPath := filepath.Join(dir, defaultPrefixesFileName) - require.NoError(t, ioutil.WriteFile(configPath, []byte(""), os.ModePerm)) + require.NoError(t, os.WriteFile(configPath, []byte(""), os.ModePerm)) getter := newPolicyRoutesGetter(chainCtx, configPath) @@ -116,7 +115,7 @@ func TestCheckReloadedPolicies(t *testing.T) { ) // Write policies to file - require.NoError(t, ioutil.WriteFile(configPath, configBytes, os.ModePerm)) + require.NoError(t, os.WriteFile(configPath, configBytes, os.ModePerm)) // Initial request already has source Ip address srcIPAddr := "172.16.2.200/24" @@ -140,7 +139,7 @@ func TestCheckReloadedPolicies(t *testing.T) { // Update policies - remove the first one policies = policies[1:] configBytes, _ = yaml.Marshal(policies) - require.NoError(t, ioutil.WriteFile(configPath, configBytes, os.ModePerm)) + require.NoError(t, os.WriteFile(configPath, configBytes, os.ModePerm)) require.Eventually(t, func() bool { _, err := server.Request(context.Background(), req) diff --git a/pkg/networkservice/common/refresh/client_utils_test.go b/pkg/networkservice/common/refresh/client_utils_test.go index 0a3395c31..47c2b97e3 100644 --- a/pkg/networkservice/common/refresh/client_utils_test.go +++ b/pkg/networkservice/common/refresh/client_utils_test.go @@ -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"); @@ -93,11 +95,11 @@ func (c *countClient) GetLastRequest() *networkservice.NetworkServiceRequest { // request aren't too fast or too slow. // // Usage details: -// * Each client Request() should be wrapped in beforeRequest()/afterRequest() -// calls. Same for Close() and beforeClose()/afterClose(). -// * Caveat: parallel client initiated requests aren't supported by this tester. -// * To distinguish between different requests, the value of -// `Connection.Context.ExtraContext[connectionMarker]` is used as a marker. +// - Each client Request() should be wrapped in beforeRequest()/afterRequest() +// calls. Same for Close() and beforeClose()/afterClose(). +// - Caveat: parallel client initiated requests aren't supported by this tester. +// - To distinguish between different requests, the value of +// `Connection.Context.ExtraContext[connectionMarker]` is used as a marker. type refreshTesterServer struct { t *testing.T minDuration time.Duration diff --git a/pkg/networkservice/common/swapip/client_test.go b/pkg/networkservice/common/swapip/client_test.go index 662705831..d14245201 100644 --- a/pkg/networkservice/common/swapip/client_test.go +++ b/pkg/networkservice/common/swapip/client_test.go @@ -18,7 +18,6 @@ package swapip_test import ( "context" - "io/ioutil" "os" "path/filepath" "testing" @@ -46,10 +45,10 @@ func TestSwapIPClient_Request(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10000) defer cancel() - err := ioutil.WriteFile(p1, []byte(`172.16.2.10: 172.16.1.10`), os.ModePerm) + err := os.WriteFile(p1, []byte(`172.16.2.10: 172.16.1.10`), os.ModePerm) require.NoError(t, err) - err = ioutil.WriteFile(p2, []byte(`172.16.2.100: 172.16.1.100`), os.ModePerm) + err = os.WriteFile(p2, []byte(`172.16.2.100: 172.16.1.100`), os.ModePerm) require.NoError(t, err) ch1 := convertBytesChToMapCh(fs.WatchFile(ctx, p1)) diff --git a/pkg/networkservice/common/swapip/server_test.go b/pkg/networkservice/common/swapip/server_test.go index 170e78ab4..897a73280 100644 --- a/pkg/networkservice/common/swapip/server_test.go +++ b/pkg/networkservice/common/swapip/server_test.go @@ -20,7 +20,6 @@ package swapip_test import ( "context" - "io/ioutil" "os" "path/filepath" "testing" @@ -48,10 +47,10 @@ func TestSwapIPServer_Request(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - err := ioutil.WriteFile(p1, []byte(`172.16.2.10: 172.16.1.10`), os.ModePerm) + err := os.WriteFile(p1, []byte(`172.16.2.10: 172.16.1.10`), os.ModePerm) require.NoError(t, err) - err = ioutil.WriteFile(p2, []byte(`172.16.2.100: 172.16.1.100`), os.ModePerm) + err = os.WriteFile(p2, []byte(`172.16.2.100: 172.16.1.100`), os.ModePerm) require.NoError(t, err) ch1 := convertBytesChToMapCh(fs.WatchFile(ctx, p1)) diff --git a/pkg/networkservice/common/timeout/server.go b/pkg/networkservice/common/timeout/server.go index 084ff3780..f82eb2ff0 100644 --- a/pkg/networkservice/common/timeout/server.go +++ b/pkg/networkservice/common/timeout/server.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020 Cisco Systems, Inc. -// // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2022 Cisco Systems, Inc. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -42,7 +42,8 @@ type timeoutServer struct { } // NewServer - creates a new NetworkServiceServer chain element that implements timeout of expired connections -// for the subsequent chain elements. +// +// for the subsequent chain elements. func NewServer(ctx context.Context) networkservice.NetworkServiceServer { return &timeoutServer{ chainCtx: ctx, diff --git a/pkg/networkservice/common/updatepath/client.go b/pkg/networkservice/common/updatepath/client.go index 318970881..7af557dd0 100644 --- a/pkg/networkservice/common/updatepath/client.go +++ b/pkg/networkservice/common/updatepath/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco Systems, Inc. +// Copyright (c) 2020-2022 Cisco Systems, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -32,7 +32,8 @@ type updatePathClient struct { } // NewClient - creates a new updatePath client to update connection path. -// name - name of the client +// +// name - name of the client // // Workflow are documented in common.go func NewClient(name string) networkservice.NetworkServiceClient { diff --git a/pkg/networkservice/common/updatepath/common.go b/pkg/networkservice/common/updatepath/common.go index db3f49202..12f9ada85 100644 --- a/pkg/networkservice/common/updatepath/common.go +++ b/pkg/networkservice/common/updatepath/common.go @@ -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"); @@ -24,15 +26,15 @@ import ( ) /* - Logic for Update path: +Logic for Update path: - 0. if Index == 0, and there is no current segment will add one. - 1. If current path segment.Name is equal to segmentName passed, it will just update current connection.Id and exit. - 2. If current path segment.Name is not equal to segmentName: - 2.0 if current path segment.Id is not equal to current connection.Id, will return error. - 2.1 if path has next segment available, but next name is not equal to segmentName, will update both next name and connection.Id. - 2.2 if no next path segment available, it will add one more path segment and generate new Id, update connection.Id. - 2.3 if path has next segment available and next name is segmentName, take Id from next path segment. + 0. if Index == 0, and there is no current segment will add one. + 1. If current path segment.Name is equal to segmentName passed, it will just update current connection.Id and exit. + 2. If current path segment.Name is not equal to segmentName: + 2.0 if current path segment.Id is not equal to current connection.Id, will return error. + 2.1 if path has next segment available, but next name is not equal to segmentName, will update both next name and connection.Id. + 2.2 if no next path segment available, it will add one more path segment and generate new Id, update connection.Id. + 2.3 if path has next segment available and next name is segmentName, take Id from next path segment. */ func updatePath(conn *networkservice.Connection, segmentName string) (*networkservice.Connection, uint32, error) { if conn == nil { diff --git a/pkg/networkservice/common/updatepath/server.go b/pkg/networkservice/common/updatepath/server.go index f398e2b10..ef9bcbed0 100644 --- a/pkg/networkservice/common/updatepath/server.go +++ b/pkg/networkservice/common/updatepath/server.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020-2021 Cisco Systems, Inc. -// // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2022 Cisco Systems, Inc. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,7 +34,8 @@ type updatePathServer struct { } // NewServer - creates a new updatePath client to update connection path. -// name - name of the client +// +// name - name of the client // // Workflow are documented in common.go func NewServer(name string) networkservice.NetworkServiceServer { diff --git a/pkg/networkservice/common/updatetoken/server.go b/pkg/networkservice/common/updatetoken/server.go index 85cf92118..65669e499 100644 --- a/pkg/networkservice/common/updatetoken/server.go +++ b/pkg/networkservice/common/updatetoken/server.go @@ -34,7 +34,7 @@ type updateTokenServer struct { } // NewServer - creates a NetworkServiceServer chain element to update the Connection token information -// - name - the name of the NetworkServiceServer of which the chain element is part +// - name - the name of the NetworkServiceServer of which the chain element is part func NewServer(tokenGenerator token.GeneratorFunc) networkservice.NetworkServiceServer { return &updateTokenServer{ tokenGenerator: tokenGenerator, diff --git a/pkg/networkservice/connectioncontext/dnscontext/client.go b/pkg/networkservice/connectioncontext/dnscontext/client.go index c8841613a..9ca42b321 100644 --- a/pkg/networkservice/connectioncontext/dnscontext/client.go +++ b/pkg/networkservice/connectioncontext/dnscontext/client.go @@ -20,7 +20,6 @@ package dnscontext import ( "context" - "io/ioutil" "os" "github.com/golang/protobuf/ptypes/empty" @@ -97,7 +96,7 @@ func (c *dnsContextClient) Close(ctx context.Context, conn *networkservice.Conne } func (c *dnsContextClient) restoreResolvConf() { - originalResolvConf, err := ioutil.ReadFile(c.storedResolvConfigPath) + originalResolvConf, err := os.ReadFile(c.storedResolvConfigPath) if err != nil || len(originalResolvConf) == 0 { return } @@ -108,11 +107,11 @@ func (c *dnsContextClient) storeOriginalResolvConf() { if _, err := os.Stat(c.storedResolvConfigPath); err == nil { return } - originalResolvConf, err := ioutil.ReadFile(c.resolveConfigPath) + originalResolvConf, err := os.ReadFile(c.resolveConfigPath) if err != nil { return } - _ = ioutil.WriteFile(c.storedResolvConfigPath, originalResolvConf, os.ModePerm) + _ = os.WriteFile(c.storedResolvConfigPath, originalResolvConf, os.ModePerm) } func (c *dnsContextClient) initialize() { diff --git a/pkg/networkservice/connectioncontext/dnscontext/client_test.go b/pkg/networkservice/connectioncontext/dnscontext/client_test.go index 7dcc59aab..6e501bbb5 100644 --- a/pkg/networkservice/connectioncontext/dnscontext/client_test.go +++ b/pkg/networkservice/connectioncontext/dnscontext/client_test.go @@ -20,7 +20,6 @@ package dnscontext_test import ( "context" - "io/ioutil" "os" "path/filepath" "runtime" @@ -44,7 +43,7 @@ func Test_DNSContextClient_Usecases(t *testing.T) { resolveConfigPath := filepath.Join(t.TempDir(), "resolv.conf") - err := ioutil.WriteFile(resolveConfigPath, []byte("nameserver 8.8.4.4\nsearch example.com\n"), os.ModePerm) + err := os.WriteFile(resolveConfigPath, []byte("nameserver 8.8.4.4\nsearch example.com\n"), os.ModePerm) require.NoError(t, err) client := chain.NewNetworkServiceClient( @@ -79,7 +78,7 @@ func Test_DNSContextClient_Usecases(t *testing.T) { func requireFileChanged(ctx context.Context, t *testing.T, location, expected string) { var r string for ctx.Err() == nil { - b, err := ioutil.ReadFile(filepath.Clean(location)) + b, err := os.ReadFile(filepath.Clean(location)) r = string(b) if err == nil && r == expected { return diff --git a/pkg/networkservice/connectioncontext/dnscontext/resolvconf.go b/pkg/networkservice/connectioncontext/dnscontext/resolvconf.go index 1ebedb6e0..344563168 100644 --- a/pkg/networkservice/connectioncontext/dnscontext/resolvconf.go +++ b/pkg/networkservice/connectioncontext/dnscontext/resolvconf.go @@ -19,7 +19,6 @@ package dnscontext import ( - "io/ioutil" "os" "strings" ) @@ -43,7 +42,7 @@ func openResolveConfig(p string) (*resolveConfig, error) { } func (r *resolveConfig) readProperties() error { - b, err := ioutil.ReadFile(r.path) + b, err := os.ReadFile(r.path) if err != nil { return err } @@ -81,7 +80,7 @@ func (r *resolveConfig) Save() error { _, _ = sb.WriteRune('\n') } } - return ioutil.WriteFile(r.path, []byte(sb.String()), os.ModePerm) + return os.WriteFile(r.path, []byte(sb.String()), os.ModePerm) } const ( diff --git a/pkg/networkservice/connectioncontext/dnscontext/resolvconf_test.go b/pkg/networkservice/connectioncontext/dnscontext/resolvconf_test.go index 43ac065bb..106007bd0 100644 --- a/pkg/networkservice/connectioncontext/dnscontext/resolvconf_test.go +++ b/pkg/networkservice/connectioncontext/dnscontext/resolvconf_test.go @@ -17,7 +17,6 @@ package dnscontext import ( - "io/ioutil" "os" "path" "path/filepath" @@ -29,7 +28,7 @@ import ( func createSample(name, source string) (string, error) { tmpPath := path.Join(os.TempDir(), name) - err := ioutil.WriteFile(tmpPath, []byte(source), os.ModePerm) + err := os.WriteFile(tmpPath, []byte(source), os.ModePerm) if err != nil { return "", err } @@ -74,7 +73,7 @@ options ndots:5` config.SetValue("my_property") err = config.Save() require.Nil(t, err) - bytes, err := ioutil.ReadFile(filepath.Clean(p)) + bytes, err := os.ReadFile(filepath.Clean(p)) require.Nil(t, err) actual := string(bytes) require.Len(t, actual, len(sample)) diff --git a/pkg/networkservice/connectioncontext/dnscontext/vl3dns/client.go b/pkg/networkservice/connectioncontext/dnscontext/vl3dns/client.go index 817ac23f6..7db2d3dd4 100644 --- a/pkg/networkservice/connectioncontext/dnscontext/vl3dns/client.go +++ b/pkg/networkservice/connectioncontext/dnscontext/vl3dns/client.go @@ -34,7 +34,8 @@ type vl3DNSClient struct { } // NewClient - returns a new null client that does nothing but call next.Client(ctx).{Request/Close} and return the result -// This is very useful in testing +// +// This is very useful in testing func NewClient(dnsServerIP net.IP, dnsConfigs *dnsconfig.Map) networkservice.NetworkServiceClient { return &vl3DNSClient{ dnsServerIP: dnsServerIP, diff --git a/pkg/networkservice/connectioncontext/ipcontext/vl3/client.go b/pkg/networkservice/connectioncontext/ipcontext/vl3/client.go index af3af6935..44c78f5ce 100644 --- a/pkg/networkservice/connectioncontext/ipcontext/vl3/client.go +++ b/pkg/networkservice/connectioncontext/ipcontext/vl3/client.go @@ -40,8 +40,9 @@ type vl3Client struct { } // NewClient - returns a new vL3 client instance that manages connection.context.ipcontext for vL3 scenario. -// Produces refresh on prefix update. -// Requires begin and metdata chain elements. +// +// Produces refresh on prefix update. +// Requires begin and metdata chain elements. func NewClient(chainContext context.Context, prefixCh <-chan *ipam.PrefixResponse) networkservice.NetworkServiceClient { if chainContext == nil { panic("chainContext can not be nil") diff --git a/pkg/networkservice/connectioncontext/ipcontext/vl3/client_test.go b/pkg/networkservice/connectioncontext/ipcontext/vl3/client_test.go index 76e79f7d9..d78d43b66 100644 --- a/pkg/networkservice/connectioncontext/ipcontext/vl3/client_test.go +++ b/pkg/networkservice/connectioncontext/ipcontext/vl3/client_test.go @@ -13,6 +13,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 vl3_test import ( diff --git a/pkg/networkservice/connectioncontext/ipcontext/vl3/server.go b/pkg/networkservice/connectioncontext/ipcontext/vl3/server.go index 0f3516bc6..f9f71f6a0 100644 --- a/pkg/networkservice/connectioncontext/ipcontext/vl3/server.go +++ b/pkg/networkservice/connectioncontext/ipcontext/vl3/server.go @@ -32,8 +32,9 @@ type vl3Server struct { } // NewServer - returns a new vL3 server instance that manages connection.context.ipcontext for vL3 scenario. -// Produces refresh on prefix update. -// Requires begin and metdata chain elements. +// +// Produces refresh on prefix update. +// Requires begin and metdata chain elements. func NewServer(ctx context.Context, prefixCh <-chan *ipam.PrefixResponse) networkservice.NetworkServiceServer { var result = new(vl3Server) diff --git a/pkg/networkservice/core/adapters/monitor_client_to_server.go b/pkg/networkservice/core/adapters/monitor_client_to_server.go index 80f38ee0c..9e84ebd64 100644 --- a/pkg/networkservice/core/adapters/monitor_client_to_server.go +++ b/pkg/networkservice/core/adapters/monitor_client_to_server.go @@ -25,7 +25,8 @@ type monitorClientToServer struct { } // NewMonitorClientToServer - returns a MonitorConnectionServer that is wrapped around the provided MonitorConnectionClient -// events that are received by the MonitorConnectionClient are sent to the MonitorConnectionServer +// +// events that are received by the MonitorConnectionClient are sent to the MonitorConnectionServer func NewMonitorClientToServer(client networkservice.MonitorConnectionClient) networkservice.MonitorConnectionServer { return &monitorClientToServer{ client: client, diff --git a/pkg/networkservice/core/adapters/monitor_server_to_client.go b/pkg/networkservice/core/adapters/monitor_server_to_client.go index 960153545..1556155f9 100644 --- a/pkg/networkservice/core/adapters/monitor_server_to_client.go +++ b/pkg/networkservice/core/adapters/monitor_server_to_client.go @@ -33,7 +33,8 @@ type monitorServerToClient struct { } // NewMonitorServerToClient - returns a MonitorConnectionClient that is a wrapper around the MonitorConnectionServer -// events sent to the MonitorConnectionServer are received byt the MonitorConnectionClient +// +// events sent to the MonitorConnectionServer are received byt the MonitorConnectionClient func NewMonitorServerToClient(server networkservice.MonitorConnectionServer) networkservice.MonitorConnectionClient { return &monitorServerToClient{server: server} } diff --git a/pkg/networkservice/core/eventchannel/monitor_client.go b/pkg/networkservice/core/eventchannel/monitor_client.go index 03bbdfa09..5b7cea564 100644 --- a/pkg/networkservice/core/eventchannel/monitor_client.go +++ b/pkg/networkservice/core/eventchannel/monitor_client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -15,10 +15,11 @@ // limitations under the License. // Package eventchannel provides implementations based on event channels of: -// networkservice.MonitorConnectionClient -// networkservice.MonitorConnectionServer -// networkservice.MonitorConnection_MonitorConnectionsClient -// networkservice.MonitorConnection_MonitorConnectionsServer +// +// networkservice.MonitorConnectionClient +// networkservice.MonitorConnectionServer +// networkservice.MonitorConnection_MonitorConnectionsClient +// networkservice.MonitorConnection_MonitorConnectionsServer package eventchannel import ( @@ -39,10 +40,11 @@ type monitorConnectionClient struct { } // NewMonitorConnectionClient - returns networkservice.MonitorConnectionClient -// eventCh - channel that provides events to feed the Recv function -// when an event is sent on the eventCh, all networkservice.MonitorConnection_MonitorConnectionsClient -// returned from calling MonitorConnections receive the event. -// Note: Does not perform filtering basedon MonitorScopeSelector +// +// eventCh - channel that provides events to feed the Recv function +// when an event is sent on the eventCh, all networkservice.MonitorConnection_MonitorConnectionsClient +// returned from calling MonitorConnections receive the event. +// Note: Does not perform filtering basedon MonitorScopeSelector func NewMonitorConnectionClient(eventCh <-chan *networkservice.ConnectionEvent) networkservice.MonitorConnectionClient { return &monitorConnectionClient{ eventCh: eventCh, diff --git a/pkg/networkservice/core/eventchannel/monitor_connection_client.go b/pkg/networkservice/core/eventchannel/monitor_connection_client.go index 6faccbab0..349daf705 100644 --- a/pkg/networkservice/core/eventchannel/monitor_connection_client.go +++ b/pkg/networkservice/core/eventchannel/monitor_connection_client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -31,9 +31,10 @@ type monitorConnectionMonitorConnectionsClient struct { } // NewMonitorConnectionMonitorConnectionsClient - returns a networkservice.MonitorConnection_MonitorConnectionsClient -// ctx - context which if Done will cause Recv to return. -// eventCh - when an event is sent on eventCh, it is returned by the -// call to Recv on the networkservice.MonitorConnection_MonitorConnectionsClient +// +// ctx - context which if Done will cause Recv to return. +// eventCh - when an event is sent on eventCh, it is returned by the +// call to Recv on the networkservice.MonitorConnection_MonitorConnectionsClient func NewMonitorConnectionMonitorConnectionsClient(ctx context.Context, eventCh <-chan *networkservice.ConnectionEvent) networkservice.MonitorConnection_MonitorConnectionsClient { ctx, cancelFunc := context.WithCancel(ctx) return &monitorConnectionMonitorConnectionsClient{ diff --git a/pkg/networkservice/core/eventchannel/monitor_connection_server.go b/pkg/networkservice/core/eventchannel/monitor_connection_server.go index 88e6e382a..7809a88a1 100644 --- a/pkg/networkservice/core/eventchannel/monitor_connection_server.go +++ b/pkg/networkservice/core/eventchannel/monitor_connection_server.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. -// // Copyright (c) 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"); @@ -32,8 +32,9 @@ type monitorConnectionMonitorConnectionsServer struct { } // NewMonitorConnectionMonitorConnectionsServer - returns a networkservice.MonitorConnection_MonitorConnectionsServer -// eventCh - when an event is passed to the Send() method, it is inserted -// into eventCh +// +// eventCh - when an event is passed to the Send() method, it is inserted +// into eventCh func NewMonitorConnectionMonitorConnectionsServer(ctx context.Context, eventCh chan<- *networkservice.ConnectionEvent) networkservice.MonitorConnection_MonitorConnectionsServer { rv := &monitorConnectionMonitorConnectionsServer{ ctx: ctx, diff --git a/pkg/networkservice/core/eventchannel/monitor_server.go b/pkg/networkservice/core/eventchannel/monitor_server.go index ef0b4ecb3..0195c58bd 100644 --- a/pkg/networkservice/core/eventchannel/monitor_server.go +++ b/pkg/networkservice/core/eventchannel/monitor_server.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. -// // Copyright (c) 2020 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,8 +36,9 @@ type monitorConnectionServer struct { } // NewMonitorServer - returns a networkservice.MonitorConnectionServer -// eventCh - when Send() is called on any of the NewMonitorConnection_MonitorConnectionsServers -// returned by a call to MonitorConnections, it is inserted into eventCh +// +// eventCh - when Send() is called on any of the NewMonitorConnection_MonitorConnectionsServers +// returned by a call to MonitorConnections, it is inserted into eventCh func NewMonitorServer(eventCh <-chan *networkservice.ConnectionEvent, options ...MonitorConnectionServerOption) networkservice.MonitorConnectionServer { rv := &monitorConnectionServer{ eventCh: eventCh, diff --git a/pkg/networkservice/core/next/context.go b/pkg/networkservice/core/next/context.go index 3d37cc245..ec4f9f681 100644 --- a/pkg/networkservice/core/next/context.go +++ b/pkg/networkservice/core/next/context.go @@ -1,6 +1,6 @@ // Copyright (c) 2020 Doc.ai and/or its affiliates. // -// Copyright (c) 2020 Cisco Systems, Inc. +// Copyright (c) 2020-2022 Cisco Systems, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -34,8 +34,9 @@ const ( type contextKeyType string // withNextServer - -// Wraps 'parent' in a new Context that has the Server networkservice.NetworkServiceServer to be called in the chain -// Should only be set in CompositeEndpoint.Request/Close +// +// Wraps 'parent' in a new Context that has the Server networkservice.NetworkServiceServer to be called in the chain +// Should only be set in CompositeEndpoint.Request/Close func withNextServer(parent context.Context, next networkservice.NetworkServiceServer) context.Context { if parent == nil { parent = context.Background() @@ -44,7 +45,8 @@ func withNextServer(parent context.Context, next networkservice.NetworkServiceSe } // Server - -// Returns the Server networkservice.NetworkServiceServer to be called in the chain from the context.Context +// +// Returns the Server networkservice.NetworkServiceServer to be called in the chain from the context.Context func Server(ctx context.Context) networkservice.NetworkServiceServer { rv, ok := ctx.Value(nextServerKey).(networkservice.NetworkServiceServer) if ok && rv != nil { @@ -54,8 +56,9 @@ func Server(ctx context.Context) networkservice.NetworkServiceServer { } // withNextClient - -// Wraps 'parent' in a new Context that has the Server networkservice.NetworkServiceServer to be called in the chain -// Should only be set in CompositeEndpoint.Request/Close +// +// Wraps 'parent' in a new Context that has the Server networkservice.NetworkServiceServer to be called in the chain +// Should only be set in CompositeEndpoint.Request/Close func withNextClient(parent context.Context, next networkservice.NetworkServiceClient) context.Context { if parent == nil { panic("cannot create context from nil parent") @@ -64,7 +67,8 @@ func withNextClient(parent context.Context, next networkservice.NetworkServiceCl } // Client - -// Returns the Client networkservice.NetworkServiceClient to be called in the chain from the context.Context +// +// Returns the Client networkservice.NetworkServiceClient to be called in the chain from the context.Context func Client(ctx context.Context) networkservice.NetworkServiceClient { rv, ok := ctx.Value(nextClientKey).(networkservice.NetworkServiceClient) if ok && rv != nil { diff --git a/pkg/networkservice/utils/checks/checkclose/client.go b/pkg/networkservice/utils/checks/checkclose/client.go index 354aeefb2..1c5ad02f4 100644 --- a/pkg/networkservice/utils/checks/checkclose/client.go +++ b/pkg/networkservice/utils/checks/checkclose/client.go @@ -34,8 +34,9 @@ type checkCloseClient struct { } // NewClient - returns NetworkServiceClient chain elements to check the Close received from the previous element in the chain -// t - *testing.T for checks -// check - function to check the Connection +// +// t - *testing.T for checks +// check - function to check the Connection func NewClient(t *testing.T, check func(*testing.T, *networkservice.Connection)) networkservice.NetworkServiceClient { return &checkCloseClient{ T: t, diff --git a/pkg/networkservice/utils/checks/checkconnection/client.go b/pkg/networkservice/utils/checks/checkconnection/client.go index fc60a5a00..d3f8cf702 100644 --- a/pkg/networkservice/utils/checks/checkconnection/client.go +++ b/pkg/networkservice/utils/checks/checkconnection/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -34,8 +34,9 @@ type checkConnectionOnReturn struct { } // NewClient - returns a NetworkServiceClient chain element that will check the connection returned by the next Client in the chain -// t - *testing.T for the check -// check - function to run on the Connection to check it is as it should be +// +// t - *testing.T for the check +// check - function to run on the Connection to check it is as it should be func NewClient(t *testing.T, check func(t *testing.T, conn *networkservice.Connection)) networkservice.NetworkServiceClient { return &checkConnectionOnReturn{ T: t, diff --git a/pkg/networkservice/utils/checks/checkcontext/client.go b/pkg/networkservice/utils/checks/checkcontext/client.go index f826d4d66..9b751527a 100644 --- a/pkg/networkservice/utils/checks/checkcontext/client.go +++ b/pkg/networkservice/utils/checks/checkcontext/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -34,8 +34,9 @@ type checkContextAfterClient struct { } // NewClient - returns NetworkServiceClient that checks the context passed in from the previous Client in the chain -// t - *testing.T used for the check -// check - function that checks the context.Context +// +// t - *testing.T used for the check +// check - function that checks the context.Context func NewClient(t *testing.T, check func(*testing.T, context.Context)) networkservice.NetworkServiceClient { return &checkContextAfterClient{ T: t, diff --git a/pkg/networkservice/utils/checks/checkcontext/server.go b/pkg/networkservice/utils/checks/checkcontext/server.go index c36544521..8407ec2fe 100644 --- a/pkg/networkservice/utils/checks/checkcontext/server.go +++ b/pkg/networkservice/utils/checks/checkcontext/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -32,8 +32,9 @@ type checkContextAfterServer struct { } // NewServer - returns NetworkServiceServer that checks the context passed in from the previous Server in the chain -// t - *testing.T used for the check -// check - function that checks the context.Context +// +// t - *testing.T used for the check +// check - function that checks the context.Context func NewServer(t *testing.T, check func(*testing.T, context.Context)) networkservice.NetworkServiceServer { return &checkContextAfterServer{ T: t, diff --git a/pkg/networkservice/utils/checks/checkcontextonreturn/client.go b/pkg/networkservice/utils/checks/checkcontextonreturn/client.go index a74dc6c04..f39790892 100644 --- a/pkg/networkservice/utils/checks/checkcontextonreturn/client.go +++ b/pkg/networkservice/utils/checks/checkcontextonreturn/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -15,7 +15,8 @@ // limitations under the License. // Package checkcontextonreturn - provides a NetworkServiceClient chain element for checking the state of the context.Context -// after the next element in the chain has returned +// +// after the next element in the chain has returned package checkcontextonreturn import ( @@ -35,9 +36,10 @@ type checkContextOnReturn struct { } // NewClient - returns a NetworkServiceClient chain element for checking the state of the context.Context -// after the next element in the chain has returned -// t - *testing.T for doing the checks -// check - function for checking the context.Context +// +// after the next element in the chain has returned +// t - *testing.T for doing the checks +// check - function for checking the context.Context func NewClient(t *testing.T, check func(t *testing.T, ctx context.Context)) networkservice.NetworkServiceClient { return &checkContextOnReturn{ T: t, diff --git a/pkg/networkservice/utils/checks/checkerror/client.go b/pkg/networkservice/utils/checks/checkerror/client.go index 67b4164d1..a2845f309 100644 --- a/pkg/networkservice/utils/checks/checkerror/client.go +++ b/pkg/networkservice/utils/checks/checkerror/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -35,9 +35,10 @@ type checkErrorClient struct { } // NewClient - returns NetworkServiceClient chain element that checks for an error being returned from the next element in the chain -// t - *testing.T for checking -// isNil - if true, check that error is nil, if false, check that err is not nil. -// errs - optional - if errs[0] is provided, will check to see if the error matches errs[0] +// +// t - *testing.T for checking +// isNil - if true, check that error is nil, if false, check that err is not nil. +// errs - optional - if errs[0] is provided, will check to see if the error matches errs[0] func NewClient(t *testing.T, isNil bool, errs ...error) networkservice.NetworkServiceClient { rv := &checkErrorClient{ T: t, diff --git a/pkg/networkservice/utils/checks/checkerror/server.go b/pkg/networkservice/utils/checks/checkerror/server.go index 26bafe474..5d41be74d 100644 --- a/pkg/networkservice/utils/checks/checkerror/server.go +++ b/pkg/networkservice/utils/checks/checkerror/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -34,9 +34,10 @@ type checkErrorServer struct { } // NewServer - returns NetworkServiceServer chain element that checks for an error being returned from the next element in the chain -// t - *testing.T for checking -// isNil - if true, check that error is nil, if false, check that err is not nil. -// errs - optional - if errs[0] is provided, will check to see if the error matches errs[0] +// +// t - *testing.T for checking +// isNil - if true, check that error is nil, if false, check that err is not nil. +// errs - optional - if errs[0] is provided, will check to see if the error matches errs[0] func NewServer(t *testing.T, isNil bool, errs ...error) networkservice.NetworkServiceServer { rv := &checkErrorServer{ T: t, diff --git a/pkg/networkservice/utils/checks/checkopts/client.go b/pkg/networkservice/utils/checks/checkopts/client.go index a094c3263..9378c334c 100644 --- a/pkg/networkservice/utils/checks/checkopts/client.go +++ b/pkg/networkservice/utils/checks/checkopts/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -34,8 +34,9 @@ type checkOptsClient struct { } // NewClient - returns a NetworkServiceClient that checks for the specified opts... being passed into it -// t - *testing.T for checks -// opts... grpc.CallOptions expected at the end of the list of opts... passed to Request/Close +// +// t - *testing.T for checks +// opts... grpc.CallOptions expected at the end of the list of opts... passed to Request/Close func NewClient(t *testing.T, opts ...grpc.CallOption) networkservice.NetworkServiceClient { if len(opts) == 0 { opts = append(opts, grpc.EmptyCallOption{}) diff --git a/pkg/networkservice/utils/checks/checkrequest/client.go b/pkg/networkservice/utils/checks/checkrequest/client.go index 580000c14..f773efab9 100644 --- a/pkg/networkservice/utils/checks/checkrequest/client.go +++ b/pkg/networkservice/utils/checks/checkrequest/client.go @@ -34,8 +34,9 @@ type checkRequestAfterClient struct { } // NewClient - returns NetworkServiceClient chain elements to check the request received from the previous element in the chain -// t - *testing.T for checks -// check - function to check the NetworkServiceRequest +// +// t - *testing.T for checks +// check - function to check the NetworkServiceRequest func NewClient(t *testing.T, check func(*testing.T, *networkservice.NetworkServiceRequest)) networkservice.NetworkServiceClient { return &checkRequestAfterClient{ T: t, diff --git a/pkg/networkservice/utils/checks/checkrequest/server.go b/pkg/networkservice/utils/checks/checkrequest/server.go index 6d0f31e6c..ed378eb32 100644 --- a/pkg/networkservice/utils/checks/checkrequest/server.go +++ b/pkg/networkservice/utils/checks/checkrequest/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -32,8 +32,9 @@ type checkRequestAfterServer struct { } // NewServer - returns NetworkServiceServer chain elements to check the request received from the previous element in the chain -// t - *testing.T for checks -// check - function to check the NetworkServiceRequest +// +// t - *testing.T for checks +// check - function to check the NetworkServiceRequest func NewServer(t *testing.T, check func(*testing.T, *networkservice.NetworkServiceRequest)) networkservice.NetworkServiceServer { return &checkRequestAfterServer{ T: t, diff --git a/pkg/networkservice/utils/checks/checkresponse/client.go b/pkg/networkservice/utils/checks/checkresponse/client.go index dcbf017ab..9e4d51eb2 100644 --- a/pkg/networkservice/utils/checks/checkresponse/client.go +++ b/pkg/networkservice/utils/checks/checkresponse/client.go @@ -37,8 +37,9 @@ type checkResponseClient struct { } // NewClient - returns NetworkServiceClient chain elements to check the response received from the next element in the chain -// t - *testing.T for checks -// check - function to check the Connnection +// +// t - *testing.T for checks +// check - function to check the Connnection func NewClient(t *testing.T, check func(*testing.T, *networkservice.Connection)) networkservice.NetworkServiceClient { return &checkResponseClient{ T: t, diff --git a/pkg/networkservice/utils/checks/checkresponse/server.go b/pkg/networkservice/utils/checks/checkresponse/server.go index f19fc5983..e95e34b16 100644 --- a/pkg/networkservice/utils/checks/checkresponse/server.go +++ b/pkg/networkservice/utils/checks/checkresponse/server.go @@ -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"); @@ -33,8 +35,9 @@ type checkResponseServer struct { } // NewServer - returns NetworkServiceServer chain elements to check the response received from the next element in the chain -// t - *testing.T for checks -// check - function to check the Connnection +// +// t - *testing.T for checks +// check - function to check the Connnection func NewServer(t *testing.T, check func(*testing.T, *networkservice.Connection)) networkservice.NetworkServiceServer { return &checkResponseServer{ T: t, diff --git a/pkg/networkservice/utils/inject/injectopts/client.go b/pkg/networkservice/utils/inject/injectopts/client.go index 2067d16bc..8a6e928ee 100644 --- a/pkg/networkservice/utils/inject/injectopts/client.go +++ b/pkg/networkservice/utils/inject/injectopts/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -15,7 +15,8 @@ // limitations under the License. // Package injectopts - injects grpc.CallOptions by appending them to the end of the opts... it receives before calling -// the next client in the chain +// +// the next client in the chain package injectopts import ( @@ -33,7 +34,8 @@ type injectOptsClient struct { } // NewClient - injects opts grpc.CallOptions by appending them to the end of the opts... it receives before calling -// the next client in the chain +// +// the next client in the chain func NewClient(opts ...grpc.CallOption) networkservice.NetworkServiceClient { if len(opts) == 0 { opts = append(opts, grpc.EmptyCallOption{}) diff --git a/pkg/networkservice/utils/metadata/client.go b/pkg/networkservice/utils/metadata/client.go index f16170f71..1f7bd2b39 100644 --- a/pkg/networkservice/utils/metadata/client.go +++ b/pkg/networkservice/utils/metadata/client.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. -// // Copyright (c) 2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,7 +35,8 @@ type metaDataClient struct { } // NewClient - Enable per Connection.Id metadata for the client -// Must come after updatepath.NewClient() in the chain +// +// Must come after updatepath.NewClient() in the chain func NewClient() networkservice.NetworkServiceClient { return &metaDataClient{} } diff --git a/pkg/networkservice/utils/metadata/server.go b/pkg/networkservice/utils/metadata/server.go index f252e83db..ce7d97295 100644 --- a/pkg/networkservice/utils/metadata/server.go +++ b/pkg/networkservice/utils/metadata/server.go @@ -34,7 +34,8 @@ type metadataServer struct { } // NewServer - Enable per Connection.Id metadata for the server -// Must come after updatepath.NewServer() in the chain +// +// Must come after updatepath.NewServer() in the chain func NewServer() networkservice.NetworkServiceServer { return &metadataServer{} } diff --git a/pkg/registry/chains/proxydns/server_ns_test.go b/pkg/registry/chains/proxydns/server_ns_test.go index 8409484df..7111b94c6 100644 --- a/pkg/registry/chains/proxydns/server_ns_test.go +++ b/pkg/registry/chains/proxydns/server_ns_test.go @@ -33,20 +33,21 @@ import ( ) /* - TestInterdomainNetworkServiceEndpointRegistry covers the next scenario: - 1. local registry from domain2 has entry "ns-1" - 2. nsmgr from domain1 call find with query "ns-1@domain2" - 3. local registry proxies query to nsmgr proxy registry - 4. nsmgr proxy registry proxies query to proxy registry - 5. proxy registry proxies query to local registry from domain2 - Expected: nsmgr found ns - - domain1: domain2: - ------------------------------------------------------------ ------------------- - | | Find | | - | local registry -> nsmgr proxy registry -> proxy registry | ---> | local registry | - | | | | - ------------------------------------------------------------ ------------------ +TestInterdomainNetworkServiceEndpointRegistry covers the next scenario: + 1. local registry from domain2 has entry "ns-1" + 2. nsmgr from domain1 call find with query "ns-1@domain2" + 3. local registry proxies query to nsmgr proxy registry + 4. nsmgr proxy registry proxies query to proxy registry + 5. proxy registry proxies query to local registry from domain2 + +Expected: nsmgr found ns + +domain1: domain2: +------------------------------------------------------------ ------------------- +| | Find | | +| local registry -> nsmgr proxy registry -> proxy registry | ---> | local registry | +| | | | +------------------------------------------------------------ ------------------ */ func TestInterdomainNetworkServiceRegistry(t *testing.T) { t.Cleanup(func() { goleak.VerifyNone(t) }) @@ -98,20 +99,21 @@ func TestInterdomainNetworkServiceRegistry(t *testing.T) { } /* - TestInterdomainNetworkServiceEndpointRegistry covers the next scenario: - 1. local registry from domain2 has entry "ns-1" - 2. nsmgr from domain1 call find with query "ns-1@domain2" - 3. local registry proxies query to nsmgr proxy registry - 4. nsmgr proxy registry proxies query to proxy registry - 5. proxy registry proxies query to local registry from domain2 - Expected: nsmgr found ns - - domain1: domain2: - ------------------------------------------------------------ ------------------- ------------------------------------------------------------ - | | 2.Find | | 1. Register | | - | local registry -> nsmgr proxy registry -> proxy registry | ---> | local registry | <----------- | local registry -> nsmgr proxy registry -> proxy registry | - | | | | | | - ------------------------------------------------------------ ------------------ ------------------------------------------------------------ +TestInterdomainNetworkServiceEndpointRegistry covers the next scenario: + 1. local registry from domain2 has entry "ns-1" + 2. nsmgr from domain1 call find with query "ns-1@domain2" + 3. local registry proxies query to nsmgr proxy registry + 4. nsmgr proxy registry proxies query to proxy registry + 5. proxy registry proxies query to local registry from domain2 + +Expected: nsmgr found ns + +domain1: domain2: +------------------------------------------------------------ ------------------- ------------------------------------------------------------ +| | 2.Find | | 1. Register | | +| local registry -> nsmgr proxy registry -> proxy registry | ---> | local registry | <----------- | local registry -> nsmgr proxy registry -> proxy registry | +| | | | | | +------------------------------------------------------------ ------------------ ------------------------------------------------------------ */ func TestLocalDomain_NetworkServiceRegistry(t *testing.T) { t.Cleanup(func() { goleak.VerifyNone(t) }) diff --git a/pkg/registry/chains/proxydns/server_nse_test.go b/pkg/registry/chains/proxydns/server_nse_test.go index 256419929..279b4712b 100644 --- a/pkg/registry/chains/proxydns/server_nse_test.go +++ b/pkg/registry/chains/proxydns/server_nse_test.go @@ -35,20 +35,21 @@ import ( ) /* - TestInterdomainNetworkServiceEndpointRegistry covers the next scenario: - 1. local registry from domain2 has entry "nse-1" - 2. nsmgr from domain1 call find with query "nse-1@domain2" - 3. local registry proxies query to nsmgr proxy registry - 4. nsmgr proxy registry proxies query to proxy registry - 5. proxy registry proxies query to local registry from domain2 - Expected: nsmgr found nse - - domain1: domain2: - ------------------------------------------------------------ ------------------- - | | Find | | - | local registry -> nsmgr proxy registry -> proxy registry | ---> | local registry | - | | | | - ------------------------------------------------------------ ------------------ +TestInterdomainNetworkServiceEndpointRegistry covers the next scenario: + 1. local registry from domain2 has entry "nse-1" + 2. nsmgr from domain1 call find with query "nse-1@domain2" + 3. local registry proxies query to nsmgr proxy registry + 4. nsmgr proxy registry proxies query to proxy registry + 5. proxy registry proxies query to local registry from domain2 + +Expected: nsmgr found nse + +domain1: domain2: +------------------------------------------------------------ ------------------- +| | Find | | +| local registry -> nsmgr proxy registry -> proxy registry | ---> | local registry | +| | | | +------------------------------------------------------------ ------------------ */ func TestInterdomainNetworkServiceEndpointRegistry(t *testing.T) { t.Cleanup(func() { goleak.VerifyNone(t) }) @@ -105,19 +106,20 @@ func TestInterdomainNetworkServiceEndpointRegistry(t *testing.T) { } /* - TestLocalDomain_NetworkServiceEndpointRegistry covers the next scenario: - 1. nsmgr from domain1 calls find with query "nse-1@domain1" - 2. local registry proxies query to nsmgr proxy registry - 3. nsmgr proxy registry proxies query to proxy registry - 4. proxy registry proxies query to local registry - Expected: nsmgr found nse - - domain1: - ----------------------------------------------------------------------------------- - | | - | local registry -> nsmgr proxy registry -> proxy registry -> local registry | - | | - ----------------------------------------------------------------------------------- +TestLocalDomain_NetworkServiceEndpointRegistry covers the next scenario: + 1. nsmgr from domain1 calls find with query "nse-1@domain1" + 2. local registry proxies query to nsmgr proxy registry + 3. nsmgr proxy registry proxies query to proxy registry + 4. proxy registry proxies query to local registry + +Expected: nsmgr found nse + +domain1: +----------------------------------------------------------------------------------- +| | +| local registry -> nsmgr proxy registry -> proxy registry -> local registry | +| | +----------------------------------------------------------------------------------- */ func TestLocalDomain_NetworkServiceEndpointRegistry(t *testing.T) { t.Cleanup(func() { goleak.VerifyNone(t) }) @@ -168,20 +170,21 @@ func TestLocalDomain_NetworkServiceEndpointRegistry(t *testing.T) { } /* - TestInterdomainNetworkServiceEndpointRegistry covers the next scenario: - 1. local registry from domain2 has entry "nse-1" - 2. nsmgr from domain1 call find with query "nse-1@domain2" - 3. local registry proxies query to nsmgr proxy registry - 4. nsmgr proxy registry proxies query to proxy registry - 5. proxy registry proxies query to local registry from domain2 - Expected: nsmgr found nse - - domain1: domain2: - ------------------------------------------------------------ ------------------- ------------------------------------------------------------ - | | 2.Find | | 1. Register | | - | local registry -> nsmgr proxy registry -> proxy registry | ---> | local registry | <----------- | local registry -> nsmgr proxy registry -> proxy registry | - | | | | | | - ------------------------------------------------------------ ------------------ ------------------------------------------------------------ +TestInterdomainNetworkServiceEndpointRegistry covers the next scenario: + 1. local registry from domain2 has entry "nse-1" + 2. nsmgr from domain1 call find with query "nse-1@domain2" + 3. local registry proxies query to nsmgr proxy registry + 4. nsmgr proxy registry proxies query to proxy registry + 5. proxy registry proxies query to local registry from domain2 + +Expected: nsmgr found nse + +domain1: domain2: +------------------------------------------------------------ ------------------- ------------------------------------------------------------ +| | 2.Find | | 1. Register | | +| local registry -> nsmgr proxy registry -> proxy registry | ---> | local registry | <----------- | local registry -> nsmgr proxy registry -> proxy registry | +| | | | | | +------------------------------------------------------------ ------------------ ------------------------------------------------------------ */ func TestInterdomainFloatingNetworkServiceEndpointRegistry(t *testing.T) { t.Cleanup(func() { goleak.VerifyNone(t) }) diff --git a/pkg/registry/common/begin/doc.go b/pkg/registry/common/begin/doc.go index 9e4c78203..4284d6dce 100644 --- a/pkg/registry/common/begin/doc.go +++ b/pkg/registry/common/begin/doc.go @@ -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): @@ -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: @@ -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). @@ -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. */ diff --git a/pkg/registry/common/clusterinfo/nse_server.go b/pkg/registry/common/clusterinfo/nse_server.go index ef85e7920..4781ec4f1 100644 --- a/pkg/registry/common/clusterinfo/nse_server.go +++ b/pkg/registry/common/clusterinfo/nse_server.go @@ -19,7 +19,7 @@ package clusterinfo import ( "context" - "io/ioutil" + "os" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" @@ -35,7 +35,7 @@ type clusterinfoNSEServer struct { func (n *clusterinfoNSEServer) Register(ctx context.Context, nse *registry.NetworkServiceEndpoint) (*registry.NetworkServiceEndpoint, error) { 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) } diff --git a/pkg/registry/common/clusterinfo/nse_server_test.go b/pkg/registry/common/clusterinfo/nse_server_test.go index 107094d44..ba52a9165 100644 --- a/pkg/registry/common/clusterinfo/nse_server_test.go +++ b/pkg/registry/common/clusterinfo/nse_server_test.go @@ -18,7 +18,6 @@ package clusterinfo_test import ( "context" - "io/ioutil" "os" "path/filepath" "testing" @@ -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.NewNetworkServiceEndpointRegistryServer(clusterinfo.WithConfigPath(path)) diff --git a/pkg/registry/core/next/context.go b/pkg/registry/core/next/context.go index 2f7c3d056..cf30dd726 100644 --- a/pkg/registry/core/next/context.go +++ b/pkg/registry/core/next/context.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020 Cisco Systems, Inc. -// // Copyright (c) 2020 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2022 Cisco Systems, Inc. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,7 +36,8 @@ const ( ) // withNextNSRegistryServer - -// Wraps 'parent' in a new Context that has the DiscoveryServer registry.NetworkServiceRegistryServer to be called in the chain +// +// Wraps 'parent' in a new Context that has the DiscoveryServer registry.NetworkServiceRegistryServer to be called in the chain func withNextNSRegistryServer(parent context.Context, next registry.NetworkServiceRegistryServer) context.Context { if parent == nil { panic("cannot create context from nil parent") @@ -45,7 +46,8 @@ func withNextNSRegistryServer(parent context.Context, next registry.NetworkServi } // withNextNSRegistryClient - -// Wraps 'parent' in a new Context that has the NetworkServiceRegistryClient registry.NetworkServiceRegistryClientWrapper to be called in the chain +// +// Wraps 'parent' in a new Context that has the NetworkServiceRegistryClient registry.NetworkServiceRegistryClientWrapper to be called in the chain func withNextNSRegistryClient(parent context.Context, next registry.NetworkServiceRegistryClient) context.Context { if parent == nil { panic("cannot create context from nil parent") @@ -54,7 +56,8 @@ func withNextNSRegistryClient(parent context.Context, next registry.NetworkServi } // NetworkServiceRegistryServer - -// Returns the NetworkServiceRegistryServer registry.NetworkServiceRegistryServer to be called in the chain from the context.Context +// +// Returns the NetworkServiceRegistryServer registry.NetworkServiceRegistryServer to be called in the chain from the context.Context func NetworkServiceRegistryServer(ctx context.Context) registry.NetworkServiceRegistryServer { rv, ok := ctx.Value(nextNSRegistryServerKey).(registry.NetworkServiceRegistryServer) if ok && rv != nil { @@ -64,7 +67,8 @@ func NetworkServiceRegistryServer(ctx context.Context) registry.NetworkServiceRe } // NetworkServiceRegistryClient - -// Returns the NetworkServiceRegistryClient registry.NetworkServiceRegistryClientWrapper to be called in the chain from the context.Context +// +// Returns the NetworkServiceRegistryClient registry.NetworkServiceRegistryClientWrapper to be called in the chain from the context.Context func NetworkServiceRegistryClient(ctx context.Context) registry.NetworkServiceRegistryClient { rv, ok := ctx.Value(nextNSRegistryClientKey).(registry.NetworkServiceRegistryClient) if ok && rv != nil { @@ -74,7 +78,8 @@ func NetworkServiceRegistryClient(ctx context.Context) registry.NetworkServiceRe } // withNextNSERegistryServer - -// Wraps 'parent' in a new Context that has the DiscoveryServer registry.NetworkServiceEndpointRegistryServer to be called in the chain +// +// Wraps 'parent' in a new Context that has the DiscoveryServer registry.NetworkServiceEndpointRegistryServer to be called in the chain func withNextNSERegistryServer(parent context.Context, next registry.NetworkServiceEndpointRegistryServer) context.Context { if parent == nil { panic("cannot create context from nil parent") @@ -83,7 +88,8 @@ func withNextNSERegistryServer(parent context.Context, next registry.NetworkServ } // withNextNSERegistryClient - -// Wraps 'parent' in a new Context that has the NetworkServiceEndpointRegistryClient registry.NetworkServiceEndpointRegistryClientWrapper to be called in the chain +// +// Wraps 'parent' in a new Context that has the NetworkServiceEndpointRegistryClient registry.NetworkServiceEndpointRegistryClientWrapper to be called in the chain func withNextNSERegistryClient(parent context.Context, next registry.NetworkServiceEndpointRegistryClient) context.Context { if parent == nil { panic("cannot create context from nil parent") @@ -92,7 +98,8 @@ func withNextNSERegistryClient(parent context.Context, next registry.NetworkServ } // NetworkServiceEndpointRegistryServer - -// Returns the NetworkServiceEndpointRegistryServer registry.NetworkServiceEndpointRegistryServer to be called in the chain from the context.Context +// +// Returns the NetworkServiceEndpointRegistryServer registry.NetworkServiceEndpointRegistryServer to be called in the chain from the context.Context func NetworkServiceEndpointRegistryServer(ctx context.Context) registry.NetworkServiceEndpointRegistryServer { rv, ok := ctx.Value(nextNSERegistryServerKey).(registry.NetworkServiceEndpointRegistryServer) if ok && rv != nil { @@ -102,7 +109,8 @@ func NetworkServiceEndpointRegistryServer(ctx context.Context) registry.NetworkS } // NetworkServiceEndpointRegistryClient - -// Returns the NetworkServiceEndpointRegistryClient registry.NetworkServiceEndpointRegistryClientWrapper to be called in the chain from the context.Context +// +// Returns the NetworkServiceEndpointRegistryClient registry.NetworkServiceEndpointRegistryClientWrapper to be called in the chain from the context.Context func NetworkServiceEndpointRegistryClient(ctx context.Context) registry.NetworkServiceEndpointRegistryClient { rv, ok := ctx.Value(nextNSERegistryClientKey).(registry.NetworkServiceEndpointRegistryClient) if ok && rv != nil { diff --git a/pkg/registry/server.go b/pkg/registry/server.go index 0d0fda84d..0a9d556f9 100644 --- a/pkg/registry/server.go +++ b/pkg/registry/server.go @@ -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"); @@ -25,8 +27,8 @@ import ( ) // Registry - aggregates the APIs: -// - registry.NetworkServiceRegistryServer -// - registry.NetworkServiceEndpointRegistryServer +// - registry.NetworkServiceRegistryServer +// - registry.NetworkServiceEndpointRegistryServer type Registry interface { // NetworkServiceRegistryServer returns network service server NetworkServiceRegistryServer() registry.NetworkServiceRegistryServer diff --git a/pkg/registry/utils/checks/checkcontext/ns_client.go b/pkg/registry/utils/checks/checkcontext/ns_client.go index 5391af9cf..3f0dd2eb3 100644 --- a/pkg/registry/utils/checks/checkcontext/ns_client.go +++ b/pkg/registry/utils/checks/checkcontext/ns_client.go @@ -29,8 +29,9 @@ import ( ) // NewNSClient - returns NetworkServiceRegistryClient that checks the context passed in from the previous NSClient in the chain -// t - *testing.T used for the check -// check - function that checks the context.Context +// +// t - *testing.T used for the check +// check - function that checks the context.Context func NewNSClient(t *testing.T, check func(*testing.T, context.Context)) registry.NetworkServiceRegistryClient { return &checkContextNSClient{ T: t, diff --git a/pkg/registry/utils/checks/checkcontext/ns_server.go b/pkg/registry/utils/checks/checkcontext/ns_server.go index b00796f9e..3ff9bb1c4 100644 --- a/pkg/registry/utils/checks/checkcontext/ns_server.go +++ b/pkg/registry/utils/checks/checkcontext/ns_server.go @@ -1,5 +1,7 @@ // Copyright (c) 2020 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"); @@ -27,8 +29,9 @@ import ( ) // NewNSServer - returns NetworkServiceRegistryServer that checks the context passed in from the previous NSServer in the chain -// t - *testing.T used for the check -// check - function that checks the context.Context +// +// t - *testing.T used for the check +// check - function that checks the context.Context func NewNSServer(t *testing.T, check func(*testing.T, context.Context)) registry.NetworkServiceRegistryServer { return &checkContextNSServer{ T: t, diff --git a/pkg/registry/utils/checks/checkcontext/nse_client.go b/pkg/registry/utils/checks/checkcontext/nse_client.go index fc5947101..4e43b3bf1 100644 --- a/pkg/registry/utils/checks/checkcontext/nse_client.go +++ b/pkg/registry/utils/checks/checkcontext/nse_client.go @@ -1,5 +1,7 @@ // Copyright (c) 2020 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"); @@ -28,8 +30,9 @@ import ( ) // NewNSEClient - returns NetworkServiceEndpointRegistryClient that checks the context passed in from the previous NSClient in the chain -// t - *testing.T used for the check -// check - function that checks the context.Context +// +// t - *testing.T used for the check +// check - function that checks the context.Context func NewNSEClient(t *testing.T, check func(*testing.T, context.Context)) registry.NetworkServiceEndpointRegistryClient { return &checkContextNSEClient{ T: t, diff --git a/pkg/registry/utils/checks/checkcontext/nse_server.go b/pkg/registry/utils/checks/checkcontext/nse_server.go index 1412b29d1..1ed97ab60 100644 --- a/pkg/registry/utils/checks/checkcontext/nse_server.go +++ b/pkg/registry/utils/checks/checkcontext/nse_server.go @@ -1,5 +1,7 @@ // Copyright (c) 2020 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"); @@ -27,8 +29,9 @@ import ( ) // NewNSEServer - returns NetworkServiceEndpointRegistryServer that checks the context passed in from the previous Server in the chain -// t - *testing.T used for the check -// check - function that checks the context.Context +// +// t - *testing.T used for the check +// check - function that checks the context.Context func NewNSEServer(t *testing.T, check func(*testing.T, context.Context)) registry.NetworkServiceEndpointRegistryServer { return &checkContextNSEServer{ T: t, diff --git a/pkg/registry/utils/checks/checknse/nse_client.go b/pkg/registry/utils/checks/checknse/nse_client.go index 4b2a09890..da6ff2962 100644 --- a/pkg/registry/utils/checks/checknse/nse_client.go +++ b/pkg/registry/utils/checks/checknse/nse_client.go @@ -1,5 +1,7 @@ // Copyright (c) 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"); @@ -34,8 +36,9 @@ type checkNSEClient struct { } // NewClient - returns NetworkServiceEndpointRegistryClient that checks the NSE passed in from the previous NSClient in the chain -// t - *testing.T used for the check -// check - function that checks the *registry.NetworkServiceEndpoint +// +// t - *testing.T used for the check +// check - function that checks the *registry.NetworkServiceEndpoint func NewClient(t *testing.T, check func(*testing.T, *registry.NetworkServiceEndpoint)) registry.NetworkServiceEndpointRegistryClient { return &checkNSEClient{ T: t, diff --git a/pkg/registry/utils/checks/checknse/nse_server.go b/pkg/registry/utils/checks/checknse/nse_server.go index 0b3847341..64f459162 100644 --- a/pkg/registry/utils/checks/checknse/nse_server.go +++ b/pkg/registry/utils/checks/checknse/nse_server.go @@ -1,5 +1,7 @@ // Copyright (c) 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"); @@ -33,8 +35,9 @@ type checkNSEServer struct { } // NewServer - returns NetworkServiceEndpointRegistryServer that checks the NSE passed in from the previous Server in the chain -// t - *testing.T used for the check -// check - function that checks the *registry.NetworkServiceEndpoint +// +// t - *testing.T used for the check +// check - function that checks the *registry.NetworkServiceEndpoint func NewServer(t *testing.T, check func(*testing.T, *registry.NetworkServiceEndpoint)) registry.NetworkServiceEndpointRegistryServer { return &checkNSEServer{ T: t, diff --git a/pkg/tools/addressof/adressof.go b/pkg/tools/addressof/adressof.go index 11011388c..c54b85e69 100644 --- a/pkg/tools/addressof/adressof.go +++ b/pkg/tools/addressof/adressof.go @@ -1,6 +1,6 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2020-2021 Cisco Systems, Inc. +// Copyright (c) 2020-2022 Cisco Systems, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -18,13 +18,14 @@ // Package addressof provides convenient functions for converting implementations of an interface to // pointers to implementations of the interface. Tt turns a concrete struct which implements an interface iface cannot be converted to -// *iface - go complains about it. -// This does not work: -// impl := &interfaceImpl{} -// var ptr *iface = &cl -// This also doesn't work: -// impl := &interfaceImpl{} -// var ptr *iface = &(cl.(iface) +// +// *iface - go complains about it. +// This does not work: +// impl := &interfaceImpl{} +// var ptr *iface = &cl +// This also doesn't work: +// impl := &interfaceImpl{} +// var ptr *iface = &(cl.(iface) package addressof import ( @@ -33,17 +34,18 @@ import ( ) // NetworkServiceClient - convenience function to help in converting things from networkservice.NetworkServiceClient to *networkservice.NetworkServiceClient -// it turns a concrete struct which implements networkservice.NetworkServiceClient cannot be converted to -// *networkservice.NetworkServiceClient - go complains about it. -// This does not work: -// impl := &clientImpl{} -// var onHeal *networkservice.NetworkServiceClient = &cl -// This also doesn't work: -// impl := &clientImpl{} -// var ptr *networkservice.NetworkServiceClient = &(cl.(networkservice.NetworkServiceClient) -// Using this function does: -// impl := &clientImpl{} -// var ptr *networkservice.NetworkServiceClient =NetworkServiceClient(cl) +// +// it turns a concrete struct which implements networkservice.NetworkServiceClient cannot be converted to +// *networkservice.NetworkServiceClient - go complains about it. +// This does not work: +// impl := &clientImpl{} +// var onHeal *networkservice.NetworkServiceClient = &cl +// This also doesn't work: +// impl := &clientImpl{} +// var ptr *networkservice.NetworkServiceClient = &(cl.(networkservice.NetworkServiceClient) +// Using this function does: +// impl := &clientImpl{} +// var ptr *networkservice.NetworkServiceClient =NetworkServiceClient(cl) func NetworkServiceClient(client networkservice.NetworkServiceClient) *networkservice.NetworkServiceClient { return &client } diff --git a/pkg/tools/clienturlctx/context.go b/pkg/tools/clienturlctx/context.go index cfe11cc07..deb0d258a 100644 --- a/pkg/tools/clienturlctx/context.go +++ b/pkg/tools/clienturlctx/context.go @@ -34,7 +34,8 @@ const ( type contextKeyType string // WithClientURL - -// Wraps 'parent' in a new Context that has the ClientURL +// +// Wraps 'parent' in a new Context that has the ClientURL func WithClientURL(parent context.Context, clientURL *url.URL) context.Context { if parent == nil { panic("cannot create context from nil parent") @@ -44,7 +45,8 @@ func WithClientURL(parent context.Context, clientURL *url.URL) context.Context { } // ClientURL - -// Returns the ClientURL +// +// Returns the ClientURL func ClientURL(ctx context.Context) *url.URL { if rv, ok := ctx.Value(clientURLKey).(*url.URL); ok { return rv @@ -53,7 +55,8 @@ func ClientURL(ctx context.Context) *url.URL { } // WithClientURLs - -// Wraps 'parent' in a new Context that has list of passed URLs +// +// Wraps 'parent' in a new Context that has list of passed URLs func WithClientURLs(parent context.Context, urls []url.URL) context.Context { if parent == nil { panic("cannot create context from nil parent") @@ -63,7 +66,8 @@ func WithClientURLs(parent context.Context, urls []url.URL) context.Context { } // ClientURLs - -// Returns list of URLs +// +// Returns list of URLs func ClientURLs(ctx context.Context) []url.URL { if rv, ok := ctx.Value(clientURLsKey).([]url.URL); ok { return rv diff --git a/pkg/tools/clockmock/mock.go b/pkg/tools/clockmock/mock.go index f5a8f1221..0dad19aef 100644 --- a/pkg/tools/clockmock/mock.go +++ b/pkg/tools/clockmock/mock.go @@ -1,5 +1,7 @@ // Copyright (c) 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"); @@ -85,7 +87,8 @@ func (m *Mock) timeTick( // SetSpeed starts mock time to run with the given speed until Mock.ctx becomes done or speed becomes changed. While // time is running, current time for the mock will be the following: -// mock time := mock start time + (real time duration from the start) * speed + mock duration added with Set, Add +// +// mock time := mock start time + (real time duration from the start) * speed + mock duration added with Set, Add func (m *Mock) SetSpeed(speed float64) { m.speedCh <- speed } diff --git a/pkg/tools/debug/self.go b/pkg/tools/debug/self.go index 813a6748a..0e2e53f4e 100644 --- a/pkg/tools/debug/self.go +++ b/pkg/tools/debug/self.go @@ -1,5 +1,7 @@ // Copyright (c) 2020 Cisco 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"); @@ -17,10 +19,10 @@ // Package debug provides a very simple function that, if executed will replace the executable with // dlv running the executable and listening on the port specified by an environment variable. // -// Example: -// if err := debug.Self(); err != nil { -// fmt.Println(err) -// } +// Example: +// if err := debug.Self(); err != nil { +// fmt.Println(err) +// } package debug import ( @@ -45,11 +47,12 @@ const ( ) // Self - replaces executable with dlv running the executable and listening on a port -// envVariableParts - variadic list of 'pieces' to be transformed into the -// env variable indicating where dlv should listen. -// Default: If no envVariableParts are provided, env variable -// defaults to []string{Dlv,Listen,path.Base(os.Args[0])} -// which is DLV_PORT_ +// +// envVariableParts - variadic list of 'pieces' to be transformed into the +// env variable indicating where dlv should listen. +// Default: If no envVariableParts are provided, env variable +// defaults to []string{Dlv,Listen,path.Base(os.Args[0])} +// which is DLV_PORT_ func Self(envVariableParts ...string) error { // Get the executable name. Note: os.Args[0] may not be the absolute path of the executable, which is // why we get it this way diff --git a/pkg/tools/dnsconfig/config_decoder_test.go b/pkg/tools/dnsconfig/config_decoder_test.go index e66b05c7d..23e4df0e6 100644 --- a/pkg/tools/dnsconfig/config_decoder_test.go +++ b/pkg/tools/dnsconfig/config_decoder_test.go @@ -15,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 dnsconfig_test import ( diff --git a/pkg/tools/fs/utils.go b/pkg/tools/fs/utils.go index 42552ff40..f14d5dcf7 100644 --- a/pkg/tools/fs/utils.go +++ b/pkg/tools/fs/utils.go @@ -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"); @@ -18,7 +20,6 @@ package fs import ( "context" - "io/ioutil" "os" "path/filepath" "strings" @@ -77,7 +78,7 @@ func WatchFile(ctx context.Context, filePath string) <-chan []byte { func monitorFile(ctx context.Context, filePath string, watcher *fsnotify.Watcher, notifyCh chan<- []byte) { logger := log.FromContext(ctx).WithField("fs.monitorFile", filePath) - bytes, _ := ioutil.ReadFile(filepath.Clean(filePath)) + bytes, _ := os.ReadFile(filepath.Clean(filePath)) if !sendOrClose(ctx, notifyCh, bytes) { return } @@ -100,11 +101,11 @@ func monitorFile(ctx context.Context, filePath string, watcher *fsnotify.Watcher } else if e.Op&(fsnotify.Write|fsnotify.Create) == 0 { continue } - data, err := ioutil.ReadFile(filepath.Clean(filePath)) + data, err := os.ReadFile(filepath.Clean(filePath)) for err != nil && ctx.Err() == nil { time.Sleep(time.Millisecond * 50) logger.Warn(err.Error()) - data, err = ioutil.ReadFile(filepath.Clean(filePath)) + data, err = os.ReadFile(filepath.Clean(filePath)) } if !sendOrClose(ctx, notifyCh, data) { return diff --git a/pkg/tools/fs/utils_test.go b/pkg/tools/fs/utils_test.go index 05d34f97b..fb9f6a390 100644 --- a/pkg/tools/fs/utils_test.go +++ b/pkg/tools/fs/utils_test.go @@ -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"); @@ -18,7 +20,6 @@ package fs_test import ( "context" - "io/ioutil" "os" "path/filepath" "runtime/debug" @@ -56,7 +57,7 @@ func Test_WatchFile(t *testing.T) { require.Nil(t, readEvent(), filePath) // Initial file read. nil because file doesn't exist yet - // We can't use things like ioutil.WriteFile here + // We can't use things like os.WriteFile here // because MacOS doesn't support recursive directory watching: https://github.com/fsnotify/fsnotify/issues/11 // and without it event watching for "create and write" operations is not stable, // we should have separate "create" and "write" events for consistent behavior. @@ -86,7 +87,7 @@ func Test_WatchFile(t *testing.T) { }, time.Millisecond*300, time.Millisecond*50) } - err = ioutil.WriteFile(filePath, []byte("data"), os.ModePerm) + err = os.WriteFile(filePath, []byte("data"), os.ModePerm) require.NoError(t, err) require.NotNil(t, readEvent(), filePath) // file created } diff --git a/pkg/tools/grpcfdutils/transceiver.go b/pkg/tools/grpcfdutils/transceiver.go index 9a926674c..9ea0771b5 100644 --- a/pkg/tools/grpcfdutils/transceiver.go +++ b/pkg/tools/grpcfdutils/transceiver.go @@ -31,7 +31,8 @@ import ( ) // notifiableFDTransceiver - grpcfd.Transceiver wrapper checking that received FDs are closed -// onRecvFile - callback receiving inodeURL string and a file received by grpcfd +// +// onRecvFile - callback receiving inodeURL string and a file received by grpcfd type notifiableFDTransceiver struct { grpcfd.FDTransceiver net.Addr diff --git a/pkg/tools/grpcutils/listen_and_serve_test.go b/pkg/tools/grpcutils/listen_and_serve_test.go index 5fe9227e1..199769c4f 100644 --- a/pkg/tools/grpcutils/listen_and_serve_test.go +++ b/pkg/tools/grpcutils/listen_and_serve_test.go @@ -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"); @@ -18,7 +20,6 @@ package grpcutils_test import ( "context" - "io/ioutil" "net/url" "os" "path" @@ -33,7 +34,7 @@ import ( func TestListenAndServe_NotExistsFolder(t *testing.T) { t.Cleanup(func() { goleak.VerifyNone(t) }) - dir, err := ioutil.TempDir(os.TempDir(), t.Name()) + dir, err := os.MkdirTemp(os.TempDir(), t.Name()) require.NoError(t, err) defer func() { _ = os.RemoveAll(dir) @@ -50,13 +51,13 @@ func TestListenAndServe_NotExistsFolder(t *testing.T) { func TestListenAndServe_ExistSocket(t *testing.T) { t.Cleanup(func() { goleak.VerifyNone(t) }) - dir, err := ioutil.TempDir(os.TempDir(), t.Name()) + dir, err := os.MkdirTemp(os.TempDir(), t.Name()) require.NoError(t, err) defer func() { _ = os.RemoveAll(dir) }() socket := path.Join(dir, "test.sock") - err = ioutil.WriteFile(socket, []byte("..."), os.ModePerm) + err = os.WriteFile(socket, []byte("..."), os.ModePerm) require.NoError(t, err) ctx, cancel := context.WithCancel(context.Background()) ch := grpcutils.ListenAndServe(ctx, &url.URL{Scheme: "unix", Path: socket}, grpc.NewServer()) diff --git a/pkg/tools/ippool/types.go b/pkg/tools/ippool/types.go index 1bad674fa..8affe1413 100644 --- a/pkg/tools/ippool/types.go +++ b/pkg/tools/ippool/types.go @@ -106,11 +106,12 @@ func (b *ipRange) Compare(ip *ipAddress) int { } // CompareRange - compares ip ranges. Returns -// 0 if crossing, -// -1 if ipR less than this and this range continues ipR range, -// -2 if ipR less than this and this range does not continues ipR range, -// 1 if ipR bigger than this and ipR continues this range, -// 2 if ipR bigger than this and ipR does not continues this range, +// +// 0 if crossing, +// -1 if ipR less than this and this range continues ipR range, +// -2 if ipR less than this and this range does not continues ipR range, +// 1 if ipR bigger than this and ipR continues this range, +// 2 if ipR bigger than this and ipR does not continues this range, func (b *ipRange) CompareRange(ipR *ipRange) int { if b.Compare(ipR.start) < 0 && b.Compare(ipR.end) < 0 { if !ipR.end.IsLast() && b.Compare(ipR.end.Next()) == 0 { diff --git a/pkg/tools/listenonurl/listenonurl.go b/pkg/tools/listenonurl/listenonurl.go index 156ea6c97..a4117c1d9 100644 --- a/pkg/tools/listenonurl/listenonurl.go +++ b/pkg/tools/listenonurl/listenonurl.go @@ -23,8 +23,9 @@ import ( ) // GetPublicURL - constructs an URL from an address accessible -// clusterwide and a given port -// defaults to the given URL if no such address can be found +// +// clusterwide and a given port +// defaults to the given URL if no such address can be found func GetPublicURL(addrs []net.Addr, defaultURL *url.URL) *url.URL { if defaultURL.Port() == "" || len(defaultURL.Host) != len(":")+len(defaultURL.Port()) { return defaultURL diff --git a/pkg/tools/monitorconnection/next/context.go b/pkg/tools/monitorconnection/next/context.go index 14f8d4f23..b06503286 100644 --- a/pkg/tools/monitorconnection/next/context.go +++ b/pkg/tools/monitorconnection/next/context.go @@ -31,7 +31,8 @@ const ( ) // withNextMonitorConnectionServer - -// Wraps 'parent' in a new Context that has the Server networkservice.MonitorConnectionServer to be called in the chain +// +// Wraps 'parent' in a new Context that has the Server networkservice.MonitorConnectionServer to be called in the chain func withNextMonitorConnectionServer(parent context.Context, next networkservice.MonitorConnectionServer) context.Context { if parent == nil { parent = context.Background() @@ -40,7 +41,8 @@ func withNextMonitorConnectionServer(parent context.Context, next networkservice } // MonitorConnectionServer - -// Returns the networkservice.MonitorConnectionServer to be called in the chain from the context.Context +// +// Returns the networkservice.MonitorConnectionServer to be called in the chain from the context.Context func MonitorConnectionServer(ctx context.Context) networkservice.MonitorConnectionServer { rv, ok := ctx.Value(nextMonitorConnectionServerKey).(networkservice.MonitorConnectionServer) if ok && rv != nil { diff --git a/pkg/tools/nsurl/nsurl.go b/pkg/tools/nsurl/nsurl.go index 310240947..44d1fa56d 100644 --- a/pkg/tools/nsurl/nsurl.go +++ b/pkg/tools/nsurl/nsurl.go @@ -1,5 +1,7 @@ // Copyright (c) 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"); @@ -19,9 +21,10 @@ // The rough schema is // ${mechanism}://${network service name}[/${interface name}][{labels in URL query format}] // Examples: -// kernel://my-service@dc.example.com/ms1 -// memif://my-vpp-service?A=1&B=2&C=3 -// vfio://second-service?sriovToken=intel/10G +// +// kernel://my-service@dc.example.com/ms1 +// memif://my-vpp-service?A=1&B=2&C=3 +// vfio://second-service?sriovToken=intel/10G package nsurl import ( diff --git a/pkg/tools/opa/policy.go b/pkg/tools/opa/policy.go index 7bc4327c2..1efa31e2c 100644 --- a/pkg/tools/opa/policy.go +++ b/pkg/tools/opa/policy.go @@ -18,7 +18,7 @@ package opa import ( "context" - "io/ioutil" + "os" "path/filepath" "strings" "sync" @@ -152,7 +152,7 @@ func (d *AuthorizationPolicy) loadSource() error { return nil } var b []byte - b, err := ioutil.ReadFile(d.policyFilePath) + b, err := os.ReadFile(d.policyFilePath) if err != nil { return err } diff --git a/pkg/tools/opa/policy_test.go b/pkg/tools/opa/policy_test.go index d9770e5d7..6e65f8920 100644 --- a/pkg/tools/opa/policy_test.go +++ b/pkg/tools/opa/policy_test.go @@ -1,5 +1,7 @@ // Copyright (c) 2020 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"); @@ -18,7 +20,6 @@ package opa_test import ( "context" - "io/ioutil" "os" "path" "path/filepath" @@ -45,7 +46,7 @@ func TestWithPolicyFromFile(t *testing.T) { ` policyPath := filepath.Clean(path.Join(dir, "policy.rego")) - err = ioutil.WriteFile(policyPath, []byte(policy), os.ModePerm) + err = os.WriteFile(policyPath, []byte(policy), os.ModePerm) require.Nil(t, err) p := opa.WithPolicyFromFile(policyPath, "allow", opa.True) diff --git a/pkg/tools/sandbox/builder.go b/pkg/tools/sandbox/builder.go index 8f9517eab..d84515322 100644 --- a/pkg/tools/sandbox/builder.go +++ b/pkg/tools/sandbox/builder.go @@ -19,7 +19,6 @@ package sandbox import ( "context" "fmt" - "io/ioutil" "net" "net/url" "os" @@ -173,7 +172,7 @@ func (b *Builder) Build() *Domain { require.Nil(b.t, b.supplyRegistry, msg) require.Nil(b.t, b.supplyRegistryProxy, msg) - sockPath, err := ioutil.TempDir(os.TempDir(), "nsm-domain-temp") + sockPath, err := os.MkdirTemp(os.TempDir(), "nsm-domain-temp") require.NoError(b.t, err) go func() { diff --git a/pkg/tools/spire/start.go b/pkg/tools/spire/start.go index 3ea394c08..134a278a6 100644 --- a/pkg/tools/spire/start.go +++ b/pkg/tools/spire/start.go @@ -26,7 +26,6 @@ import ( "crypto/x509" "errors" "fmt" - "io/ioutil" "os" "path" "strings" @@ -66,7 +65,8 @@ func logrusEntry(ctx context.Context) *logrus.Entry { } // AddEntry - adds an entry to the spire server for parentID, spiffeID, and selector -// parentID is usually the same as the agentID provided to Start() +// +// parentID is usually the same as the agentID provided to Start() func AddEntry(ctx context.Context, parentID, spiffeID, selector, federatesWith string) error { cmdStr := "spire-server entry create -parentID %s -spiffeID %s -selector %s" cmdStr = fmt.Sprintf(cmdStr, parentID, spiffeID, selector) @@ -82,7 +82,7 @@ func AddEntry(ctx context.Context, parentID, spiffeID, selector, federatesWith s // Start - start a spire-server and spire-agent with the given agentId func Start(options ...Option) <-chan error { errCh := make(chan error, 4) - defaultRoot, err := ioutil.TempDir("", "spire") + defaultRoot, err := os.MkdirTemp("", "spire") if err != nil { errCh <- err close(errCh) @@ -254,7 +254,7 @@ func writeConfigFiles(ctx context.Context, agentConfig, serverConfig, spireRoot if err := os.MkdirAll(path.Dir(filename), 0o700); err != nil { return err } - if err := ioutil.WriteFile(filename, []byte(contents), 0o600); err != nil { + if err := os.WriteFile(filename, []byte(contents), 0o600); err != nil { return err } } diff --git a/pkg/tools/token/token.go b/pkg/tools/token/token.go index e39c98681..526482dd7 100644 --- a/pkg/tools/token/token.go +++ b/pkg/tools/token/token.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -24,5 +24,6 @@ import ( ) // GeneratorFunc - a function which takes the credentials.AuthInfo of the peer of the client or server -// and returns a token as a string (example: JWT), a expireTime, and an error. +// +// and returns a token as a string (example: JWT), a expireTime, and an error. type GeneratorFunc func(peerAuthInfo credentials.AuthInfo) (token string, expireTime time.Time, err error)