Skip to content

Commit

Permalink
🤖 Make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler committed Jul 26, 2022
1 parent 5eef667 commit 9ca5401
Show file tree
Hide file tree
Showing 30 changed files with 209 additions and 159 deletions.
13 changes: 12 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ linters:
- gofmt # check fmt
- goheader # Check license headers, only checks files in current year
- goimports # check imports
- gocyclo # check complexity
- gocyclo # check complexity
- govet
- gosimple
- deadcode
- ineffassign
- unused
- varcheck
- staticcheck
- typecheck
- structcheck
- godot
- misspell
4 changes: 1 addition & 3 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
//"fmt"

"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -268,7 +266,7 @@ This command is meant to be used from the boot GRUB menu, but can be started man
Description: `
Starts c3os recovery mode.
In recovery mode a QR code will be printed out on the screen which should be used in conjuction with "c3os bridge". Pass by the QR code as snapshot
In recovery mode a QR code will be printed out on the screen which should be used in conjunction with "c3os bridge". Pass by the QR code as snapshot
to the bridge to connect over the machine which runs the "c3os recovery" command.
See also https://docs.c3os.io/after_install/recovery_mode/ for documentation.
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func bridge(c *cli.Context) error {
return err
}

go api.API(ctx, c.String("api"), 5*time.Second, 20*time.Second, e, nil, false)
go api.API(ctx, c.String("api"), 5*time.Second, 20*time.Second, e, nil, false) //nolint:errcheck

return e.Start(ctx)
}
2 changes: 0 additions & 2 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
//"fmt"

"fmt"
"os"

Expand Down
7 changes: 6 additions & 1 deletion cmd/provider/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"

"github.com/c3os-io/c3os/internal/provider"
Expand All @@ -21,5 +22,9 @@ func main() {
// Expected output: string
factory.Add(bus.EventChallenge, provider.Challenge)

factory.Run(pluggable.EventType(os.Args[1]), os.Stdin, os.Stdout)
err := factory.Run(pluggable.EventType(os.Args[1]), os.Stdin, os.Stdout)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
12 changes: 7 additions & 5 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import (
"github.com/nxadm/tail"
)

// setup needs edgevpn and k3s installed locally
// (both k3s and k3s-agent systemd services)
// setup needs edgevpn and k3s installed locally (both k3s and k3s-agent systemd services).
func Run(apiAddress string, dir []string, force bool) error {

os.MkdirAll("/usr/local/.c3os", 0600)
os.MkdirAll("/usr/local/.c3os", 0600) //nolint:errcheck

// Reads config
c, err := config.Scan(config.Directories(dir...))
Expand All @@ -31,7 +30,7 @@ func Run(apiAddress string, dir []string, force bool) error {
return nil
}

os.MkdirAll("/var/log/c3os", 0600)
os.MkdirAll("/var/log/c3os", 0600) //nolint:errcheck
fileName := filepath.Join("/var/log/c3os", "agent-provider.log")
err = ioutil.WriteFile(fileName, []byte{}, os.ModePerm)
if err != nil {
Expand All @@ -58,7 +57,10 @@ func Run(apiAddress string, dir []string, force bool) error {

// Re-load providers
bus.Manager.LoadProviders()
machine.CreateSentinel("bundles")
err = machine.CreateSentinel("bundles")
if !c.IgnoreBundleErrors && err != nil {
return err
}
}

_, err = bus.Manager.Publish(events.EventBootstrap, events.BootstrapPayload{APIAddress: apiAddress, Config: c.String(), Logfile: fileName})
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func LoadConfig(path ...string) (*Config, error) {
for _, p := range path {
f, err := ioutil.ReadFile(p)
if err == nil {
yaml.Unmarshal(f, cfg)
yaml.Unmarshal(f, cfg) //nolint:errcheck
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/agent/iconunix.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package agent

var DefaultBanner []byte = []byte{
var DefaultBanner = []byte{
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00,
0x08, 0x06, 0x00, 0x00, 0x00, 0xf4, 0x78, 0xd4, 0xfa, 0x00, 0x00, 0x02,
Expand Down
45 changes: 27 additions & 18 deletions internal/agent/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func optsToArgs(options map[string]string) (res []string) {
for k, v := range options {
if k != "device" && k != "cc" && k != "reboot" && k != "poweroff" {
res = append(res, fmt.Sprintf("--%s", k))
res = append(res, fmt.Sprintf("%s", v))
res = append(res, v)
}
}
return
Expand All @@ -38,7 +38,7 @@ func Install(dir ...string) error {
utils.OnSignal(func() {
svc, err := machine.Getty(1)
if err == nil {
svc.Start()
svc.Start() //nolint:errcheck
}
}, syscall.SIGINT, syscall.SIGTERM)

Expand All @@ -47,7 +47,7 @@ func Install(dir ...string) error {

mergeOption := func(cloudConfig string) {
c := &config.Config{}
yaml.Unmarshal([]byte(cloudConfig), c)
yaml.Unmarshal([]byte(cloudConfig), c) //nolint:errcheck
for k, v := range c.Options {
if k == "cc" {
continue
Expand Down Expand Up @@ -80,11 +80,14 @@ func Install(dir ...string) error {
r["device"] = cc.Install.Device
mergeOption(cc.String())

RunInstall(r)
err = RunInstall(r)
if err != nil {
return err
}

svc, err := machine.Getty(1)
if err == nil {
svc.Start()
svc.Start() //nolint:errcheck
}

return nil
Expand Down Expand Up @@ -133,10 +136,10 @@ func Install(dir ...string) error {
header = head
}

// What we receive take precedence over the one in the system
yaml.Unmarshal([]byte(cc.String()), &ccData)
// What we receive take precedence over the one in the system. best-effort
yaml.Unmarshal([]byte(cc.String()), &ccData) //nolint:errcheck
if exists {
yaml.Unmarshal([]byte(cloudConfig), &ccData)
yaml.Unmarshal([]byte(cloudConfig), &ccData) //nolint:errcheck
if hasHeader, head := config.HasHeader(cloudConfig, ""); hasHeader {
header = head
}
Expand All @@ -150,19 +153,21 @@ func Install(dir ...string) error {
r["cc"] = config.AddHeader(header, string(out))

pterm.Info.Println("Starting installation")
utils.SH("elemental run-stage c3os-install.pre")
bus.RunHookScript("/usr/bin/c3os-agent.install.pre.hook")
utils.SH("elemental run-stage c3os-install.pre") //nolint:errcheck
bus.RunHookScript("/usr/bin/c3os-agent.install.pre.hook") //nolint:errcheck

RunInstall(r)
if err := RunInstall(r); err != nil {
return err
}

pterm.Info.Println("Installation completed, press enter to go back to the shell.")

utils.Prompt("")
utils.Prompt("") //nolint:errcheck

// give tty1 back
svc, err := machine.Getty(1)
if err == nil {
svc.Start()
svc.Start() //nolint: errcheck
}

return nil
Expand All @@ -185,15 +190,19 @@ func RunInstall(options map[string]string) error {
}

c := &config.Config{}
yaml.Unmarshal([]byte(cloudInit), c)
yaml.Unmarshal([]byte(cloudInit), c) //nolint:errcheck

_, reboot := options["reboot"]
_, poweroff := options["poweroff"]

ioutil.WriteFile(f.Name(), []byte(cloudInit), os.ModePerm)
err := ioutil.WriteFile(f.Name(), []byte(cloudInit), os.ModePerm)
if err != nil {
fmt.Printf("could not write cloud init: %s\n", err.Error())
os.Exit(1)
}
args := []string{"install"}
args = append(args, optsToArgs(options)...)
args = append(args, "-c", f.Name(), fmt.Sprintf("%s", device))
args = append(args, "-c", f.Name(), device)

cmd := exec.Command("elemental", args...)
cmd.Env = os.Environ()
Expand All @@ -204,8 +213,8 @@ func RunInstall(options map[string]string) error {
fmt.Println(err)
os.Exit(1)
}
utils.SH("elemental run-stage c3os-install.after")
bus.RunHookScript("/usr/bin/c3os-agent.install.after.hook")
utils.SH("elemental run-stage c3os-install.after") //nolint:errcheck
bus.RunHookScript("/usr/bin/c3os-agent.install.after.hook") //nolint:errcheck

if reboot || c.Install != nil && c.Install.Reboot {
utils.Reboot()
Expand Down
18 changes: 10 additions & 8 deletions internal/agent/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ func Recovery() error {
serviceUUID := utils.RandStringRunes(10)
generatedPassword := utils.RandStringRunes(7)

startRecoveryService(ctx, tk, serviceUUID, recoveryAddr, "fatal")
if err := startRecoveryService(ctx, tk, serviceUUID, recoveryAddr, "fatal"); err != nil {
return err
}

cmd.PrintText(agentConfig.Branding.Recovery, "Recovery")

Expand All @@ -90,12 +92,12 @@ func Recovery() error {
go sshServer(recoveryAddr, generatedPassword)

// Wait for user input and go back to shell
utils.Prompt("")
utils.Prompt("") //nolint:errcheck
cancel()
// give tty1 back
svc, err := machine.Getty(1)
if err == nil {
svc.Start()
svc.Start() //nolint:errcheck
}

return nil
Expand All @@ -117,13 +119,13 @@ func sshServer(listenAdddr, password string) {
}
}()
go func() {
io.Copy(f, s) // stdin
io.Copy(f, s) //nolint:errcheck
}()
io.Copy(s, f) // stdout
cmd.Wait()
io.Copy(s, f) //nolint:errcheck
cmd.Wait() //nolint:errcheck
} else {
io.WriteString(s, "No PTY requested.\n")
s.Exit(1)
io.WriteString(s, "No PTY requested.\n") //nolint:errcheck
s.Exit(1) //nolint:errcheck
}
})

Expand Down
4 changes: 2 additions & 2 deletions internal/agent/recovery_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (
)

func setWinsize(f *os.File, w, h int) {
syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCSWINSZ),
uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0})))
syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCSWINSZ), //nolint:errcheck
uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0}))) //nolint:errcheck
}
8 changes: 4 additions & 4 deletions internal/agent/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func Reset() error {
lock := sync.Mutex{}
go func() {
// Wait for user input and go back to shell
utils.Prompt("")
utils.Prompt("") //nolint:errcheck
// give tty1 back
svc, err := machine.Getty(1)
if err == nil {
svc.Start()
svc.Start() //nolint:errcheck
}

lock.Lock()
Expand Down Expand Up @@ -61,11 +61,11 @@ func Reset() error {
lock2 := sync.Mutex{}
go func() {
// Wait for user input and go back to shell
utils.Prompt("")
utils.Prompt("") //nolint:errcheck
// give tty1 back
svc, err := machine.Getty(1)
if err == nil {
svc.Start()
svc.Start() //nolint:errcheck
}

lock2.Lock()
Expand Down
4 changes: 2 additions & 2 deletions internal/bus/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/mudler/go-pluggable"
)

// Manager is the bus instance manager, which subscribes plugins to events emitted
var Manager *Bus = &Bus{
// Manager is the bus instance manager, which subscribes plugins to events emitted.
var Manager = &Bus{
Manager: pluggable.NewManager(
[]pluggable.EventType{
bus.EventBootstrap,
Expand Down
2 changes: 0 additions & 2 deletions internal/cmd/commands.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cmd

import (
//"fmt"

"encoding/base64"
"fmt"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion internal/machine/bootcmdline.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ func dotToYAML(v map[string]interface{}) ([]byte, error) {
if err != nil {
errs = multierror.Append(errs, err)
}
return out, err
return out, errs
}
Loading

0 comments on commit 9ca5401

Please sign in to comment.