Skip to content

Commit

Permalink
chore(fmt): Enable disabled linters in global scope
Browse files Browse the repository at this point in the history
Global options:
* An explanation for all nolint annotations is required.
  Please do not just ignore it, tell us why is it ignored.

== wsl

* Fixed everywhere.

== lll

* Fix everywhere.
* Added exception on `https://` links.

== gochecknoglobals

* Fixed everywhere.

== gci

* Fixed everywhere (with `golangci-lint run --fix`)

== godox

No TODO comments should live in the code without filed issues to track
them. The reason is simple: if we have a comment with "todo", it has the
same value as not having that comment at all, because no one will care
about it.

* No TODO, BUG, and FIXME comments in the code.
* Except if it has a filed github issue reference.
  • Loading branch information
yitsushi committed Nov 11, 2021
1 parent 37abed2 commit ce0e78a
Show file tree
Hide file tree
Showing 51 changed files with 641 additions and 215 deletions.
72 changes: 43 additions & 29 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ run:
- "./*/mock"

linters-settings:
funlen:
lines: 110
statements: 60
staticcheck:
go: "1.17"
stylecheck:
go: "1.17"
cyclop:
max-complexity: 12
skip-tests: true
gosec:
exclude-generated: true
lll:
line-length: 120
misspell:
locale: GB
goimports:
local-prefixes: github.com/weaveworks/flintlock
govet:
Expand All @@ -28,6 +44,9 @@ issues:
- text: "local replacement are not allowed: github.com/weaveworks/flintlock/"
linters:
- gomoddirectives
- source: "https://"
linters:
- lll
- path: _test\.go
linters:
- goerr113
Expand All @@ -45,73 +64,68 @@ issues:
linters:
- exhaustivestruct
- lll

linters-settings:
funlen:
lines: 110
statements: 60
staticcheck:
go: "1.17"
stylecheck:
go: "1.17"
cyclop:
max-complexity: 12
skip-tests: true
- source: "// .* #\\d+"
linters:
- godox
- path: test/e2e/
linters:
- goerr113
- gomnd

linters:
disable-all: true
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exhaustive
- exportloopref
- exportloopref
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- godox
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
- revive
- gomnd
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- nestif
- nlreturn
- noctx
- nolintlint
- prealloc
- revive
- rowserrcheck
- exportloopref
- sqlclosecheck
- staticcheck
- structcheck
- stylecheck
- testpackage
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
disabled:
- gci
- godox
- gochecknoglobals
- lll
- wsl
disabled: []
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ docs-deploy: docs-build
.PHONY: help
help: ## Display this help. Thanks to https://www.thapaliya.com/en/writings/well-documented-makefiles/
ifeq ($(OS),Windows_NT)
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make <target>\n"} /^[a-zA-Z_-]+:.*?##/ { printf " %-40s %s\n", $$1, $$2 } /^##@/ { printf "\n%s\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make <target>\n"} /^[0-9a-zA-Z_-]+:.*?##/ { printf " %-40s %s\n", $$1, $$2 } /^##@/ { printf "\n%s\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
else
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-40s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-40s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
endif
2 changes: 1 addition & 1 deletion cmd/dev-helper/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//nolint
//nolint // We don't care about this, it will be deleted.
package main

import (
Expand Down
4 changes: 2 additions & 2 deletions core/application/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ func (a *app) CreateMicroVM(ctx context.Context, mvm *models.MicroVM) (*models.M
if err != nil {
return nil, fmt.Errorf("generating random name for microvm: %w", err)
}

vmid, err := models.NewVMID(name, defaults.MicroVMNamespace)
if err != nil {
return nil, fmt.Errorf("creating vmid: %w", err)
}

mvm.ID = *vmid
}

Expand All @@ -49,8 +51,6 @@ func (a *app) CreateMicroVM(ctx context.Context, mvm *models.MicroVM) (*models.M
}
}

// TODO: validate the spec

// Set the timestamp when the VMspec was created.
mvm.Spec.CreatedAt = a.ports.Clock().Unix()
mvm.Status.State = models.PendingState
Expand Down
3 changes: 2 additions & 1 deletion core/application/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func (a *app) ReconcileMicroVM(ctx context.Context, id, namespace string) error
logger := log.GetLogger(ctx).WithField("action", "reconcile")

logger.Debugf("Getting spec for %s/%s", namespace, id)

