Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <[email protected]>
  • Loading branch information
cpanato committed Jul 10, 2024
1 parent 8f02e7d commit 65b9426
Show file tree
Hide file tree
Showing 57 changed files with 320 additions and 259 deletions.
17 changes: 17 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,25 @@ issues:
linters:
enable-all: true
disable:
- bodyclose
- contextcheck
- cyclop
- depguard
- exhaustruct
- err113
- forcetypeassert
- ireturn
- interfacebloat
- inamedparam
- musttag
- nonamedreturns
- nilnil
- tagliatelle
- gomoddirectives
- gochecknoglobals
- varnamelen
- protogetter
- gomnd
- mnd
- wsl
- wrapcheck
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
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
4 changes: 2 additions & 2 deletions core/steps/event/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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 +47,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
}
2 changes: 1 addition & 1 deletion core/steps/microvm/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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
}
2 changes: 1 addition & 1 deletion core/steps/microvm/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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
}
5 changes: 3 additions & 2 deletions core/steps/network/interface_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ 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/infrastructure/network"
"github.com/liquidmetal-dev/flintlock/pkg/log"
"github.com/liquidmetal-dev/flintlock/pkg/planner"
"github.com/sirupsen/logrus"
)

func NewNetworkInterface(vmid *models.VMID,
Expand Down Expand Up @@ -129,6 +130,6 @@ func (s *createInterface) Do(ctx context.Context) ([]planner.Procedure, error) {
return nil, nil
}

func (s *createInterface) Verify(ctx context.Context) error {
func (s *createInterface) Verify(_ context.Context) error {
return nil
}
2 changes: 1 addition & 1 deletion core/steps/network/interface_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ func (s deleteInterface) ShouldDo(ctx context.Context) (bool, error) {
return exists, nil
}

func (s deleteInterface) Verify(ctx context.Context) error {
func (s deleteInterface) Verify(_ context.Context) error {
return nil
}
2 changes: 1 addition & 1 deletion core/steps/runtime/dir_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ func (s *createDirectory) directoryExists() (bool, error) {
return exists, nil
}

func (s *createDirectory) Verify(ctx context.Context) error {
func (s *createDirectory) Verify(_ context.Context) error {
return nil
}
2 changes: 1 addition & 1 deletion core/steps/runtime/dir_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ func (s *deleteDirectory) targetExists() (bool, error) {
return exists, nil
}

func (s *deleteDirectory) Verify(ctx context.Context) error {
func (s *deleteDirectory) Verify(_ context.Context) error {
return nil
}
2 changes: 1 addition & 1 deletion core/steps/runtime/initrd_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ func (s *initrdMount) getMountSpec() *ports.ImageMountSpec {
}
}

func (s *initrdMount) Verify(ctx context.Context) error {
func (s *initrdMount) Verify(_ context.Context) error {
return nil
}
2 changes: 1 addition & 1 deletion core/steps/runtime/kernel_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ func (s *kernelMount) getMountSpec() *ports.ImageMountSpec {
}
}

func (s *kernelMount) Verify(ctx context.Context) error {
func (s *kernelMount) Verify(_ context.Context) error {
return nil
}
2 changes: 1 addition & 1 deletion core/steps/runtime/repo_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ func (s *repoRelease) Do(ctx context.Context) ([]planner.Procedure, error) {
return nil, nil
}

func (s *repoRelease) Verify(ctx context.Context) error {
func (s *repoRelease) Verify(_ context.Context) error {
return nil
}
2 changes: 1 addition & 1 deletion core/steps/runtime/volume_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ func (s *volumeMount) getMountSpec() *ports.ImageMountSpec {
}
}

func (s *volumeMount) Verify(ctx context.Context) error {
func (s *volumeMount) Verify(_ context.Context) error {
return nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require (
require (
github.com/carlmjohnson/requests v0.23.5
github.com/containerd/containerd/api v1.7.19
github.com/containerd/platforms v0.2.1
github.com/containerd/typeurl/v2 v2.1.1
github.com/diskfs/go-diskfs v1.3.0
github.com/docker/go-units v0.5.0
Expand Down Expand Up @@ -75,7 +76,6 @@ require (
github.com/containerd/errdefs v0.1.0 // indirect
github.com/containerd/fifo v1.1.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/containerd/ttrpc v1.2.5 // indirect
github.com/containernetworking/cni v1.1.2 // indirect
github.com/containernetworking/plugins v1.2.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/containerd/client_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/services/introspection"
"github.com/containerd/containerd/snapshots"
"github.com/containerd/platforms"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/containerd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func convertMountToModel(mountPoint mount.Mount, snapshotter string) (models.Mou
}
}

func getOverlayMountPath(m mount.Mount) string {
func getOverlayMountPath(_ mount.Mount) string {
return ""
}

Expand Down
6 changes: 4 additions & 2 deletions infrastructure/containerd/image_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import (
"context"
"fmt"

"github.com/sirupsen/logrus"

"github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/snapshots"
"github.com/opencontainers/image-spec/identity"

"github.com/liquidmetal-dev/flintlock/core/models"
"github.com/liquidmetal-dev/flintlock/core/ports"
"github.com/liquidmetal-dev/flintlock/pkg/log"
"github.com/opencontainers/image-spec/identity"
"github.com/sirupsen/logrus"
)

// NewImageService will create a new image service based on containerd with the supplied config.
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/containerd/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func withOwnerLease(ctx context.Context, owner string, client Client) (context.C
}

func getExistingOrCreateLease(ctx context.Context, name string, manager leases.Manager) (*leases.Lease, error) {
filter := fmt.Sprintf("id==%s", name)
filter := "id==" + name

existingLeases, err := manager.List(ctx, filter)
if err != nil {
Expand Down Expand Up @@ -53,5 +53,5 @@ func deleteLease(ctx context.Context, owner string, client Client) error {
}

func getLeaseNameForOwner(owner string) string {
return fmt.Sprintf("flintlock/%s", owner)
return "flintlock/" + owner
}
7 changes: 4 additions & 3 deletions infrastructure/containerd/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/namespaces"
"github.com/google/go-cmp/cmp"
"github.com/opencontainers/go-digest"
v1 "github.com/opencontainers/image-spec/specs-go/v1"

"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/opencontainers/go-digest"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
)

// NewMicroVMRepo will create a new containerd backed microvm repository with the supplied containerd configuration.
Expand Down Expand Up @@ -127,7 +128,7 @@ func (r *containerdRepo) Get(ctx context.Context, options ports.RepositoryGetOpt
}

if spec == nil {
return nil, errors.NewSpecNotFound( //nolint: wrapcheck // No need to wrap this error
return nil, errors.NewSpecNotFound(
options.Name,
options.Namespace,
options.Version,
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/containerd/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func snapshotKey(owner, ownerUsageID string) string {
func snapshotExists(ctx context.Context, key string, ss snapshots.Snapshotter) (bool, error) {
snapshotExists := false

err := ss.Walk(ctx, func(walkCtx context.Context, info snapshots.Info) error {
err := ss.Walk(ctx, func(_ context.Context, info snapshots.Info) error {
if info.Name == key {
snapshotExists = true
}
Expand Down
8 changes: 6 additions & 2 deletions infrastructure/controllers/microvm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import (
"github.com/sirupsen/logrus"
)

func New(eventSvc ports.EventService, reconcileUC ports.ReconcileMicroVMsUseCase, queryUC ports.MicroVMQueryUseCases) *MicroVMController {
func New(
eventSvc ports.EventService,
reconcileUC ports.ReconcileMicroVMsUseCase,
queryUC ports.MicroVMQueryUseCases,
) *MicroVMController {
return &MicroVMController{
eventSvc: eventSvc,
reconcileUC: reconcileUC,
Expand Down Expand Up @@ -69,7 +73,7 @@ func (r *MicroVMController) Run(ctx context.Context,
logger.Info("Starting workers", "num_workers", numWorkers)
wg.Add(numWorkers)

for i := 0; i < numWorkers; i++ {
for range numWorkers {
go func() {
defer wg.Done()

Expand Down
4 changes: 2 additions & 2 deletions infrastructure/godisk/disk_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type diskService struct {
}

// Create will create a new disk.
func (s *diskService) Create(ctx context.Context, input ports.DiskCreateInput) error {
func (s *diskService) Create(_ context.Context, input ports.DiskCreateInput) error {
if input.Path == "" {
return errPathRequired
}
Expand All @@ -59,7 +59,7 @@ func (s *diskService) Create(ctx context.Context, input ports.DiskCreateInput) e
return fmt.Errorf("converting disk size %s: %w", input.Size, err)
}

createdDisk, err := diskfs.Create(input.Path, int64(diskSize), diskfs.Raw, diskfs.SectorSizeDefault)
createdDisk, err := diskfs.Create(input.Path, diskSize, diskfs.Raw, diskfs.SectorSizeDefault)
if err != nil {
return fmt.Errorf("creating disk %s: %w", input.Path, err)
}
Expand Down
Loading

0 comments on commit 65b9426

Please sign in to comment.