Skip to content

Commit

Permalink
Merge pull request #49 from sapcc/lints
Browse files Browse the repository at this point in the history
Fix and enable lints
  • Loading branch information
xsen84 authored Jan 13, 2025
2 parents e15b23d + a321105 commit 7af14cc
Show file tree
Hide file tree
Showing 97 changed files with 2,453 additions and 1,755 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bin/
kubeconfig.yaml
/build/
/kubeconfig.yaml
173 changes: 173 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
################################################################################
# This file is AUTOGENERATED with <https://github.com/sapcc/go-makefile-maker> #
# Edit Makefile.maker.yaml instead. #
################################################################################

# Copyright 2024 SAP SE
# SPDX-License-Identifier: Apache-2.0

run:
timeout: 3m # 1m by default
modules-download-mode: vendor

output:
# Do not print lines of code with issue.
print-issued-lines: false

issues:
exclude:
# It is idiomatic Go to reuse the name 'err' with ':=' for subsequent errors.
# Ref: https://go.dev/doc/effective_go#redeclaration
- 'declaration of "err" shadows declaration at'
exclude-rules:
- path: _test\.go
linters:
- bodyclose
- dupl
# '0' disables the following options.
max-issues-per-linter: 0
max-same-issues: 0

linters-settings:
dupl:
# Tokens count to trigger issue, 150 by default.
threshold: 100
errcheck:
# Report about assignment of errors to blank identifier.
check-blank: true
# Do not report about not checking of errors in type assertions.
# This is not as dangerous as skipping error values because an unchecked type assertion just immediately panics.
# We disable this because it makes a ton of useless noise esp. in test code.
check-type-assertions: false
forbidigo:
analyze-types: true # required for pkg:
forbid:
# ioutil package has been deprecated: https://github.com/golang/go/issues/42026
- ^ioutil\..*$
# Using http.DefaultServeMux is discouraged because it's a global variable that some packages silently and magically add handlers to (esp. net/http/pprof).
# Applications wishing to use http.ServeMux should obtain local instances through http.NewServeMux() instead of using the global default instance.
- ^http\.DefaultServeMux$
- ^http\.Handle(?:Func)?$
# Forbid usage of old and archived square/go-jose
- pkg: ^gopkg\.in/square/go-jose\.v2$
msg: "gopk.in/square/go-jose is archived and has CVEs. Replace it with gopkg.in/go-jose/go-jose.v2"
- pkg: ^github.com/coreos/go-oidc$
msg: "github.com/coreos/go-oidc depends on gopkg.in/square/go-jose which has CVEs. Replace it with github.com/coreos/go-oidc/v3"

- pkg: ^github.com/howeyc/gopass$
msg: "github.com/howeyc/gopass is archived, use golang.org/x/term instead"
goconst:
ignore-tests: true
min-occurrences: 5
gocritic:
enabled-checks:
- boolExprSimplify
- builtinShadow
- emptyStringTest
- evalOrder
- httpNoBody
- importShadow
- initClause
- methodExprCall
- paramTypeCombine
- preferFilepathJoin
- ptrToRefParam
- redundantSprint
- returnAfterHttpError
- stringConcatSimplify
- timeExprSimplify
- truncateCmp
- typeAssertChain
- typeUnparen
- unnamedResult
- unnecessaryBlock
- unnecessaryDefer
- weakCond
- yodaStyleExpr
goimports:
# Put local imports after 3rd-party packages.
local-prefixes: github.com/sapcc/kube-parrot
gomoddirectives:
toolchain-forbidden: true
go-version-pattern: '1\.\d+(\.0)?$'
gosec:
excludes:
# gosec wants us to set a short ReadHeaderTimeout to avoid Slowloris attacks, but doing so would expose us to Keep-Alive race conditions (see https://iximiuz.com/en/posts/reverse-proxy-http-keep-alive-and-502s/)
- G112
# created file permissions are restricted by umask if necessary
- G306
govet:
enable-all: true
disable:
- fieldalignment
nolintlint:
require-specific: true
stylecheck:
dot-import-whitelist:
- github.com/onsi/ginkgo/v2
- github.com/onsi/gomega
usestdlibvars:
constant-kind: true
crypto-hash: true
default-rpc-path: true
http-method: true
http-status-code: true
sql-isolation-level: true
time-layout: true
time-month: true
time-weekday: true
tls-signature-scheme: true
usetesting:
os-setenv: true
os-temp-dir: true
whitespace:
# Enforce newlines (or comments) after multi-line function signatures.
multi-func: true

linters:
# We use 'disable-all' and enable linters explicitly so that a newer version
# does not introduce new linters unexpectedly.
disable-all: true
enable:
- bodyclose
- containedctx
- copyloopvar
- dupl
- dupword
- durationcheck
- errcheck
- errname
- errorlint
- exptostd
- forbidigo
- ginkgolinter
- gocheckcompilerdirectives
- goconst
- gocritic
- gofmt
- goimports
- gomoddirectives
- gosec
- gosimple
- govet
- ineffassign
- intrange
- misspell
- nilerr
- noctx
- nolintlint
- nosprintfhostport
- perfsprint
- predeclared
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tenv
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- usetesting
- whitespace
4 changes: 2 additions & 2 deletions Makefile.maker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ golang:
setGoModVersion: true

