diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index cdacd49a..474460e4 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -45,8 +45,8 @@ jobs: - name: Run golangci-lint uses: golangci/golangci-lint-action@v2.5.2 with: - version: v1.55.2 - args: --timeout 300s --skip-dirs test/skoop/e2e --skip-dirs-use-default -v -E goconst -E gofmt -E ineffassign -E goimports -E revive -E misspell -E vet -E deadcode + version: 1.62.2 + args: --timeout 300s --exclude-dirs test/skoop/e2e -v -E goconst -E gofmt -E ineffassign -E goimports -E revive -E misspell -E govet -E deadcode shellcheck: name: Shellcheck diff --git a/pkg/controller/cmd/root.go b/pkg/controller/cmd/root.go index f36653e2..7e97bac4 100644 --- a/pkg/controller/cmd/root.go +++ b/pkg/controller/cmd/root.go @@ -13,11 +13,10 @@ import ( // rootCmd represents the base command when called without any subcommands var ( rootCmd = &cobra.Command{ - Use: "skoop-controller", - Short: "skoop centralized controller", - PersistentPreRun: func(cmd *cobra.Command, args []string) { - }, - RunE: func(cmd *cobra.Command, args []string) error { + Use: "skoop-controller", + Short: "skoop centralized controller", + PersistentPreRun: func(_ *cobra.Command, _ []string) {}, + RunE: func(_ *cobra.Command, _ []string) error { config := &Config{} var err error if configPath != "" { diff --git a/pkg/controller/service/capture.go b/pkg/controller/service/capture.go index 34b509fd..2f96feca 100644 --- a/pkg/controller/service/capture.go +++ b/pkg/controller/service/capture.go @@ -56,7 +56,7 @@ func podListWithInformer() ([]*Pod, error) { if err != nil { return nil, fmt.Errorf("list pods failed: %v", err) } - return lo.Map[*corev1.Pod, *Pod](pods, func(pod *corev1.Pod, idx int) *Pod { + return lo.Map[*corev1.Pod, *Pod](pods, func(pod *corev1.Pod, _ int) *Pod { return &Pod{ Name: pod.Name, Namespace: pod.Namespace, @@ -76,7 +76,7 @@ func (c *controller) PodList(ctx context.Context) ([]*Pod, error) { if err != nil { return nil, fmt.Errorf("list pods failed: %v", err) } - return lo.Map[corev1.Pod, *Pod](pods.Items, func(pod corev1.Pod, idx int) *Pod { + return lo.Map[corev1.Pod, *Pod](pods.Items, func(pod corev1.Pod, _ int) *Pod { return &Pod{ Name: pod.Name, Namespace: pod.Namespace, @@ -91,7 +91,7 @@ func (c *controller) NodeList(ctx context.Context) ([]*Node, error) { if err != nil { return nil, fmt.Errorf("list pods failed: %v", err) } - return lo.Map[corev1.Node, *Node](nodes.Items, func(node corev1.Node, idx int) *Node { + return lo.Map[corev1.Node, *Node](nodes.Items, func(node corev1.Node, _ int) *Node { return &Node{ Name: node.Name, Labels: node.Labels, @@ -104,7 +104,7 @@ func (c *controller) NamespaceList(ctx context.Context) ([]string, error) { if err != nil { return nil, fmt.Errorf("list pods failed: %v", err) } - return lo.Map[corev1.Namespace, string](namespaces.Items, func(namespace corev1.Namespace, idx int) string { + return lo.Map[corev1.Namespace, string](namespaces.Items, func(namespace corev1.Namespace, _ int) string { return namespace.Name }), nil } diff --git a/pkg/exporter/btfhack/discover.go b/pkg/exporter/btfhack/discover.go index d03ea168..f17eac06 100644 --- a/pkg/exporter/btfhack/discover.go +++ b/pkg/exporter/btfhack/discover.go @@ -19,7 +19,7 @@ var ( cpCmd = &cobra.Command{ Use: "discover", Short: "copy or download appropriate btf file to dst path", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { if btfSrcPath == "" { btfSrcPath = defaultBTFPath } diff --git a/pkg/exporter/btfhack/test.go b/pkg/exporter/btfhack/test.go index 2587d05e..b77d95ce 100644 --- a/pkg/exporter/btfhack/test.go +++ b/pkg/exporter/btfhack/test.go @@ -15,7 +15,7 @@ var ( testCmd = &cobra.Command{ Use: "test", Short: "test btf support locally", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { if btfSrcPath == "" { btfSrcPath = defaultBTFPath } diff --git a/pkg/exporter/btfhack/version.go b/pkg/exporter/btfhack/version.go index bf14ae4d..3bb8cfe0 100644 --- a/pkg/exporter/btfhack/version.go +++ b/pkg/exporter/btfhack/version.go @@ -9,7 +9,7 @@ var ( versionCmd = &cobra.Command{ Use: "version", Short: "show version", - Run: func(_ *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { version.PrintVersion() }, } diff --git a/pkg/exporter/cmd/list.go b/pkg/exporter/cmd/list.go index 587b7b1a..ab11e28e 100644 --- a/pkg/exporter/cmd/list.go +++ b/pkg/exporter/cmd/list.go @@ -9,8 +9,8 @@ var ( listCmd = &cobra.Command{ Use: "list", Short: "list available options", - Run: func(cmd *cobra.Command, args []string) { - cmd.Help() // nolint + Run: func(cmd *cobra.Command, _ []string) { + _ = cmd.Help() // nolint }, } ) diff --git a/pkg/exporter/cmd/list_probe.go b/pkg/exporter/cmd/list_probe.go index c871b3ae..6b0dab83 100644 --- a/pkg/exporter/cmd/list_probe.go +++ b/pkg/exporter/cmd/list_probe.go @@ -15,7 +15,7 @@ var ( probeCmd = &cobra.Command{ Use: "probe", Short: "list supported probe with metric exporting", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { res := make(map[string][]string) res["metrics"] = probe.ListMetricsProbes() res["event"] = probe.ListEventProbes() diff --git a/pkg/exporter/cmd/root.go b/pkg/exporter/cmd/root.go index bc692708..e5861c36 100644 --- a/pkg/exporter/cmd/root.go +++ b/pkg/exporter/cmd/root.go @@ -13,7 +13,7 @@ var ( rootCmd = &cobra.Command{ Use: "inspector", Short: "network inspection tool", - PersistentPreRun: func(cmd *cobra.Command, args []string) { + PersistentPreRun: func(_ *cobra.Command, _ []string) { if debug { log.SetLevel(log.DebugLevel) } else { diff --git a/pkg/exporter/cmd/server.go b/pkg/exporter/cmd/server.go index f79f67cb..2cb7e477 100644 --- a/pkg/exporter/cmd/server.go +++ b/pkg/exporter/cmd/server.go @@ -45,7 +45,7 @@ var ( serverCmd = &cobra.Command{ Use: "server", Short: "start inspector server", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { insp := &inspServer{ configPath: configPath, ctx: context.Background(), diff --git a/pkg/exporter/cmd/version.go b/pkg/exporter/cmd/version.go index 1646d5ef..7082b6e8 100644 --- a/pkg/exporter/cmd/version.go +++ b/pkg/exporter/cmd/version.go @@ -9,7 +9,7 @@ var ( versionCmd = &cobra.Command{ Use: "version", Short: "show version", - Run: func(_ *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { version.PrintVersion() }, } diff --git a/pkg/exporter/task-agent/ping_test.go b/pkg/exporter/task-agent/ping_test.go index 8253dd5a..516b019b 100644 --- a/pkg/exporter/task-agent/ping_test.go +++ b/pkg/exporter/task-agent/ping_test.go @@ -10,10 +10,10 @@ func TestGetLatency(t *testing.T) { round-trip min/avg/max = 43.689/43.720/43.809 ms` min, avg, max, err := getLatency(pingStr) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } if min != 43.689 || avg != 43.720 || max != 43.809 { - t.Fatalf("min/avg/max is not correct") + t.Fatal("min/avg/max is not correct") } t.Logf("min/avg/max is %v, %v, %v", min, avg, max) } diff --git a/pkg/skoop/assertions/netstack.go b/pkg/skoop/assertions/netstack.go index ceb84265..401efd57 100644 --- a/pkg/skoop/assertions/netstack.go +++ b/pkg/skoop/assertions/netstack.go @@ -99,7 +99,7 @@ func (na *NetstackAssertion) AssertNoPolicyRoute() { } func (na *NetstackAssertion) AssertListen(localIP net.IP, localPort uint16, protocol model.Protocol) { - socks := lo.Filter(na.netns.NetNSInfo.ConnStats, func(stat netstack.ConnStat, index int) bool { + socks := lo.Filter(na.netns.NetNSInfo.ConnStats, func(stat netstack.ConnStat, _ int) bool { if stat.State == netstack.SockStatListen && strings.EqualFold(string(stat.Protocol), string(protocol)) && localPort == stat.LocalPort { if localIP.String() == stat.LocalIP { return true diff --git a/pkg/skoop/cmd/app.go b/pkg/skoop/cmd/app.go index 0aa79eb6..519825df 100644 --- a/pkg/skoop/cmd/app.go +++ b/pkg/skoop/cmd/app.go @@ -22,7 +22,7 @@ func NewSkoopCmd() *cobra.Command { cmd := &cobra.Command{ Use: "skoop", Long: "Skoop is an one-shot kubernetes network diagnose tool.", - PreRunE: func(cmd *cobra.Command, args []string) error { + PreRunE: func(_ *cobra.Command, _ []string) error { if context.SkoopContext.MiscConfig().Version { version.PrintVersion() os.Exit(0) @@ -35,7 +35,7 @@ func NewSkoopCmd() *cobra.Command { } return context.SkoopContext.BuildTask() }, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { prvd, err := provider.GetProvider(context.SkoopContext.ClusterConfig().CloudProvider) if err != nil { klog.Fatalf("error get service provider: %v", err) diff --git a/pkg/skoop/collector/podcollector/collector.go b/pkg/skoop/collector/podcollector/collector.go index 1cceea8d..d49e9017 100644 --- a/pkg/skoop/collector/podcollector/collector.go +++ b/pkg/skoop/collector/podcollector/collector.go @@ -62,7 +62,7 @@ func (a *podCollector) DumpNodeInfos() (*k8s.NodeNetworkStackDump, error) { dump.Pods = nil } if a.podNamespace != "" && a.podName != "" { - dump.Pods = lo.Filter(dump.Pods, func(item k8s.PodNetInfo, index int) bool { + dump.Pods = lo.Filter(dump.Pods, func(item k8s.PodNetInfo, _ int) bool { return item.PodNamespace == a.podNamespace && item.PodName == a.podName }) collectHost = false diff --git a/pkg/skoop/context/task.go b/pkg/skoop/context/task.go index 09ac74a1..bfb7ac4b 100644 --- a/pkg/skoop/context/task.go +++ b/pkg/skoop/context/task.go @@ -34,7 +34,7 @@ func (tc *TaskConfig) Validate() error { return fmt.Errorf("source or destination address cannot be empty") } - if tc.Destination.Port <= 0 || tc.Destination.Port > 65535 { + if tc.Destination.Port == 0 { return fmt.Errorf("a valid destination port should be provided") }