Skip to content

Commit

Permalink
chore: lint code in preparation for rekres
Browse files Browse the repository at this point in the history
Just adds in the golangcilint file from kres so this should be a no-op
PR.

Part of: #14

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo authored and robinelfrink committed Mar 28, 2024
1 parent 737c8f2 commit 8d26e25
Show file tree
Hide file tree
Showing 11 changed files with 405 additions and 89 deletions.
160 changes: 160 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-03-28T09:36:34Z by kres 88d1199.

# options for analysis running
run:
timeout: 10m
issues-exit-code: 1
tests: true
build-tags: [ ]
modules-download-mode: readonly

# output configuration options
output:
formats:
- format: colored-line-number
path: stdout
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
path-prefix: ""

# all available settings of specific linters
linters-settings:
dogsled:
max-blank-identifiers: 2
dupl:
threshold: 150
errcheck:
check-type-assertions: true
check-blank: true
exhaustive:
default-signifies-exhaustive: false
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/siderolabs/talos-vmtoolsd/) # Custom section: groups all imports with the specified Prefix.
gocognit:
min-complexity: 30
nestif:
min-complexity: 5
goconst:
min-len: 3
min-occurrences: 3
gocritic:
disabled-checks: [ ]
gocyclo:
min-complexity: 20
godot:
scope: declarations
gofmt:
simplify: true
goimports:
local-prefixes: github.com/siderolabs/talos-vmtoolsd/
gomodguard: { }
gomnd: { }
govet:
enable-all: true
lll:
line-length: 200
tab-width: 4
misspell:
locale: US
ignore-words: [ ]
nakedret:
max-func-lines: 30
prealloc:
simple: true
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default
nolintlint:
allow-unused: false
allow-no-explanation: [ ]
require-explanation: false
require-specific: true
rowserrcheck: { }
testpackage: { }
unparam:
check-exported: false
unused:
local-variables-are-used: false
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
wsl:
strict-append: true
allow-assign-and-call: true
allow-multiline-assign: true
allow-cuddle-declarations: false
allow-trailing-comment: false
force-case-trailing-whitespace: 0
force-err-cuddling: false
allow-separated-leading-comment: false
gofumpt:
extra-rules: false
cyclop:
# the maximal code complexity to report
max-complexity: 20
# depguard:
# Main:
# deny:
# - github.com/OpenPeeDeeP/depguard # this is just an example

linters:
enable-all: true
disable-all: false
fast: false
disable:
- exhaustivestruct
- exhaustruct
- forbidigo
- funlen
- gochecknoglobals
- gochecknoinits
- godox
- goerr113
- gomnd
- gomoddirectives
- gosec
- inamedparam
- ireturn
- nestif
- nonamedreturns
- nosnakecase
- paralleltest
- tagalign
- tagliatelle
- thelper
- typecheck
- varnamelen
- wrapcheck
- depguard # Disabled because starting with golangci-lint 1.53.0 it doesn't allow denylist alone anymore
- testifylint # complains about our assert recorder and has a number of false positives for assert.Greater(t, thing, 1)
- protogetter # complains about us using Value field on typed spec, instead of GetValue which has a different signature
- perfsprint # complains about us using fmt.Sprintf in non-performance critical code, updating just kres took too long
# abandoned linters for which golangci shows the warning that the repo is archived by the owner
- deadcode
- golint
- ifshort
- interfacer
- maligned
- scopelint
- structcheck
- varcheck
# disabled as it seems to be broken - goes into imported libraries and reports issues there
- musttag

issues:
exclude: [ ]
exclude-rules: [ ]
exclude-use-default: false
exclude-case-sensitive: false
max-issues-per-linter: 10
max-same-issues: 3
new: false

severity:
default-severity: error
case-sensitive: false
42 changes: 29 additions & 13 deletions cmd/talos-vmtoolsd/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main implements the main entry point for the Talos VMware Tools Daemon.
package main