golangciLint:
createConfig: false
createConfig: true

githubWorkflow:
ci:
Expand All @@ -38,4 +38,4 @@ renovate:
- defo89
- SchwarzM
- xsen84
- goerangudat
- goerangudat
30 changes: 17 additions & 13 deletions cmd/parrot/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2025 SAP SE
// SPDX-License-Identifier: Apache-2.0

package main

import (
Expand All @@ -11,11 +14,13 @@ import (
"time"

"github.com/golang/glog"
"github.com/sapcc/go-bits/must"
"github.com/sapcc/go-traceroute/traceroute"
"github.com/sapcc/kube-parrot/pkg/metrics"
"github.com/sapcc/kube-parrot/pkg/parrot"
flag "github.com/spf13/pflag"
"golang.org/x/net/context"

"github.com/sapcc/kube-parrot/pkg/metrics"
"github.com/sapcc/kube-parrot/pkg/parrot"
)

type Neighbors []*net.IP
Expand All @@ -24,8 +29,8 @@ var opts parrot.Options
var neighbors Neighbors

func init() {
flag.IntVar(&opts.As, "as", 65000, "local BGP ASN")
flag.IntVar(&opts.RemoteAs, "remote-as", 0, "remote BGP ASN. Default to local ASN (iBGP)")
flag.Uint32Var(&opts.As, "as", 65000, "local BGP ASN")
flag.Uint32Var(&opts.RemoteAs, "remote-as", 0, "remote BGP ASN. Default to local ASN (iBGP)")
flag.StringVar(&opts.NodeName, "nodename", "", "Name of the node this pod is running on")
flag.IPVar(&opts.HostIP, "hostip", net.ParseIP("127.0.0.1"), "IP")
flag.IntVar(&opts.MetricsPort, "metric-port", 30039, "Port for Prometheus metrics")
Expand All @@ -36,7 +41,7 @@ func init() {
}

func main() {
goflag.CommandLine.Parse([]string{})
must.Succeed(goflag.CommandLine.Parse([]string{}))
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
flag.Parse()

Expand Down Expand Up @@ -68,21 +73,21 @@ func main() {
glog.V(2).Infof("Shutdown Completed. Bye!")
}

func (f *Neighbors) String() string {
return fmt.Sprintf("%v", *f)
func (n *Neighbors) String() string {
return fmt.Sprintf("%v", *n)
}

func (i *Neighbors) Set(value string) error {
func (n *Neighbors) Set(value string) error {
ip := net.ParseIP(value)
if ip == nil {
return fmt.Errorf("%v is not a valid IP address", value)
}

*i = append(*i, &ip)
*n = append(*n, &ip)
return nil
}

func (s *Neighbors) Type() string {
func (n *Neighbors) Type() string {
return "neighborSlice"
}

Expand All @@ -100,10 +105,9 @@ func getNeighbors() []*net.IP {
defer t.Close()

h := make(map[string]struct{})
for i := 0; i < opts.TraceCount; i++ {
for i := range opts.TraceCount {
dst := fmt.Sprintf("1.1.1.%v", i)
err := t.Trace(context.Background(), net.ParseIP(dst), func(reply *traceroute.Reply) {

h[reply.IP.String()] = struct{}{}
})
if err != nil {
Expand All @@ -112,7 +116,7 @@ func getNeighbors() []*net.IP {
}

var neigh []*net.IP
for k, _ := range h {
for k := range h {
ip := net.ParseIP(k)
neigh = append(neigh, &ip)
}
Expand Down
13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ require (
github.com/golang/glog v1.2.2
github.com/juju/ratelimit v1.0.2
github.com/osrg/gobgp v0.0.0-20180701120657-8e6bd4c7145d
github.com/prometheus/client_golang v1.20.4
github.com/prometheus/client_golang v1.20.5
github.com/sapcc/go-bits v0.0.0-20250110100829-6bde0afe3f09
github.com/sapcc/go-traceroute v0.0.0-20210130143923-d034613e85fc
github.com/spf13/pflag v1.0.5
golang.org/x/net v0.33.0
Expand Down Expand Up @@ -45,13 +46,13 @@ require (
github.com/klauspost/compress v1.17.9 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/common v0.61.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/satori/go.uuid v0.0.0-20180103174451-36e9d2ebbde5 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
Expand All @@ -63,14 +64,14 @@ require (
github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5 // indirect
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.56.3 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/tomb.v2 v2.0.0-20140626144623-14b3d72120e8 // indirect
Expand Down
Loading

0 comments on commit 7af14cc

Please sign in to comment.