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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,60 @@
version: "2"

run:
tests: false
timeout: 10m

linters:
disable-all: true
default: none
enable:
- misspell
- gofmt
- goimports
- ineffassign
- revive
- unconvert
- unused
- govet
settings:
govet:
enable:
- nilness
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- revive
text: stutters
- linters:
- revive
text: empty-block
- linters:
- revive
text: superfluous-else
- linters:
- revive
text: unused-parameter
- linters:
- revive
text: redefines-builtin-id
- linters:
- revive
text: if-return
paths:
- .*\.pb\.go$

formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- .*\.pb\.go$

issues:
exclude-files:
- ".*\\.pb\\.go$"
max-issues-per-linter: 0
max-same-issues: 0
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION=1.21
ARG GO_VERSION=1.24
ARG PROTOC_VERSION=3.11.4
ARG GOLANGCI_LINT_VERSION=v1.57.2
ARG GOLANGCI_LINT_VERSION=v2.1.5
ARG DEBIAN_FRONTEND=noninteractive

FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bullseye AS gobase
Expand Down
6 changes: 3 additions & 3 deletions ca/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (s *Server) GetUnlockKey(_ context.Context, _ *api.GetUnlockKeyRequest) (*a
// NodeCertificateStatus returns the current issuance status of an issuance request identified by the nodeID
func (s *Server) NodeCertificateStatus(ctx context.Context, request *api.NodeCertificateStatusRequest) (*api.NodeCertificateStatusResponse, error) {
if request.NodeID == "" {
return nil, status.Errorf(codes.InvalidArgument, codes.InvalidArgument.String())
return nil, status.Error(codes.InvalidArgument, codes.InvalidArgument.String())
}

serverCtx, err := s.isRunningLocked()
Expand Down Expand Up @@ -178,7 +178,7 @@ func (s *Server) NodeCertificateStatus(ctx context.Context, request *api.NodeCer

// This node ID doesn't exist
if node == nil {
return nil, status.Errorf(codes.NotFound, codes.NotFound.String())
return nil, status.Error(codes.NotFound, codes.NotFound.String())
}

log.G(ctx).WithFields(log.Fields{
Expand Down Expand Up @@ -234,7 +234,7 @@ func (s *Server) NodeCertificateStatus(ctx context.Context, request *api.NodeCer
func (s *Server) IssueNodeCertificate(ctx context.Context, request *api.IssueNodeCertificateRequest) (*api.IssueNodeCertificateResponse, error) {
// First, let's see if the remote node is presenting a non-empty CSR
if len(request.CSR) == 0 {
return nil, status.Errorf(codes.InvalidArgument, codes.InvalidArgument.String())
return nil, status.Error(codes.InvalidArgument, codes.InvalidArgument.String())
}

if err := s.isReadyLocked(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion direct.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ version/version.go:
setup: ## install dependencies
@echo "🐳 $@"
# install golangci-lint to ./bin/golangci-lint
@curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/v1.57.2/install.sh | sh -s v1.57.2
@curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/v2.1.5/install.sh | sh -s v2.1.5
@(cd ./tools ; GO111MODULE=on go install github.com/containerd/protobuild)

.PHONY: generate
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/moby/swarmkit/v2

go 1.21.0
go 1.23.0

require (
code.cloudfoundry.org/clock v1.1.0
Expand Down
36 changes: 12 additions & 24 deletions manager/allocator/allocator_test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2083,24 +2083,21 @@ func watchNode(t *testing.T, watch chan events.Event, expectTimeout bool,
case event := <-watch:
if n, ok := event.(api.EventUpdateNode); ok {
node = n.Node.Copy()
if fn == nil || (fn != nil && fn(mockTester{}, originalNode, node, networks)) {
if fn == nil || fn(mockTester{}, originalNode, node, networks) {
return
}
}

if n, ok := event.(api.EventDeleteNode); ok {
node = n.Node.Copy()
if fn == nil || (fn != nil && fn(mockTester{}, originalNode, node, networks)) {
if fn == nil || fn(mockTester{}, originalNode, node, networks) {
return
}
}

case <-time.After(getWatchTimeout(expectTimeout)):
if !expectTimeout {
if node != nil && fn != nil {
fn(t, originalNode, node, networks)
}

fn(t, originalNode, node, networks)
t.Fatal("timed out before watchNode found expected node state", string(debug.Stack()))
}

Expand All @@ -2116,24 +2113,21 @@ func watchNetwork(t *testing.T, watch chan events.Event, expectTimeout bool, fn
case event := <-watch:
if n, ok := event.(api.EventUpdateNetwork); ok {
network = n.Network.Copy()
if fn == nil || (fn != nil && fn(mockTester{}, network)) {
if fn == nil || fn(mockTester{}, network) {
return
}
}

if n, ok := event.(api.EventDeleteNetwork); ok {
network = n.Network.Copy()
if fn == nil || (fn != nil && fn(mockTester{}, network)) {
if fn == nil || fn(mockTester{}, network) {
return
}
}

case <-time.After(getWatchTimeout(expectTimeout)):
if !expectTimeout {
if network != nil && fn != nil {
fn(t, network)
}

fn(t, network)
t.Fatal("timed out before watchNetwork found expected network state", string(debug.Stack()))
}

Expand All @@ -2149,24 +2143,21 @@ func watchService(t *testing.T, watch chan events.Event, expectTimeout bool, fn
case event := <-watch:
if s, ok := event.(api.EventUpdateService); ok {
service = s.Service.Copy()
if fn == nil || (fn != nil && fn(mockTester{}, service)) {
if fn == nil || fn(mockTester{}, service) {
return
}
}

if s, ok := event.(api.EventDeleteService); ok {
service = s.Service.Copy()
if fn == nil || (fn != nil && fn(mockTester{}, service)) {
if fn == nil || fn(mockTester{}, service) {
return
}
}

case <-time.After(getWatchTimeout(expectTimeout)):
if !expectTimeout {
if service != nil && fn != nil {
fn(t, service)
}

fn(t, service)
t.Fatalf("timed out before watchService found expected service state\n stack = %s", string(debug.Stack()))
}

Expand All @@ -2182,24 +2173,21 @@ func watchTask(t *testing.T, s *store.MemoryStore, watch chan events.Event, expe
case event := <-watch:
if t, ok := event.(api.EventUpdateTask); ok {
task = t.Task.Copy()
if fn == nil || (fn != nil && fn(mockTester{}, s, task)) {
if fn == nil || fn(mockTester{}, s, task) {
return
}
}

if t, ok := event.(api.EventDeleteTask); ok {
task = t.Task.Copy()
if fn == nil || (fn != nil && fn(mockTester{}, s, task)) {
if fn == nil || fn(mockTester{}, s, task) {
return
}
}

case <-time.After(getWatchTimeout(expectTimeout)):
if !expectTimeout {
if task != nil && fn != nil {
fn(t, s, task)
}

fn(t, s, task)
t.Fatalf("timed out before watchTask found expected task state %s", debug.Stack())
}

Expand Down
4 changes: 2 additions & 2 deletions manager/controlapi/ca_rotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func validateCAConfig(ctx context.Context, securityConfig *ca.SecurityConfig, cl
if cluster.RootCA.LastForcedRotation != newConfig.ForceRotate {
newRootCA, err := ca.CreateRootCA(ca.DefaultRootCN)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
return newRootRotationObject(ctx, securityConfig, &cluster.RootCA, newRootCA, oldCertExtCAs, newConfig.ForceRotate)
}
Expand All @@ -265,7 +265,7 @@ func validateCAConfig(ctx context.Context, securityConfig *ca.SecurityConfig, cl
}
newRootCA, err := ca.NewRootCA(newConfig.SigningCACert, signingCert, newConfig.SigningCAKey, ca.DefaultNodeCertExpiration, nil)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
return nil, status.Error(codes.InvalidArgument, err.Error())
}

if len(newRootCA.Pool.Subjects()) != 1 {
Expand Down
10 changes: 5 additions & 5 deletions manager/controlapi/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ var (

func validateClusterSpec(spec *api.ClusterSpec) error {
if spec == nil {
return status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}

// Validate that expiry time being provided is valid, and over our minimum
if spec.CAConfig.NodeCertExpiry != nil {
expiry, err := gogotypes.DurationFromProto(spec.CAConfig.NodeCertExpiry)
if err != nil {
return status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}
if expiry < ca.MinNodeCertExpiration {
return status.Errorf(codes.InvalidArgument, "minimum certificate expiry time is: %s", ca.MinNodeCertExpiration)
Expand All @@ -60,7 +60,7 @@ func validateClusterSpec(spec *api.ClusterSpec) error {
if spec.Dispatcher.HeartbeatPeriod != nil {
heartbeatPeriod, err := gogotypes.DurationFromProto(spec.Dispatcher.HeartbeatPeriod)
if err != nil {
return status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}
if heartbeatPeriod < 0 {
return status.Errorf(codes.InvalidArgument, "heartbeat time period cannot be a negative duration")
Expand All @@ -79,7 +79,7 @@ func validateClusterSpec(spec *api.ClusterSpec) error {
// - Returns `NotFound` if the Cluster is not found.
func (s *Server) GetCluster(_ context.Context, request *api.GetClusterRequest) (*api.GetClusterResponse, error) {
if request.ClusterID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return nil, status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}

var cluster *api.Cluster
Expand All @@ -105,7 +105,7 @@ func (s *Server) GetCluster(_ context.Context, request *api.GetClusterRequest) (
// - Returns an error if the update fails.
func (s *Server) UpdateCluster(ctx context.Context, request *api.UpdateClusterRequest) (*api.UpdateClusterResponse, error) {
if request.ClusterID == "" || request.ClusterVersion == nil {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return nil, status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}
if err := validateClusterSpec(request.Spec); err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions manager/controlapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *Server) GetConfig(_ context.Context, request *api.GetConfigRequest) (*a
// - Returns an error if the update fails.
func (s *Server) UpdateConfig(ctx context.Context, request *api.UpdateConfigRequest) (*api.UpdateConfigResponse, error) {
if request.ConfigID == "" || request.ConfigVersion == nil {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return nil, status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}

var config *api.Config
Expand Down Expand Up @@ -234,7 +234,7 @@ func (s *Server) RemoveConfig(ctx context.Context, request *api.RemoveConfigRequ

func validateConfigSpec(spec *api.ConfigSpec) error {
if spec == nil {
return status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}
if err := validateConfigOrSecretAnnotations(spec.Annotations); err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions manager/controlapi/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *Server) validateIPAM(ipam *api.IPAMOptions) error {

func (s *Server) validateNetworkSpec(spec *api.NetworkSpec) error {
if spec == nil {
return status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}

if spec.Attachable && spec.Ingress {
Expand Down Expand Up @@ -138,7 +138,7 @@ func (s *Server) CreateNetwork(_ context.Context, request *api.CreateNetworkRequ
// - Returns `NotFound` if the Network is not found.
func (s *Server) GetNetwork(ctx context.Context, request *api.GetNetworkRequest) (*api.GetNetworkResponse, error) {
if request.NetworkID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return nil, status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}

var n *api.Network
Expand All @@ -162,7 +162,7 @@ func (s *Server) GetNetwork(ctx context.Context, request *api.GetNetworkRequest)
// - Returns an error if the deletion fails.
func (s *Server) RemoveNetwork(_ context.Context, request *api.RemoveNetworkRequest) (*api.RemoveNetworkResponse, error) {
if request.NetworkID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return nil, status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}

var (
Expand Down
8 changes: 4 additions & 4 deletions manager/controlapi/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func validateNodeSpec(spec *api.NodeSpec) error {
if spec == nil {
return status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}
return nil
}
Expand All @@ -25,7 +25,7 @@ func validateNodeSpec(spec *api.NodeSpec) error {
// - Returns `NotFound` if the Node is not found.
func (s *Server) GetNode(_ context.Context, request *api.GetNodeRequest) (*api.GetNodeResponse, error) {
if request.NodeID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return nil, status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}

var node *api.Node
Expand Down Expand Up @@ -202,7 +202,7 @@ func (s *Server) ListNodes(_ context.Context, request *api.ListNodesRequest) (*a
// - Returns an error if the update fails.
func (s *Server) UpdateNode(_ context.Context, request *api.UpdateNodeRequest) (*api.UpdateNodeResponse, error) {
if request.NodeID == "" || request.NodeVersion == nil {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return nil, status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}
if err := validateNodeSpec(request.Spec); err != nil {
return nil, err
Expand Down Expand Up @@ -293,7 +293,7 @@ func orphanNodeTasks(tx store.Tx, nodeID string) error {
// - Returns an error if the delete fails.
func (s *Server) RemoveNode(_ context.Context, request *api.RemoveNodeRequest) (*api.RemoveNodeResponse, error) {
if request.NodeID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
return nil, status.Error(codes.InvalidArgument, errInvalidArgument.Error())
}

err := s.store.Update(func(tx store.Tx) error {
Expand Down
Loading