From 50bc31d9fa95572cdb86fa984ea8db9c9b42100b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Nov 2022 21:35:27 +0100 Subject: [PATCH 01/10] integration: move files to _test.go files to fix linting The linter marked these as unused, as they're only used in tests; integration/api.go:45:20: func `(*dummyAPI).RemoveNode` is unused (unused) func (a *dummyAPI) RemoveNode(ctx context.Context, r *api.RemoveNodeRequest) (*api.RemoveNodeResponse, error) { ^ integration/api.go:81:20: func `(*dummyAPI).CreateService` is unused (unused) func (a *dummyAPI) CreateService(ctx context.Context, r *api.CreateServiceRequest) (*api.CreateServiceResponse, error) { ^ integration/api.go:135:20: func `(*dummyAPI).UpdateCluster` is unused (unused) func (a *dummyAPI) UpdateCluster(ctx context.Context, r *api.UpdateClusterRequest) (*api.UpdateClusterResponse, error) { ^ integration/cluster.go:156:23: func `(*testCluster).runNode` is unused (unused) func (c *testCluster) runNode(n *testNode, nodeOrder int) error { ^ integration/node.go:56:6: func `newTestNode` is unused (unused) func newTestNode(joinAddr, joinToken string, lateBind bool, fips bool) (*testNode, error) { ^ integration/cluster.go:28:6: type `testCluster` is unused (unused) type testCluster struct { ^ integration/api.go:111:20: func `(*dummyAPI).RemoveNetwork` is unused (unused) func (a *dummyAPI) RemoveNetwork(context.Context, *api.RemoveNetworkRequest) (*api.RemoveNetworkResponse, error) { ^ integration/api.go:77:20: func `(*dummyAPI).ListServices` is unused (unused) func (a *dummyAPI) ListServices(context.Context, *api.ListServicesRequest) (*api.ListServicesResponse, error) { ^ integration/node.go:174:20: func `(*testNode).IsManager` is unused (unused) func (n *testNode) IsManager() bool { ^ integration/api.go:13:20: func `(*dummyAPI).GetNode` is unused (unused) func (a *dummyAPI) GetNode(ctx context.Context, r *api.GetNodeRequest) (*api.GetNodeResponse, error) { ^ integration/node.go:29:6: func `generateCerts` is unused (unused) func generateCerts(tmpDir string, rootCA *ca.RootCA, nodeID, role, org string, writeKey bool) error { ^ integration/api.go:115:20: func `(*dummyAPI).GetCluster` is unused (unused) func (a *dummyAPI) GetCluster(ctx context.Context, r *api.GetClusterRequest) (*api.GetClusterResponse, error) { ^ integration/node.go:113:20: func `(*testNode).stop` is unused (unused) func (n *testNode) stop() error { ^ integration/api.go:73:20: func `(*dummyAPI).GetService` is unused (unused) func (a *dummyAPI) GetService(context.Context, *api.GetServiceRequest) (*api.GetServiceResponse, error) { ^ integration/cluster.go:196:23: func `(*testCluster).CreateService` is unused (unused) func (c *testCluster) CreateService(name string, instances int) (string, error) { ^ integration/cluster.go:378:23: func `(*testCluster).RotateUnlockKey` is unused (unused) func (c *testCluster) RotateUnlockKey() error { ^ integration/cluster.go:397:23: func `(*testCluster).AutolockManagers` is unused (unused) func (c *testCluster) AutolockManagers(autolock bool) error { ^ integration/cluster.go:76:23: func `(*testCluster).AddManager` is unused (unused) func (c *testCluster) AddManager(lateBind bool, rootCA *ca.RootCA) error { ^ integration/api.go:55:20: func `(*dummyAPI).GetTask` is unused (unused) func (a *dummyAPI) GetTask(context.Context, *api.GetTaskRequest) (*api.GetTaskResponse, error) { ^ integration/cluster.go:278:23: func `(*testCluster).SetNodeRole` is unused (unused) func (c *testCluster) SetNodeRole(id string, role api.NodeRole) error { ^ integration/cluster.go:61:23: func `(*testCluster).RandomManager` is unused (unused) func (c *testCluster) RandomManager() *testNode { ^ integration/api.go:69:20: func `(*dummyAPI).RemoveTask` is unused (unused) func (a *dummyAPI) RemoveTask(context.Context, *api.RemoveTaskRequest) (*api.RemoveTaskResponse, error) { ^ integration/node.go:145:20: func `(*testNode).Stop` is unused (unused) func (n *testNode) Stop() error { ^ integration/cluster.go:348:23: func `(*testCluster).GetClusterInfo` is unused (unused) func (c *testCluster) GetClusterInfo() (*api.Cluster, error) { ^ integration/cluster.go:241:23: func `(*testCluster).RemoveNode` is unused (unused) func (c *testCluster) RemoveNode(id string, graceful bool) error { ^ integration/api.go:125:20: func `(*dummyAPI).ListClusters` is unused (unused) func (a *dummyAPI) ListClusters(ctx context.Context, r *api.ListClustersRequest) (*api.ListClustersResponse, error) { ^ integration/cluster.go:145:23: func `(*testCluster).AddNode` is unused (unused) func (c *testCluster) AddNode(n *testNode) error { ^ integration/node.go:22:6: type `testNode` is unused (unused) type testNode struct { ^ integration/cluster.go:359:23: func `(*testCluster).RotateRootCA` is unused (unused) func (c *testCluster) RotateRootCA(cert, key []byte) error { ^ integration/api.go:103:20: func `(*dummyAPI).ListNetworks` is unused (unused) func (a *dummyAPI) ListNetworks(context.Context, *api.ListNetworksRequest) (*api.ListNetworksResponse, error) { ^ integration/api.go:95:20: func `(*dummyAPI).RemoveService` is unused (unused) func (a *dummyAPI) RemoveService(context.Context, *api.RemoveServiceRequest) (*api.RemoveServiceResponse, error) { ^ integration/api.go:91:20: func `(*dummyAPI).UpdateService` is unused (unused) func (a *dummyAPI) UpdateService(context.Context, *api.UpdateServiceRequest) (*api.UpdateServiceResponse, error) { ^ Signed-off-by: Sebastiaan van Stijn --- integration/{api.go => api_test.go} | 0 integration/{cluster.go => cluster_test.go} | 5 ++--- integration/integration_test.go | 8 +++----- integration/{node.go => node_test.go} | 3 +-- 4 files changed, 6 insertions(+), 10 deletions(-) rename integration/{api.go => api_test.go} (100%) rename integration/{cluster.go => cluster_test.go} (99%) rename integration/{node.go => node_test.go} (99%) diff --git a/integration/api.go b/integration/api_test.go similarity index 100% rename from integration/api.go rename to integration/api_test.go diff --git a/integration/cluster.go b/integration/cluster_test.go similarity index 99% rename from integration/cluster.go rename to integration/cluster_test.go index 0be39bb66b..4cacb3f669 100644 --- a/integration/cluster.go +++ b/integration/cluster_test.go @@ -9,9 +9,6 @@ import ( "sync" "time" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" - "github.com/moby/swarmkit/v2/api" "github.com/moby/swarmkit/v2/ca" "github.com/moby/swarmkit/v2/identity" @@ -20,6 +17,8 @@ import ( "github.com/moby/swarmkit/v2/node" "github.com/moby/swarmkit/v2/testutils" "github.com/sirupsen/logrus" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" ) const opsTimeout = 64 * time.Second diff --git a/integration/integration_test.go b/integration/integration_test.go index 00a7bb7bf8..8a570e580a 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -7,15 +7,12 @@ import ( "fmt" "os" "path/filepath" + "reflect" "runtime" "strings" "testing" "time" - "github.com/moby/swarmkit/v2/node" - - "reflect" - "github.com/cloudflare/cfssl/helpers" events "github.com/docker/go-events" "github.com/moby/swarmkit/v2/api" @@ -23,6 +20,7 @@ import ( cautils "github.com/moby/swarmkit/v2/ca/testutils" "github.com/moby/swarmkit/v2/identity" "github.com/moby/swarmkit/v2/manager" + "github.com/moby/swarmkit/v2/node" "github.com/moby/swarmkit/v2/testutils" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -399,7 +397,7 @@ func TestDemotePromoteLeader(t *testing.T) { numManager-- pollClusterReady(t, cl, numWorker, numManager) - //promote former leader back + // promote former leader back require.NoError(t, cl.SetNodeRole(leader.node.NodeID(), api.NodeRoleManager)) // agents 1, managers 3 numWorker-- diff --git a/integration/node.go b/integration/node_test.go similarity index 99% rename from integration/node.go rename to integration/node_test.go index af4802f859..016a85f14d 100644 --- a/integration/node.go +++ b/integration/node_test.go @@ -8,13 +8,12 @@ import ( "runtime" "strings" - "google.golang.org/grpc" - agentutils "github.com/moby/swarmkit/v2/agent/testutils" "github.com/moby/swarmkit/v2/api" "github.com/moby/swarmkit/v2/ca" "github.com/moby/swarmkit/v2/node" "github.com/moby/swarmkit/v2/testutils" + "google.golang.org/grpc" ) // TestNode is representation of *agent.Node. It stores listeners, connections, From ab69e467bc8d822e0844294736ede33a2351659c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Nov 2022 21:46:42 +0100 Subject: [PATCH 02/10] agent: fix linting issues (unused, misspell) agent/reporter.go:18:13: `recieves` is a misspelling of `receives` (misspell) // Reporter recieves update to both task and volume status. ^ agent/reporter.go:30:6: type `volumeReporterFunc` is unused (unused) type volumeReporterFunc func(ctx context.Context, volumeID string) error ^ agent/reporter.go:32:30: func `volumeReporterFunc.ReportVolumeUnpublished` is unused (unused) func (fn volumeReporterFunc) ReportVolumeUnpublished(ctx context.Context, volumeID string) error { ^ agent/reporter.go:36:6: `statusReporterCombined` is unused (deadcode) type statusReporterCombined struct { ^ agent/session.go:394:19: func `(*session).sendTaskStatuses` is unused (unused) func (s *session) sendTaskStatuses(ctx context.Context, updates ...*api.UpdateTaskStatusRequest_TaskStatusUpdate) ([]*api.UpdateTaskStatusRequest_TaskStatusUpdate, error) { ^ agent/worker.go:60:2: field `publisher` is unused (unused) publisher exec.LogPublisher ^ Signed-off-by: Sebastiaan van Stijn --- agent/reporter.go | 5 ++++- agent/session.go | 1 + agent/worker.go | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/agent/reporter.go b/agent/reporter.go index db7456c3b7..0abb565a03 100644 --- a/agent/reporter.go +++ b/agent/reporter.go @@ -15,7 +15,7 @@ type StatusReporter interface { UpdateTaskStatus(ctx context.Context, taskID string, status *api.TaskStatus) error } -// Reporter recieves update to both task and volume status. +// Reporter receives update to both task and volume status. type Reporter interface { StatusReporter ReportVolumeUnpublished(ctx context.Context, volumeID string) error @@ -27,12 +27,15 @@ func (fn statusReporterFunc) UpdateTaskStatus(ctx context.Context, taskID string return fn(ctx, taskID, status) } +//nolint:unused // currently only used in tests. type volumeReporterFunc func(ctx context.Context, volumeID string) error +//nolint:unused // currently only used in tests. func (fn volumeReporterFunc) ReportVolumeUnpublished(ctx context.Context, volumeID string) error { return fn(ctx, volumeID) } +//nolint:unused // currently only used in tests. type statusReporterCombined struct { statusReporterFunc volumeReporterFunc diff --git a/agent/session.go b/agent/session.go index 97d5621eb9..e751f4a654 100644 --- a/agent/session.go +++ b/agent/session.go @@ -391,6 +391,7 @@ func (s *session) sendTaskStatus(ctx context.Context, taskID string, taskStatus return nil } +//nolint:unused // TODO(thaJeztah) this is currently unused: is it safe to remove? func (s *session) sendTaskStatuses(ctx context.Context, updates ...*api.UpdateTaskStatusRequest_TaskStatusUpdate) ([]*api.UpdateTaskStatusRequest_TaskStatusUpdate, error) { if len(updates) < 1 { return nil, nil diff --git a/agent/worker.go b/agent/worker.go index ad51aa716e..2143f3506d 100644 --- a/agent/worker.go +++ b/agent/worker.go @@ -57,7 +57,6 @@ type statusReporterKey struct { type worker struct { db *bolt.DB executor exec.Executor - publisher exec.LogPublisher listeners map[*statusReporterKey]struct{} taskevents *watch.Queue publisherProvider exec.LogPublisherProvider From 70fdaf14738ffde5bca6b5861d9231d507600a24 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Nov 2022 22:22:28 +0100 Subject: [PATCH 03/10] agent/csi: fix linting issues (golint, revive) The CSI_CALL_TIMEOUT const looks to be only used internally, so un-exporting it. The PluginManager interface and NewPluginManager constructor have not yet been in a release, so renaming them. To be on the safe side, aliases were added. agent/csi/volumes.go:20:7: don't use ALL_CAPS in Go names; use CamelCase (golint) const CSI_CALL_TIMEOUT = 15 * time.Second ^ agent/csi/plugin/manager.go:23:6: exported: type name will be used as plugin.PluginManager by other packages, and that stutters; consider calling this Manager (revive) type PluginManager interface { ^ Signed-off-by: Sebastiaan van Stijn --- agent/csi/plugin/manager.go | 8 ++++---- agent/csi/plugin/manager_deprecated.go | 11 +++++++++++ agent/csi/plugin/manager_test.go | 2 +- agent/csi/plugin/plugin_fake_test.go | 2 +- agent/csi/volumes.go | 10 +++++----- 5 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 agent/csi/plugin/manager_deprecated.go diff --git a/agent/csi/plugin/manager.go b/agent/csi/plugin/manager.go index 39bb60f450..26c74f79f5 100644 --- a/agent/csi/plugin/manager.go +++ b/agent/csi/plugin/manager.go @@ -18,9 +18,9 @@ const ( DockerCSIPluginCap = "csinode" ) -// PluginManager manages the multiple CSI plugins that may be in use on the -// node. PluginManager should be thread-safe. -type PluginManager interface { +// Manager manages the multiple CSI plugins that may be in use on the +// node. Manager should be thread-safe. +type Manager interface { // Get gets the plugin with the given name Get(name string) (NodePlugin, error) @@ -43,7 +43,7 @@ type pluginManager struct { pg plugingetter.PluginGetter } -func NewPluginManager(pg plugingetter.PluginGetter, secrets SecretGetter) PluginManager { +func NewManager(pg plugingetter.PluginGetter, secrets SecretGetter) Manager { return &pluginManager{ plugins: map[string]NodePlugin{}, newNodePluginFunc: NewNodePlugin, diff --git a/agent/csi/plugin/manager_deprecated.go b/agent/csi/plugin/manager_deprecated.go new file mode 100644 index 0000000000..5c814c7e93 --- /dev/null +++ b/agent/csi/plugin/manager_deprecated.go @@ -0,0 +1,11 @@ +package plugin + +// Deprecated: use [Manager]. +// +//nolint:revive // exported: type name will be used as plugin.PluginManager by other packages +type PluginManager = Manager + +// Deprecated: use [NewManager]. +// +//nolint:unused +var NewPluginManager = NewManager diff --git a/agent/csi/plugin/manager_test.go b/agent/csi/plugin/manager_test.go index a0e94a310e..092efa43f4 100644 --- a/agent/csi/plugin/manager_test.go +++ b/agent/csi/plugin/manager_test.go @@ -10,7 +10,7 @@ import ( "github.com/moby/swarmkit/v2/testutils" ) -var _ = Describe("PluginManager", func() { +var _ = Describe("Manager", func() { var ( pm *pluginManager pg *testutils.FakePluginGetter diff --git a/agent/csi/plugin/plugin_fake_test.go b/agent/csi/plugin/plugin_fake_test.go index 8600a39e17..f1fdc60c5c 100644 --- a/agent/csi/plugin/plugin_fake_test.go +++ b/agent/csi/plugin/plugin_fake_test.go @@ -39,7 +39,7 @@ func (f *fakeNodePlugin) NodeGetInfo(ctx context.Context) (*api.NodeCSIInfo, err } // these methods are all stubs, as they are not needed for testing the -// PluginManager. +// Manager. func (f *fakeNodePlugin) GetPublishedPath(volumeID string) string { return "" } diff --git a/agent/csi/volumes.go b/agent/csi/volumes.go index a2127fc963..46fd772cf9 100644 --- a/agent/csi/volumes.go +++ b/agent/csi/volumes.go @@ -17,7 +17,7 @@ import ( "github.com/moby/swarmkit/v2/volumequeue" ) -const CSI_CALL_TIMEOUT = 15 * time.Second +const csiCallTimeout = 15 * time.Second // volumeState keeps track of the state of a volume on this node. type volumeState struct { @@ -39,8 +39,8 @@ type volumes struct { // volumes is a mapping of volume ID to volumeState volumes map[string]volumeState - // plugins is the PluginManager, which provides translation to the CSI RPCs - plugins plugin.PluginManager + // plugins is the Manager, which provides translation to the CSI RPCs + plugins plugin.Manager // pendingVolumes is a VolumeQueue which manages which volumes are // processed and when. @@ -51,7 +51,7 @@ type volumes struct { func NewManager(pg plugingetter.PluginGetter, secrets exec.SecretGetter) exec.VolumesManager { r := &volumes{ volumes: map[string]volumeState{}, - plugins: plugin.NewPluginManager(pg, secrets), + plugins: plugin.NewManager(pg, secrets), pendingVolumes: volumequeue.NewVolumeQueue(), } go r.retryVolumes() @@ -107,7 +107,7 @@ func (r *volumes) tryVolume(ctx context.Context, id string, attempt uint) { // These are too complicated to be worth the engineering effort at this // time. - timeoutCtx, cancel := context.WithTimeout(ctx, CSI_CALL_TIMEOUT) + timeoutCtx, cancel := context.WithTimeout(ctx, csiCallTimeout) // always gotta call the WithTimeout cancel defer cancel() From c768a6c91774fd3cfa6e113a4b5ef51c72488cf3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Nov 2022 22:00:03 +0100 Subject: [PATCH 04/10] agent/exec: fix linting issues (unused) agent/exec/dockerapi/container.go:79:27: func `(*containerConfig).endpoint` is unused (unused) func (c *containerConfig) endpoint() *api.Endpoint { ^ agent/exec/dockerapi/container.go:482:27: func `(*containerConfig).virtualIP` is unused (unused) func (c *containerConfig) virtualIP(networkID string) string { ^ agent/exec/controller_stub.go:24:2: field `cstatus` is unused (unused) cstatus *api.ContainerStatus ^ Signed-off-by: Sebastiaan van Stijn --- agent/exec/controller_stub.go | 1 - agent/exec/dockerapi/container.go | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/agent/exec/controller_stub.go b/agent/exec/controller_stub.go index 6775779e59..ce24158937 100644 --- a/agent/exec/controller_stub.go +++ b/agent/exec/controller_stub.go @@ -21,7 +21,6 @@ type StubController struct { RemoveFn func(ctx context.Context) error CloseFn func() error calls map[string]int - cstatus *api.ContainerStatus } // NewStubController returns an initialized StubController diff --git a/agent/exec/dockerapi/container.go b/agent/exec/dockerapi/container.go index 2a5e74b945..05ba1efe23 100644 --- a/agent/exec/dockerapi/container.go +++ b/agent/exec/dockerapi/container.go @@ -76,6 +76,7 @@ func (c *containerConfig) setTask(n *api.NodeDescription, t *api.Task) error { return nil } +//nolint:unused // TODO(thaJeztah) this is currently unused: is it safe to remove? func (c *containerConfig) endpoint() *api.Endpoint { return c.task.Endpoint } @@ -479,6 +480,7 @@ func (c *containerConfig) resources() enginecontainer.Resources { return resources } +//nolint:unused // TODO(thaJeztah) this is currently unused: is it safe to remove? func (c *containerConfig) virtualIP(networkID string) string { if c.task.Endpoint == nil { return "" From b9e0197397bc8363a642266b373e1075f9b91f45 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Nov 2022 22:38:42 +0100 Subject: [PATCH 05/10] ca: fix linting issues (unused) Field is no longer used since 32522512dd0a579346569a7751935e5d3d8a3daa ca/server.go:68:2: field `rootReconciler` is unused (unused) rootReconciler *rootRotationReconciler ^ Signed-off-by: Sebastiaan van Stijn --- ca/server.go | 1 - 1 file changed, 1 deletion(-) diff --git a/ca/server.go b/ca/server.go index 44a51b5e24..19f495c4ed 100644 --- a/ca/server.go +++ b/ca/server.go @@ -65,7 +65,6 @@ type Server struct { signingMu sync.Mutex // lets us monitor and finish root rotations - rootReconciler *rootRotationReconciler rootReconciliationRetryInterval time.Duration } From 5ca936692ac0bf15a53c6b8d304899c49fdb1eeb Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Nov 2022 22:07:34 +0100 Subject: [PATCH 06/10] manager/allocator: fix linting issues (unused) manager/allocator/network.go:378:21: func `(*Allocator).getAllocatedNetworks` is unused (unused) func (a *Allocator) getAllocatedNetworks() ([]*api.Network, error) { ^ manager/allocator/network.go:509:21: func `(*Allocator).deallocateNodes` is unused (unused) func (a *Allocator) deallocateNodes(ctx context.Context) error { ^ Signed-off-by: Sebastiaan van Stijn --- manager/allocator/network.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manager/allocator/network.go b/manager/allocator/network.go index d39f8627d9..673da84996 100644 --- a/manager/allocator/network.go +++ b/manager/allocator/network.go @@ -375,6 +375,7 @@ func isOverlayNetwork(n *api.Network) bool { return false } +//nolint:unused // TODO(thaJeztah) this is currently unused: is it safe to remove? func (a *Allocator) getAllocatedNetworks() ([]*api.Network, error) { var ( err error @@ -506,6 +507,7 @@ func (a *Allocator) allocateNodes(ctx context.Context, existingAddressesOnly boo return nil } +//nolint:unused // TODO(thaJeztah) this is currently unused: is it safe to remove? func (a *Allocator) deallocateNodes(ctx context.Context) error { var ( nodes []*api.Node From f78638e79d7f06581308012358107dd6182ababa Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Nov 2022 22:04:50 +0100 Subject: [PATCH 07/10] manager/allocator/cnmallocator: fix linting issues (unused) manager/allocator/cnmallocator/portallocator.go:300:26: func `(*portAllocator).isPortsAllocated` is unused (unused) func (pa *portAllocator) isPortsAllocated(s *api.Service) bool { ^ Signed-off-by: Sebastiaan van Stijn --- manager/allocator/cnmallocator/portallocator.go | 4 ---- manager/allocator/cnmallocator/portallocator_test.go | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/manager/allocator/cnmallocator/portallocator.go b/manager/allocator/cnmallocator/portallocator.go index 303ac13b6b..3e5e1c4443 100644 --- a/manager/allocator/cnmallocator/portallocator.go +++ b/manager/allocator/cnmallocator/portallocator.go @@ -297,10 +297,6 @@ func (pa *portAllocator) hostPublishPortsNeedUpdate(s *api.Service) bool { return false } -func (pa *portAllocator) isPortsAllocated(s *api.Service) bool { - return pa.isPortsAllocatedOnInit(s, false) -} - func (pa *portAllocator) isPortsAllocatedOnInit(s *api.Service, onInit bool) bool { // If service has no user-defined endpoint and allocated endpoint, // we assume it is allocated and return true. diff --git a/manager/allocator/cnmallocator/portallocator_test.go b/manager/allocator/cnmallocator/portallocator_test.go index cbda0a3a50..b514f40077 100644 --- a/manager/allocator/cnmallocator/portallocator_test.go +++ b/manager/allocator/cnmallocator/portallocator_test.go @@ -879,7 +879,7 @@ func TestIsPortsAllocated(t *testing.T) { for _, singleTest := range testCases { t.Run(singleTest.name, func(t *testing.T) { - expect := pa.isPortsAllocated(singleTest.input) + expect := pa.isPortsAllocatedOnInit(singleTest.input, false) assert.Equal(t, expect, singleTest.expect) }) } From 9756c8e166d7695ffd4f3468bf7a66f364dbec2e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Nov 2022 22:27:32 +0100 Subject: [PATCH 08/10] manager/scheduler: fix linting issues (unused) manager/scheduler/volumes.go:80:22: func `(*volumeSet).removeVolume` is unused (unused) func (vs *volumeSet) removeVolume(volumeID string) { ^ manager/scheduler/volumes.go:53:22: func `(*volumeSet).getVolume` is unused (unused) func (vs *volumeSet) getVolume(id string) *api.Volume { ^ Signed-off-by: Sebastiaan van Stijn --- manager/scheduler/volumes.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/manager/scheduler/volumes.go b/manager/scheduler/volumes.go index 12383c98ef..9ddba6be16 100644 --- a/manager/scheduler/volumes.go +++ b/manager/scheduler/volumes.go @@ -50,9 +50,11 @@ func newVolumeSet() *volumeSet { } } +// getVolume returns the volume object for the given ID as stored in the +// volumeSet, or nil if none exists. +// +//nolint:unused // TODO(thaJeztah) this is currently unused: is it safe to remove? func (vs *volumeSet) getVolume(id string) *api.Volume { - // getVolume returns the volume object for the given ID as stored in the - // volumeSet, or nil if none exists return vs.volumes[id].volume } @@ -77,6 +79,7 @@ func (vs *volumeSet) addOrUpdateVolume(v *api.Volume) { vs.byName[v.Spec.Annotations.Name] = v.ID } +//nolint:unused // only used in tests. func (vs *volumeSet) removeVolume(volumeID string) { if info, ok := vs.volumes[volumeID]; ok { // if the volume exists in the set, look up its group ID and remove it From 6e497f6ca20ec9a389c090703ab1295a8be3dbec Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Nov 2022 22:29:47 +0100 Subject: [PATCH 09/10] manager/state/raft: fix linting issues (unused) manager/state/raft/raft.go:1292:16: func `(*Node).reportNewAddress` is unused (unused) func (n *Node) reportNewAddress(ctx context.Context, id uint64) error { ^ manager/state/raft/raft.go:136:2: field `removeRaftCh` is unused (unused) removeRaftCh chan struct{} ^ Signed-off-by: Sebastiaan van Stijn --- manager/state/raft/raft.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manager/state/raft/raft.go b/manager/state/raft/raft.go index 86e313958e..3d607b1350 100644 --- a/manager/state/raft/raft.go +++ b/manager/state/raft/raft.go @@ -132,8 +132,7 @@ type Node struct { // RemovedFromRaft notifies about node deletion from raft cluster RemovedFromRaft chan struct{} cancelFunc func() - // removeRaftCh notifies about node deletion from raft cluster - removeRaftCh chan struct{} + removeRaftOnce sync.Once leadershipBroadcast *watch.Queue @@ -1289,6 +1288,7 @@ func (n *Node) processRaftMessageLogger(ctx context.Context, msg *api.ProcessRaf return log.G(ctx).WithFields(fields) } +//nolint:unused // currently unused, but should be used again; see TODO in Node.ProcessRaftMessage func (n *Node) reportNewAddress(ctx context.Context, id uint64) error { // too early if !n.IsMember() { @@ -1418,9 +1418,9 @@ func (n *Node) ProcessRaftMessage(ctx context.Context, msg *api.ProcessRaftMessa // See https://github.com/docker/docker/issues/30455. // This should be reenabled in the future with additional // safeguards (perhaps storing multiple addresses per node). - //if err := n.reportNewAddress(ctx, msg.Message.From); err != nil { + // if err := n.reportNewAddress(ctx, msg.Message.From); err != nil { // log.G(ctx).WithError(err).Errorf("failed to report new address of %x to transport", msg.Message.From) - //} + // } // Reject vote requests from unreachable peers if msg.Message.Type == raftpb.MsgVote { From bacc574fc374e55a0ca34c86bc4d3db119b20a51 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Nov 2022 20:13:45 +0100 Subject: [PATCH 10/10] update golangci-lint to v1.50.1 WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused. WARN [runner] The linter 'golint' is deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner. Replaced by revive. Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 7 ++++--- direct.mk | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 694ae5c372..e464d9c980 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,14 +1,15 @@ run: tests: false + timeout: 10m linters: disable-all: true enable: - misspell - gofmt - goimports - - golint - ineffassign - - deadcode + - revive - unconvert + - unused - govet - + diff --git a/direct.mk b/direct.mk index c142a3b584..bca9a1383a 100644 --- a/direct.mk +++ b/direct.mk @@ -37,8 +37,8 @@ version/version.go: .PHONY: setup setup: ## install dependencies @echo "🐳 $@" - # install golangci-lint version 1.17.1 to ./bin/golangci-lint - @curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/v1.17.1/install.sh | sh -s v1.17.1 + # install golangci-lint version v1.50.1 to ./bin/golangci-lint + @curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/v1.50.1/install.sh | sh -s v1.50.1 @(cd tools ; GO111MODULE=on go install github.com/containerd/protobuild) .PHONY: generate