diff --git a/.golangci.yaml b/.golangci.yaml index 711eb5b..b5051f7 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -38,10 +38,6 @@ linters-settings: check-type-assertions: true exclude-functions: - netlink.RouteGet - - viper.BindPFlags - - rand.Seed - - fmt.Errorf - - wg forbidigo: forbid: # ioutil package has been deprecated: https://github.com/golang/go/issues/42026 diff --git a/Makefile.maker.yaml b/Makefile.maker.yaml index 505bcdc..b6ac3db 100644 --- a/Makefile.maker.yaml +++ b/Makefile.maker.yaml @@ -17,10 +17,6 @@ golangciLint: createConfig: true errcheckExcludes: - netlink.RouteGet - - viper.BindPFlags - - rand.Seed - - fmt.Errorf - - wg githubWorkflow: ci: diff --git a/internal/cmd/command.go b/internal/cmd/command.go index 5383133..3a736c4 100644 --- a/internal/cmd/command.go +++ b/internal/cmd/command.go @@ -55,10 +55,14 @@ func init() { rootCmd.PersistentFlags().IntVar(&cfg.ArpRequestTimeoutSeconds, "arp-timeout-seconds", 1, "Timeout in seconds for node arp request") rootCmd.PersistentFlags().StringVar(&cfg.KubeContext, "kube_context", "", "kube-context to use") rootCmd.PersistentFlags().AddGoFlagSet(goflag.CommandLine) - _ = viper.BindPFlags(rootCmd.PersistentFlags()) + err := viper.BindPFlags(rootCmd.PersistentFlags()) + if err != nil { + os.Exit(1) + } - rand.Seed(time.Now().UnixNano()) - cfg.RandDelay = rand.Intn(1000) + 1000 + source := rand.NewSource(time.Now().UnixNano()) + rng := rand.New(source) + cfg.RandDelay = rng.Intn(1000) + 1000 metrics.Registry.MustRegister(metr.SentError, metr.Error, metr.ArpResolveError, metr.SentPacketsPeer, metr.SentPackets, metr.RecvPackets, metr.CallbackDuration) cfg.PeerList = make(map[string]conf.PeerEntry) diff --git a/internal/nflog/pmtud.go b/internal/nflog/pmtud.go index 057375b..fcd06dc 100644 --- a/internal/nflog/pmtud.go +++ b/internal/nflog/pmtud.go @@ -5,7 +5,6 @@ import ( golog "log" "net" "os" - "sync" "time" "github.com/florianl/go-nflog/v2" @@ -21,8 +20,6 @@ import ( const nfBufsize = 2 * 1024 * 1024 const readBufsize = 2 * 1024 * 1024 -var wg = sync.WaitGroup{} - type Controller struct { Log logr.Logger Cfg *config.Config diff --git a/internal/node/controller.go b/internal/node/controller.go index 3520f88..8dc47b7 100644 --- a/internal/node/controller.go +++ b/internal/node/controller.go @@ -2,13 +2,13 @@ package node import ( "context" - "fmt" + "errors" "strings" "time" "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" + k8serr "k8s.io/apimachinery/pkg/api/errors" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -42,7 +42,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) ( var node = corev1.Node{} err := r.Client.Get(ctx, request.NamespacedName, &node) if err != nil { - if errors.IsNotFound(err) { + if k8serr.IsNotFound(err) { log.Info("node not found, skip", "node", request.NamespacedName) // Node could have been deleted return reconcile.Result{}, nil @@ -51,7 +51,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) ( return reconcile.Result{}, err } if len(node.Status.Addresses) == 0 { - err = fmt.Errorf("no ip found for node %s", request.Name) + err = errors.New("no ip found for node") return reconcile.Result{}, err } log.Info(node.Status.Addresses[0].Address) @@ -61,7 +61,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) ( } mac, err := res.Resolve(node.Status.Addresses[0].Address) if err != nil { - err = fmt.Errorf("could not resolve mac address for node %s", request.Name) + err = errors.New("could not resolve mac address for node") metrics.ArpResolveError.WithLabelValues(r.Cfg.NodeName, request.Name).Inc() return reconcile.Result{}, err } diff --git a/internal/util/interface.go b/internal/util/interface.go index 1db40b5..937e8c6 100644 --- a/internal/util/interface.go +++ b/internal/util/interface.go @@ -1,7 +1,7 @@ package util import ( - "fmt" + "errors" "net" "strings" @@ -29,7 +29,7 @@ func GetReplicationInterface(cfg *config.Config, log logr.Logger) error { } } } - err = fmt.Errorf("no interface found with names: %v", cfg.InterfaceNames) + err = errors.New("no configured interface found") log.Error(err, "error getting replication interface") return err } @@ -48,7 +48,7 @@ func GetDefaultInterface(cfg *config.Config, log logr.Logger) error { return err } if len(route) == 0 { - err := fmt.Errorf("no default route found") + err := errors.New("no default route found") log.Error(err, "error getting default route") return err } @@ -93,7 +93,7 @@ func GetInterfaceIP(name string, log logr.Logger) (string, error) { } return ip.String(), nil } - err = fmt.Errorf("%s is not connected to the network", name) + err = errors.New("Interface is not connected to the network") log.Error(err, "error finding interface ip") return "", err }