import (
Expand All @@ -8,13 +9,20 @@ import (
"os/signal"
"syscall"

vmtoolsd "github.com/siderolabs/talos-vmtoolsd"
"github.com/siderolabs/talos-vmtoolsd/internal/nanotoolbox"
"github.com/siderolabs/talos-vmtoolsd/internal/talosapi"
"github.com/siderolabs/talos-vmtoolsd/internal/tboxcmds"
"github.com/sirupsen/logrus"
vmguestmsg "github.com/vmware/vmw-guestinfo/message"
"github.com/vmware/vmw-guestinfo/vmcheck"

"github.com/siderolabs/talos-vmtoolsd/internal/nanotoolbox"
"github.com/siderolabs/talos-vmtoolsd/internal/talosapi"
"github.com/siderolabs/talos-vmtoolsd/internal/tboxcmds"
"github.com/siderolabs/talos-vmtoolsd/internal/version"
)

// Debug flags.
var (
talosTestQuery string
useMachinedSocket bool
)

func main() {
Expand All @@ -24,9 +32,6 @@ func main() {
DisableHTMLEscape: true,
})

// Debug flags
var talosTestQuery string
var useMachinedSocket bool
flag.StringVar(&talosTestQuery, "test-apid-query", "", "query apid")
flag.BoolVar(&useMachinedSocket, "use-machined", false, "use machined unix socket")
flag.Parse()
Expand All @@ -45,7 +50,7 @@ func main() {
l.Infof("talos-vmtoolsd version %v\n"+
"Copyright 2020-2022 Oliver Kuckertz <[email protected]>\n"+
"This program is free software and available under the Apache 2.0 license.",
vmtoolsd.Version)
version.Version)

// Simplify deployment to mixed vSphere and non-vSphere clusters by detecting ESXi and stopping
// early for other platforms. Admins can avoid the overhead of this idle process by labeling
Expand All @@ -58,14 +63,18 @@ func main() {

ctx, ctxCancel := context.WithCancel(context.Background())

var api *talosapi.LocalClient
var err error
var (
api *talosapi.LocalClient
err error
)

if !useMachinedSocket {
// Our spec file passes the secret path and K8s host IP via env vars.
configPath := os.Getenv("TALOS_CONFIG_PATH")
if len(configPath) == 0 {
l.Fatal("error: TALOS_CONFIG_PATH is a required path to a Talos configuration file")
}

k8sHost := os.Getenv("TALOS_HOST")
if len(k8sHost) == 0 {
l.Fatal("error: TALOS_HOST is required to point to a node's internal IP")
Expand Down Expand Up @@ -94,10 +103,11 @@ func main() {
if talosTestQuery != "" {
if err := testQuery(api, talosTestQuery); err != nil {
l.WithField("test_query", talosTestQuery).WithError(err).Fatal("test query failed")
os.Exit(1)
} else {
os.Exit(0)

os.Exit(1) //nolint:gocritic
}

os.Exit(0)
}

// Wires up VMware Toolbox commands to Talos apid.
Expand All @@ -116,6 +126,7 @@ func main() {
// Graceful shutdown on SIGINT/SIGTERM
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)

go func() {
l.Debugf("signal: %s", <-sig)
ctxCancel()
Expand All @@ -127,22 +138,27 @@ func main() {

func testQuery(api *talosapi.LocalClient, query string) error {
w := os.Stdout

switch query {
case "net-interfaces":
for idx, intf := range api.NetInterfaces() {
for _, addr := range intf.Addrs {
_, _ = fmt.Fprintf(w, "%d: name=%s mac=%s addr=%s\n", idx, intf.Name, intf.MAC, addr)
}
}

return nil
case "hostname":
_, _ = fmt.Fprintln(w, api.Hostname())

return nil
case "os-version":
_, _ = fmt.Fprintln(w, api.OSVersion())

return nil
case "os-version-short":
_, _ = fmt.Fprintln(w, api.OSVersionShort())

return nil
default:
return fmt.Errorf("unknown test query %q", query)
Expand Down
16 changes: 11 additions & 5 deletions internal/nanotoolbox/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package nanotoolbox provides a minimal set of tools for communicating with the vmx.
package nanotoolbox

import (
Expand All @@ -33,9 +34,10 @@ const (
tcloProtocol uint32 = 0x4f4c4354
)

// ErrNotVirtualWorld is returned when the current process is not running in a virtual world.
var ErrNotVirtualWorld = errors.New("not in a virtual world")

// Channel abstracts the guest<->vmx RPC transport
// Channel abstracts the guest<->vmx RPC transport.
type Channel interface {
Start() error
Stop() error
Expand All @@ -44,16 +46,18 @@ type Channel interface {
}

var (
RpciOK = []byte{'1', ' '}
// RpciOK is the return code for a successful RPCI request.
RpciOK = []byte{'1', ' '}
// RpciERR is the return code for a failed RPCI request.
RpciERR = []byte{'0', ' '}
)

// ChannelOut extends Channel to provide RPCI protocol helpers
// ChannelOut extends Channel to provide RPCI protocol helpers.
type ChannelOut struct {
Channel
}

// Request sends an RPC command to the vmx and checks the return code for success or error
// Request sends an RPC command to the vmx and checks the return code for success or error.
func (c *ChannelOut) Request(request []byte) ([]byte, error) {
if c.Channel == nil {
return nil, fmt.Errorf("no channel available for request %q", request)
Expand All @@ -75,7 +79,7 @@ func (c *ChannelOut) Request(request []byte) ([]byte, error) {
return nil, fmt.Errorf("failed request %q: %q", request, reply)
}

type hypervisorChannel struct {
type hypervisorChannel struct { //nolint:govet
protocol uint32

*message.Channel
Expand Down Expand Up @@ -108,8 +112,10 @@ func (b *hypervisorChannel) Stop() error {
return err
}

// NewHypervisorChannelPair returns a pair of channels for communicating with the vmx.
func NewHypervisorChannelPair() (Channel, Channel) {
in := &hypervisorChannel{protocol: tcloProtocol}
out := &hypervisorChannel{protocol: rpciProtocol}

return in, out
}
Loading

0 comments on commit 8d26e25

Please sign in to comment.