Skip to content

Commit

Permalink
upgrade golangci-lint to 1.62.2 & fix lint issues
Browse files Browse the repository at this point in the history
Signed-off-by: xiayu.lyt <[email protected]>
  • Loading branch information
Lyt99 committed Dec 5, 2024
1 parent 91c3330 commit ef9aaaa
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ jobs:
- name: Run golangci-lint
uses: golangci/[email protected]
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
Expand Down
9 changes: 4 additions & 5 deletions pkg/controller/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/service/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/btfhack/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/btfhack/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/btfhack/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/exporter/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/cmd/list_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/exporter/task-agent/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/skoop/assertions/netstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/skoop/cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/skoop/collector/podcollector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/skoop/context/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit ef9aaaa

Please sign in to comment.