Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

update hack/tools, update golangci-lint and fix lints #879

Merged
merged 2 commits into from
Jul 10, 2024
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
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
directories:
- "/"
- "./hack/tools"
schedule:
interval: "weekly"
labels:
Expand Down
43 changes: 26 additions & 17 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
run:
go: "1.18"
go: "1.22"
timeout: 10m
tests: false
allow-parallel-runners: true
skip-dirs:
- "./*/mock"

linters-settings:
funlen:
lines: 110
statements: 60
staticcheck:
go: "1.18"
stylecheck:
go: "1.18"
cyclop:
max-complexity: 15
skip-tests: true
gosec:
exclude-generated: true
excludes:
- G108
lll:
line-length: 120
misspell:
locale: GB
locale: UK
goimports:
local-prefixes: github.com/liquidmetal-dev/flintlock
govet:
check-shadowing: true
nolintlint:
allow-leading-space: false
allow-unused: false
require-explanation: true
require-specific: false
Expand Down Expand Up @@ -85,21 +78,37 @@ issues:
- path: test/e2e/
linters:
- goerr113
- gomnd
- mnd
# remove this once https://github.com/golangci/golangci-lint/issues/2649 is closed
- path: /
linters:
- typecheck
exclude-dirs:
- "./*/mock"

linters:
enable-all: true
disable:
- exhaustivestruct
- golint
- interfacer
- bodyclose
- contextcheck
- cyclop
- depguard
- exhaustruct
- err113
- forcetypeassert
- ireturn
- maligned
- interfacebloat
- inamedparam
- musttag
- nonamedreturns
- nilnil
- scopelint
- tagliatelle
- gomoddirectives
- gochecknoglobals
- gci
- varnamelen
- protogetter
- gomnd
- mnd
- wsl
- wrapcheck
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ generate: ## Generate code
$(MAKE) generate-di

.PHONY: generate-go
generate-go: $(MOCKGEN) ## Generate Go Code
generate-go: $(MOCKGEN) ## Generate Go Code
go generate ./infrastructure/mock

.PHONY: generate-proto ## Generate protobuf/grpc code
Expand Down Expand Up @@ -165,7 +165,7 @@ $(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod # Get and build golangci-lint
cd $(TOOLS_DIR); go build -tags=tools -o $(subst hack/tools/,,$@) github.com/golangci/golangci-lint/cmd/golangci-lint

$(GINKGO): $(TOOLS_DIR)/go.mod # Get and build gginkgo
cd $(TOOLS_DIR); go build -tags=tools -o $(subst hack/tools/,,$@) github.com/onsi/ginkgo/ginkgo
cd $(TOOLS_DIR); go build -tags=tools -o $(subst hack/tools/,,$@) github.com/onsi/ginkgo/v2/ginkgo

$(MOCKGEN): $(TOOLS_DIR)/go.mod # Get and build mockgen
cd $(TOOLS_DIR); go build -tags=tools -o $(subst hack/tools/,,$@) github.com/golang/mock/mockgen
Expand Down
15 changes: 8 additions & 7 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ go 1.17

require (
github.com/containerd/typeurl/v2 v2.1.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
google.golang.org/genproto v0.0.0-20211021150943-2b146023228c
google.golang.org/grpc v1.41.0
google.golang.org/protobuf v1.27.1
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.1
)

require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.15.0 // indirect
)
324 changes: 16 additions & 308 deletions api/go.sum

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion cmd/flintlock-metrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package main
import (
"os"

"github.com/liquidmetal-dev/flintlock/internal/command/metrics"
"github.com/sirupsen/logrus"

"github.com/liquidmetal-dev/flintlock/internal/command/metrics"
)

