Skip to content

Commit

Permalink
feat: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
anrs committed Feb 19, 2022
1 parent bd896fc commit e78418f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 108 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: golangci-lint
on:
push:
tags:
- '!v*'
branches:
- '*'
pull_request:

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
container: projecteru2/yavirt:prebuild
steps:
- name: Checkout
uses: actions/checkout@v2

- name: golangci-lint
uses: golangci/golangci-lint-action@v1
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.42
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
53 changes: 53 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
run:
timeout: 5m
tests: false
skip-dirs:
- vendor
- guestfs
- bin
modules-download-mode: readonly

linters-settings:
maligned:
suggest-new: true
gocritic:
disabled-checks:
- captLocal

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- revive
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- rowserrcheck
- exportloopref
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- gocognit
- errcheck
- dupl
- asciicheck
- nolintlint
- nestif
2 changes: 1 addition & 1 deletion virt/agent/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (w *file) Tail(n int) ([]byte, error) {
var buff bytes.Buffer
lineEnd := size
cursor := make([]byte, 1)
for i := size - 2; i >= 0; i-- { //nolint // start from the last second element
for i := size - 2; i >= 0; i-- { // nolint // start from the last second element
if _, err = w.ReadAt(cursor, i); err != nil {
return nil, err
}
Expand Down
2 changes: 0 additions & 2 deletions virt/guest/guest.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ func (g *Guest) start() error {
return util.Invoke([]func() error{
bot.Boot,
g.joinEthernet,
g.joinExtraNetworks,
bot.BindExtraNetwork,
g.ForwardRunning,
})
})
Expand Down
2 changes: 0 additions & 2 deletions virt/guest/guest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func TestLifecycle(t *testing.T) {
bot.On("Boot").Return(nil).Once()
bot.On("Close").Return(nil).Once()
bot.On("GetState").Return(libvirt.DomainShutoff, nil).Once()
bot.On("BindExtraNetwork").Return(nil)
assert.NilErr(t, guest.Start())
assert.Equal(t, model.StatusRunning, guest.Status)
guest.rangeVolumes(checkVolsStatus(t, model.StatusRunning))
Expand Down Expand Up @@ -212,7 +211,6 @@ func TestSyncState(t *testing.T) {
bot.On("Boot").Return(nil).Once()
bot.On("Close").Return(nil).Once()
bot.On("GetState").Return(libvirt.DomainShutoff, nil).Once()
bot.On("BindExtraNetwork").Return(nil).Once()
assert.NilErr(t, guest.SyncState())
}

Expand Down
103 changes: 0 additions & 103 deletions virt/guest/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/projecteru2/yavirt/config"
"github.com/projecteru2/yavirt/errors"
"github.com/projecteru2/yavirt/libvirt"
"github.com/projecteru2/yavirt/log"
"github.com/projecteru2/yavirt/meta"
"github.com/projecteru2/yavirt/model"
Expand Down Expand Up @@ -45,67 +44,6 @@ func (g *Guest) ConnectExtraNetwork(network, ipv4 string) (ip meta.IP, err error
return
}

func (g *Guest) bindExtraNetwork(ip meta.IP) error {
g.ExtraNetworks.Append(ip)
if err := g.Save(); err != nil {
return errors.Trace(err)
}

return g.botOperate(func(bot Bot) error {
switch st, err := bot.GetState(); {
case err != nil:
return errors.Trace(err)
case st != libvirt.DomainRunning:
return nil
}

return bot.BindExtraNetwork()
})
}

func (g *Guest) parseExtraNetworkIP(hand handler.Handler, ipv4 string) (ip meta.IP, rollback func() error, err error) {
if len(ipv4) < 1 {
return g.createExtraNetwork(hand)
}

return g.queryExtraNetworkIP(hand, ipv4)
}

func (g *Guest) queryExtraNetworkIP(hand handler.Handler, ipv4 string) (meta.IP, func() error, error) {
// todo
return nil, nil, nil
}

func (g *Guest) unjoinExtraNetwork(hand handler.Handler, ip meta.IP) error {
args, err := g.getExtraEndpointArgs(ip, true)
if err != nil {
return errors.Trace(err)
}

return hand.DeleteEndpointNetwork(args)
}

func (g *Guest) joinExtraNetworks() (err error) {
// todo
return
}

func (g *Guest) joinExtraNetwork(hand handler.Handler, ip meta.IP) error {
args, err := g.getExtraEndpointArgs(ip, true)
if err != nil {
return errors.Trace(err)
}

_, err = hand.JoinEndpointNetwork(args)

return err
}

func (g *Guest) createExtraNetwork(hand handler.Handler) (ip meta.IP, rollback func() error, err error) {
// todo
return
}

// CreateEthernet .
func (g *Guest) CreateEthernet() (rollback func() error, err error) {
if g.EnabledCalicoCNI {
Expand Down Expand Up @@ -240,50 +178,9 @@ func (g *Guest) assignIP() (meta.IP, error) {

// DeleteNetwork .
func (g *Guest) DeleteNetwork() error {
if err := g.deleteExtraNetworks(); err != nil {
return errors.Trace(err)
}

return g.deleteEthernet()
}

func (g *Guest) deleteExtraNetworks() (err error) {
// todo
return
}

type deleteExtraNetworkArgs struct {
args types.EndpointArgs
}

func (g *Guest) getDeleteExtraNetworksArgs() (args map[string]*deleteExtraNetworkArgs, err error) {
// todo
return
}

func (g *Guest) getExtraEndpointArgs(ip meta.IP, includeDevice bool) (types.EndpointArgs, error) {
args := types.EndpointArgs{
EndpointID: g.ID,
IPs: []meta.IP{ip},
MAC: g.MAC,
}

cali, err := g.calicoHandler()
if err != nil {
return args, errors.Annotatef(errors.ErrInvalidValue, "only calico ethernet supports extra network")
}

if includeDevice {
if args.Device, err = cali.GetEndpointDevice(g.NetworkPair); err != nil {
return args, errors.Trace(err)
}
}

args.Hostname, err = util.Hostname()

return args, err
}

func (g *Guest) deleteEthernet() error {
if g.EnabledCalicoCNI {
return g.calicoCNIDel()
Expand Down

0 comments on commit e78418f

Please sign in to comment.