Skip to content

Commit

Permalink
Merge pull request #1759 from saschagrunert/wsl-nlreturn
Browse files Browse the repository at this point in the history
Enable `wsl` and `nlreturn` linters
  • Loading branch information
k8s-ci-robot authored Jan 27, 2025
2 parents 3a73c5c + f23688f commit 29437ed
Show file tree
Hide file tree
Showing 50 changed files with 675 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ linters:
- nestif
- nilerr
- nilnesserr
- nlreturn
- noctx
- nolintlint
- nosprintfhostport
Expand Down Expand Up @@ -97,6 +98,7 @@ linters:
- usetesting
- wastedassign
- whitespace
- wsl
- zerologlint
# - depguard
# - err113
Expand All @@ -110,12 +112,10 @@ linters:
# - lll
# - mnd
# - nilnil
# - nlreturn
# - nonamedreturns
# - testpackage
# - varnamelen
# - wrapcheck
# - wsl
linters-settings:
stylecheck:
checks:
Expand Down
7 changes: 7 additions & 0 deletions cmd/crictl/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var runtimeAttachCommand = &cli.Command{
if err = Attach(ctx, runtimeClient, opts); err != nil {
return fmt.Errorf("attaching running container failed: %w", err)
}

return nil
},
}
Expand All @@ -111,6 +112,7 @@ func Attach(ctx context.Context, client internalapi.RuntimeService, opts attachO
if opts.id == "" {
return errors.New("ID cannot be empty")
}

request := &pb.AttachRequest{
ContainerId: opts.id,
Tty: opts.tty,
Expand All @@ -119,13 +121,16 @@ func Attach(ctx context.Context, client internalapi.RuntimeService, opts attachO
Stderr: !opts.tty,
}
logrus.Debugf("AttachRequest: %v", request)

r, err := InterruptableRPC(ctx, func(ctx context.Context) (*pb.AttachResponse, error) {
return client.Attach(ctx, request)
})
logrus.Debugf("AttachResponse: %v", r)

if err != nil {
return err
}

attachURL := r.Url

URL, err := url.Parse(attachURL)
Expand All @@ -136,10 +141,12 @@ func Attach(ctx context.Context, client internalapi.RuntimeService, opts attachO
if URL.Host == "" {
URL.Host = kubeletURLHost
}

if URL.Scheme == "" {
URL.Scheme = kubeletURLSchema
}

logrus.Debugf("Attach URL: %v", URL)

return stream(ctx, opts.stdin, opts.tty, opts.transport, URL, opts.tlsConfig)
}
8 changes: 8 additions & 0 deletions cmd/crictl/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ complete -F _crictl crictl`

func bashCompletion(c *cli.Context) error {
subcommands := []string{}

for _, command := range c.App.Commands {
if command.Hidden {
continue
}

subcommands = append(subcommands, command.Names()...)
}

Expand All @@ -50,6 +52,7 @@ func bashCompletion(c *cli.Context) error {
}

fmt.Fprintln(c.App.Writer, fmt.Sprintf(bashCompletionTemplate, strings.Join(subcommands, "\n")))

return nil
}

Expand All @@ -71,10 +74,12 @@ compdef _crictl crictl`

func zshCompletion(c *cli.Context) error {
subcommands := []string{}

for _, command := range c.App.Commands {
if command.Hidden {
continue
}

for _, name := range command.Names() {
subcommands = append(subcommands, name+":"+command.Usage)
}
Expand All @@ -87,6 +92,7 @@ func zshCompletion(c *cli.Context) error {
}

fmt.Fprintln(c.App.Writer, fmt.Sprintf(zshCompletionTemplate, strings.Join(subcommands, "' '"), strings.Join(opts, "' '")))

return nil
}

Expand All @@ -95,7 +101,9 @@ func fishCompletion(c *cli.Context) error {
if err != nil {
return err
}

fmt.Fprintln(c.App.Writer, completion)

return nil
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/crictl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ CRICTL OPTIONS:
default:
return fmt.Errorf("no configuration option named %s", get)
}

return nil
} else if c.IsSet("set") {
settings := c.StringSlice("set")
Expand All @@ -115,6 +116,7 @@ CRICTL OPTIONS:
}
}
}

return common.WriteConfig(config, configFile)
} else if c.Bool("list") {
display := newDefaultTableDisplay()
Expand All @@ -141,6 +143,7 @@ CRICTL OPTIONS:
if err := setValue(key, value, config); err != nil {
return fmt.Errorf("set %q to %q: %w", key, value, err)
}

return common.WriteConfig(config, configFile)
},
}
Expand All @@ -156,27 +159,32 @@ func setValue(key, value string, config *common.Config) error {
if err != nil {
return fmt.Errorf("parse timeout value '%s': %w", value, err)
}

config.Timeout = n
case common.Debug:
debug, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("parse debug value '%s': %w", value, err)
}

config.Debug = debug
case common.PullImageOnCreate:
pi, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("parse pull-image-on-create value '%s': %w", value, err)
}

config.PullImageOnCreate = pi
case common.DisablePullOnRun:
pi, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("parse disable-pull-on-run value '%s': %w", value, err)
}

config.DisablePullOnRun = pi
default:
return fmt.Errorf("no configuration option named %s", key)
}

return nil
}
Loading

0 comments on commit 29437ed

Please sign in to comment.