func main() {
Expand Down
7 changes: 3 additions & 4 deletions core/application/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"encoding/base64"
"fmt"

"github.com/sirupsen/logrus"
"sigs.k8s.io/yaml"

"github.com/liquidmetal-dev/flintlock/api/events"
"github.com/liquidmetal-dev/flintlock/client/cloudinit"
"github.com/liquidmetal-dev/flintlock/client/cloudinit/instance"
Expand All @@ -14,8 +17,6 @@ import (
"github.com/liquidmetal-dev/flintlock/pkg/defaults"
"github.com/liquidmetal-dev/flintlock/pkg/log"
"github.com/liquidmetal-dev/flintlock/pkg/validation"
"github.com/sirupsen/logrus"
"sigs.k8s.io/yaml"
)

const (
Expand Down Expand Up @@ -216,6 +217,4 @@ func (a *app) addMetadataInterface(mvm *models.MicroVM) {
}
interfaces = append(interfaces, mvm.Spec.NetworkInterfaces...)
mvm.Spec.NetworkInterfaces = interfaces

return
}
3 changes: 2 additions & 1 deletion core/application/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"time"

"github.com/sirupsen/logrus"

"github.com/liquidmetal-dev/flintlock/api/events"
"github.com/liquidmetal-dev/flintlock/core/models"
"github.com/liquidmetal-dev/flintlock/core/plans"
Expand All @@ -13,7 +15,6 @@ import (
"github.com/liquidmetal-dev/flintlock/pkg/defaults"
"github.com/liquidmetal-dev/flintlock/pkg/log"
"github.com/liquidmetal-dev/flintlock/pkg/planner"
"github.com/sirupsen/logrus"
)

const backoffBaseInSeconds = 20
Expand Down
6 changes: 3 additions & 3 deletions core/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
ErrNoMount = errors.New("no image mount point")
ErrNoVolumeMount = errors.New("no volume mount point")
ErrParentIfaceRequiredForMacvtap = errors.New("a parent network device name is required for macvtap interfaces")
ErrParentIfaceRequiredForAttachingTap = errors.New("a parent network device name is required for attaching a TAP interface")
ErrParentIfaceRequiredForAttachingTap = errors.New("a parent network device name is required for attaching a TAP interface") //nolint: lll // that is okay
ErrGuestDeviceNameRequired = errors.New("a guest device name is required")
ErrUnsupportedIfaceType = errors.New("unsupported network interface type")
ErrIfaceNotFound = errors.New("network interface not found")
Expand All @@ -41,7 +41,7 @@ type IncorrectVMIDFormatError struct {

// Error returns the error message.
func (e IncorrectVMIDFormatError) Error() string {
return fmt.Sprintf("unexpected vmid format: %s", e.ActualID)
return "unexpected vmid format: " + e.ActualID
}

func NewErrUnsupportedInterface(ifaceType string) UnsupportedInterfaceError {
Expand Down Expand Up @@ -136,7 +136,7 @@ type notSupportedError struct {

// Error returns the error message.
func (e notSupportedError) Error() string {
return fmt.Sprintf("%s is not supported", e.unsupported)
return e.unsupported + "is not supported"
}

// IsNotSupported tests an error to see if its a not supported error.
Expand Down
2 changes: 1 addition & 1 deletion core/models/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (v Volumes) GetByID(id string) *Volume {
}

// HasMountableVolumes returns true if any of the volumes
// have a mount point defined
// have a mount point defined.
func (v Volumes) HasMountableVolumes() bool {
for _, vol := range v {
if vol.MountPoint != "" {
Expand Down
3 changes: 2 additions & 1 deletion core/plans/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package plans

import (
"github.com/liquidmetal-dev/flintlock/core/ports"
"github.com/spf13/afero"

"github.com/liquidmetal-dev/flintlock/core/ports"
)

// Providers input is a type to be used as input to plans.
Expand Down
2 changes: 1 addition & 1 deletion core/steps/cloudinit/disk_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (s *diskMountStep) Do(ctx context.Context) ([]planner.Procedure, error) {
return nil, nil
}

func (s *diskMountStep) Verify(ctx context.Context) error {
func (s *diskMountStep) Verify(_ context.Context) error {
return nil
}

Expand Down
7 changes: 4 additions & 3 deletions core/steps/event/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"fmt"

"github.com/sirupsen/logrus"

"github.com/liquidmetal-dev/flintlock/core/ports"
"github.com/liquidmetal-dev/flintlock/pkg/log"
"github.com/liquidmetal-dev/flintlock/pkg/planner"
"github.com/sirupsen/logrus"
)

func NewPublish(topic string, event interface{}, eventSvc ports.EventService) planner.Procedure {
Expand All @@ -29,7 +30,7 @@ func (s *eventPublish) Name() string {
return "event_publish"
}

func (s *eventPublish) ShouldDo(ctx context.Context) (bool, error) {
func (s *eventPublish) ShouldDo(_ context.Context) (bool, error) {
return true, nil
}

Expand All @@ -47,6 +48,6 @@ func (s *eventPublish) Do(ctx context.Context) ([]planner.Procedure, error) {
return nil, nil
}

func (s *eventPublish) Verify(ctx context.Context) error {
func (s *eventPublish) Verify(_ context.Context) error {
return nil
}
3 changes: 2 additions & 1 deletion core/steps/event/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"testing"

"github.com/golang/mock/gomock"
g "github.com/onsi/gomega"

"github.com/liquidmetal-dev/flintlock/api/events"
"github.com/liquidmetal-dev/flintlock/core/steps/event"
"github.com/liquidmetal-dev/flintlock/infrastructure/mock"
g "github.com/onsi/gomega"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions core/steps/microvm/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"fmt"

"github.com/sirupsen/logrus"

"github.com/liquidmetal-dev/flintlock/core/errors"
"github.com/liquidmetal-dev/flintlock/core/models"
"github.com/liquidmetal-dev/flintlock/core/ports"
"github.com/liquidmetal-dev/flintlock/pkg/log"
"github.com/liquidmetal-dev/flintlock/pkg/planner"
"github.com/sirupsen/logrus"
)

func NewCreateStep(vm *models.MicroVM, vmSvc ports.MicroVMService) planner.Procedure {
Expand Down Expand Up @@ -63,6 +64,6 @@ func (s *createStep) Do(ctx context.Context) ([]planner.Procedure, error) {
return nil, nil
}

func (s *createStep) Verify(ctx context.Context) error {
func (s *createStep) Verify(_ context.Context) error {
return nil
}
3 changes: 2 additions & 1 deletion core/steps/microvm/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"testing"

"github.com/golang/mock/gomock"
g "github.com/onsi/gomega"

internalerr "github.com/liquidmetal-dev/flintlock/core/errors"
"github.com/liquidmetal-dev/flintlock/core/models"
"github.com/liquidmetal-dev/flintlock/core/ports"
"github.com/liquidmetal-dev/flintlock/core/steps/microvm"
"github.com/liquidmetal-dev/flintlock/infrastructure/mock"
g "github.com/onsi/gomega"
)

func testVMToCreate() *models.MicroVM {
Expand Down
5 changes: 3 additions & 2 deletions core/steps/microvm/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"fmt"

"github.com/sirupsen/logrus"

"github.com/liquidmetal-dev/flintlock/core/errors"
"github.com/liquidmetal-dev/flintlock/core/models"
"github.com/liquidmetal-dev/flintlock/core/ports"
"github.com/liquidmetal-dev/flintlock/pkg/log"
"github.com/liquidmetal-dev/flintlock/pkg/planner"
"github.com/sirupsen/logrus"
)

func NewDeleteStep(vm *models.MicroVM, vmSvc ports.MicroVMService) planner.Procedure {
Expand Down Expand Up @@ -60,6 +61,6 @@ func (s *deleteStep) Do(ctx context.Context) ([]planner.Procedure, error) {
return nil, nil
}

func (s *deleteStep) Verify(ctx context.Context) error {
func (s *deleteStep) Verify(_ context.Context) error {
return nil
}
3 changes: 2 additions & 1 deletion core/steps/microvm/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"testing"

"github.com/golang/mock/gomock"
g "github.com/onsi/gomega"

internalerr "github.com/liquidmetal-dev/flintlock/core/errors"
"github.com/liquidmetal-dev/flintlock/core/models"
"github.com/liquidmetal-dev/flintlock/core/ports"
"github.com/liquidmetal-dev/flintlock/core/steps/microvm"
"github.com/liquidmetal-dev/flintlock/infrastructure/mock"
g "github.com/onsi/gomega"
)

func testVMToDelete() *models.MicroVM {
Expand Down
3 changes: 2 additions & 1 deletion core/steps/microvm/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"fmt"
"time"

"github.com/sirupsen/logrus"

"github.com/liquidmetal-dev/flintlock/core/errors"
"github.com/liquidmetal-dev/flintlock/core/models"
"github.com/liquidmetal-dev/flintlock/core/ports"
"github.com/liquidmetal-dev/flintlock/pkg/log"
"github.com/liquidmetal-dev/flintlock/pkg/planner"
"github.com/sirupsen/logrus"
)

func NewStartStep(
Expand Down
3 changes: 2 additions & 1 deletion core/steps/microvm/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"testing"

"github.com/golang/mock/gomock"
g "github.com/onsi/gomega"

internalerr "github.com/liquidmetal-dev/flintlock/core/errors"
"github.com/liquidmetal-dev/flintlock/core/models"
"github.com/liquidmetal-dev/flintlock/core/ports"
"github.com/liquidmetal-dev/flintlock/core/steps/microvm"
"github.com/liquidmetal-dev/flintlock/infrastructure/mock"
g "github.com/onsi/gomega"
)

const bootTimeInSeconds = 1
Expand Down
Loading