spec, err := a.ports.Repo.Get(ctx, ports.RepositoryGetOptions{
Name: id,
Namespace: namespace,
Expand All @@ -35,8 +36,8 @@ func (a *app) ResyncMicroVMs(ctx context.Context, namespace string) error {
"namespace": "ns",
})
logger.Info("Resyncing specs")

logger.Debug("Getting all specs")

specs, err := a.ports.Repo.GetAll(ctx, namespace)
if err != nil {
return fmt.Errorf("getting all microvm specs for resync: %w", err)
Expand Down
4 changes: 1 addition & 3 deletions core/models/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type NetworkInterface struct {
// GuestDeviceName is the name of the network interface to create in the microvm.
GuestDeviceName string `json:"guest_device_name" validate:"required,excludesall=/@,guestDeviceName"`
// AllowMetadataRequests indicates that this interface can be used for metadata requests.
// TODO: we may hide this within the firecracker plugin.
// TODO: we may hide this within the firecracker plugin. #179
AllowMetadataRequests bool `json:"allow_mmds,omitempty"`
// GuestMAC allows the specifying of a specifi MAC address to use for the interface. If
// not supplied a autogenerated MAC address will be used.
Expand All @@ -14,8 +14,6 @@ type NetworkInterface struct {
Type IfaceType `json:"type" validate:"oneof=tap macvtap unsupported"`
// Address is an optional IP address to assign to this interface. If not supplied then DHCP will be used.
Address string `json:"address,omitempty" validate:"omitempty,cidr"`
// TODO: add rate limiting.
// TODO: add CNI.
}

type NetworkInterfaceStatus struct {
Expand Down
2 changes: 2 additions & 0 deletions core/models/vmid.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func NewVMID(name, namespace string) (*VMID, error) {
if name == "" {
return nil, coreerrs.ErrNameRequired
}

if namespace == "" {
return nil, coreerrs.ErrNamespaceRequired
}
Expand Down Expand Up @@ -98,6 +99,7 @@ func splitVMIDFromString(id string) (namespace string, name string, err error) {
if parts[0] == "" {
return "", "", coreerrs.ErrNamespaceRequired
}

if parts[1] == "" {
return "", "", coreerrs.ErrNameRequired
}
Expand Down
2 changes: 0 additions & 2 deletions core/models/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type Volume struct {
PartitionID string `json:"partition_id,omitempty"`
// Size is the size to resize this volume to.
Size int32 `json:"size,omitempty"`
// TODO: add rate limiting.
}

// Volumes represents a collection of volumes.
Expand All @@ -38,7 +37,6 @@ func (v Volumes) GetByID(id string) *Volume {
type VolumeSource struct {
// Container is used to specify a source of a volume as a OCI container.
Container *ContainerVolumeSource `json:"container,omitempty"`
// TODO: add CSI.
}

// ContainerDriveSource represents the details of a volume coming from a OCI image.
Expand Down
16 changes: 14 additions & 2 deletions core/plans/microvm_create_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,32 @@ func (p *microvmCreateOrUpdatePlan) addStep(ctx context.Context, step planner.Pr
return nil
}

func (p *microvmCreateOrUpdatePlan) addImageSteps(ctx context.Context, vm *models.MicroVM, imageSvc ports.ImageService) error {
func (p *microvmCreateOrUpdatePlan) addImageSteps(ctx context.Context,
vm *models.MicroVM,
imageSvc ports.ImageService,
) error {
for i := range vm.Spec.Volumes {
vol := vm.Spec.Volumes[i]

status, ok := vm.Status.Volumes[vol.ID]
if !ok {
status = &models.VolumeStatus{}
vm.Status.Volumes[vol.ID] = status
}

if vol.Source.Container != nil {
if err := p.addStep(ctx, runtime.NewVolumeMount(&vm.ID, &vol, status, imageSvc)); err != nil {
return fmt.Errorf("adding volume mount step: %w", err)
}
}
}

if string(vm.Spec.Kernel.Image) != "" {
if err := p.addStep(ctx, runtime.NewKernelMount(vm, imageSvc)); err != nil {
return fmt.Errorf("adding kernel mount step: %w", err)
}
}

if vm.Spec.Initrd != nil {
if err := p.addStep(ctx, runtime.NewInitrdMount(vm, imageSvc)); err != nil {
return fmt.Errorf("adding initrd mount step: %w", err)
Expand All @@ -135,14 +142,19 @@ func (p *microvmCreateOrUpdatePlan) addImageSteps(ctx context.Context, vm *model
return nil
}

func (p *microvmCreateOrUpdatePlan) addNetworkSteps(ctx context.Context, vm *models.MicroVM, networkSvc ports.NetworkService) error {
func (p *microvmCreateOrUpdatePlan) addNetworkSteps(ctx context.Context,
vm *models.MicroVM,
networkSvc ports.NetworkService,
) error {
for i := range vm.Spec.NetworkInterfaces {
iface := vm.Spec.NetworkInterfaces[i]

status, ok := vm.Status.NetworkInterfaces[iface.GuestDeviceName]
if !ok {
status = &models.NetworkInterfaceStatus{}
vm.Status.NetworkInterfaces[iface.GuestDeviceName] = status
}

if err := p.addStep(ctx, network.NewNetworkInterface(&vm.ID, &iface, status, networkSvc)); err != nil {
return fmt.Errorf("adding create network interface step: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion core/plans/microvm_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ func (p *microvmDeletePlan) addStep(ctx context.Context, step planner.Procedure)
return nil
}

func (p *microvmDeletePlan) addNetworkSteps(ctx context.Context, vm *models.MicroVM, networkSvc ports.NetworkService) error {
func (p *microvmDeletePlan) addNetworkSteps(
ctx context.Context,
vm *models.MicroVM,
networkSvc ports.NetworkService,
) error {
for i := range vm.Spec.NetworkInterfaces {
iface := vm.Spec.NetworkInterfaces[i]
ifaceStats := vm.Status.NetworkInterfaces[iface.GuestDeviceName]
Expand Down
1 change: 1 addition & 0 deletions core/plans/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plans

import (
"github.com/spf13/afero"

"github.com/weaveworks/flintlock/core/ports"
)

Expand Down
1 change: 1 addition & 0 deletions core/steps/microvm/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/sirupsen/logrus"

"github.com/weaveworks/flintlock/core/errors"
"github.com/weaveworks/flintlock/core/models"
"github.com/weaveworks/flintlock/core/ports"
Expand Down
1 change: 1 addition & 0 deletions core/steps/microvm/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/sirupsen/logrus"

"github.com/weaveworks/flintlock/core/errors"
"github.com/weaveworks/flintlock/core/models"
"github.com/weaveworks/flintlock/core/ports"
Expand Down
14 changes: 10 additions & 4 deletions core/steps/network/interface_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/sirupsen/logrus"

"github.com/weaveworks/flintlock/core/errors"
"github.com/weaveworks/flintlock/core/models"
"github.com/weaveworks/flintlock/core/ports"
Expand All @@ -13,7 +14,11 @@ import (
"github.com/weaveworks/flintlock/pkg/planner"
)

func NewNetworkInterface(vmid *models.VMID, iface *models.NetworkInterface, status *models.NetworkInterfaceStatus, svc ports.NetworkService) planner.Procedure {
func NewNetworkInterface(vmid *models.VMID,
iface *models.NetworkInterface,
status *models.NetworkInterfaceStatus,
svc ports.NetworkService,
) planner.Procedure {
return &createInterface{
vmid: vmid,
iface: iface,
Expand Down Expand Up @@ -87,14 +92,15 @@ func (s *createInterface) Do(ctx context.Context) ([]planner.Procedure, error) {
if err != nil {
return nil, fmt.Errorf("checking if networking interface exists: %w", err)
}

if exists {
// This whole block is unreachable right now, because
// the Do function is called only if ShouldDo returns
// true. It retruns false if IfaceExists returns true.
// Line 76 will never return exists=true
details, err := s.svc.IfaceDetails(ctx, deviceName)
if err != nil {
return nil, fmt.Errorf("getting interface details: %w", err)
details, detailsErr := s.svc.IfaceDetails(ctx, deviceName)
if detailsErr != nil {
return nil, fmt.Errorf("getting interface details: %w", detailsErr)
}

s.status.HostDeviceName = deviceName
Expand Down
6 changes: 5 additions & 1 deletion core/steps/network/interface_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import (
"fmt"

"github.com/sirupsen/logrus"

"github.com/weaveworks/flintlock/core/errors"
"github.com/weaveworks/flintlock/core/models"
"github.com/weaveworks/flintlock/core/ports"
"github.com/weaveworks/flintlock/pkg/log"
"github.com/weaveworks/flintlock/pkg/planner"
)

func DeleteNetworkInterface(vmid *models.VMID, iface *models.NetworkInterfaceStatus, svc ports.NetworkService) planner.Procedure {
func DeleteNetworkInterface(vmid *models.VMID,
iface *models.NetworkInterfaceStatus,
svc ports.NetworkService,
) planner.Procedure {
return deleteInterface{
vmid: vmid,
iface: iface,
Expand Down
Loading

0 comments on commit ce0e78a

Please sign in to comment.