Skip to content

Commit

Permalink
Merge pull request #16011 from vrothberg/lint
Browse files Browse the repository at this point in the history
bump golangci-lint to v1.49.0
  • Loading branch information
openshift-merge-robot authored Oct 17, 2022
2 parents 29d0cbe + 44bac51 commit cd0c949
Show file tree
Hide file tree
Showing 49 changed files with 400 additions and 262 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ linters:
disable:
# All these break for one reason or another
- tagliatelle # too many JSON keys cannot be changed due to compat
- nosnakecase # too many false positives due to the `unix` package
- gocognit
- testpackage
- goerr113
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ install.tools: .install.ginkgo .install.golangci-lint .install.swagger ## Instal

.PHONY: .install.golangci-lint
.install.golangci-lint:
VERSION=1.46.2 ./hack/install_golangci.sh
VERSION=1.49.0 ./hack/install_golangci.sh

.PHONY: .install.swagger
.install.swagger:
Expand Down
1 change: 1 addition & 0 deletions cmd/podman/common/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (c *Car) Color() string {
}

// This is for reflect testing required.
//
//nolint:unused
func (c Car) internal() int {
return 0
Expand Down
10 changes: 6 additions & 4 deletions cmd/podman/utils/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ func (o OutputErrors) PrintErrors() (lastError error) {
return
}

/* For remote client, server does not returns error with exit code
instead returns a message and we cast it to a new error.
/*
For remote client, server does not returns error with exit code
Following function performs parsing on build error and returns
exit status which was expected for this current build
instead returns a message and we cast it to a new error.
Following function performs parsing on build error and returns
exit status which was expected for this current build
*/
func ExitCodeFromBuildError(errorMsg string) (int, error) {
if strings.Contains(errorMsg, "exit status") {
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/validate/choice.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type ChoiceValue struct {
// Value may be used in cobra FlagSet methods Var/VarP/VarPF() to select from a set of values
//
// Example:
// created := validate.ChoiceValue(&opts.Sort, "command", "created", "id", "image", "names", "runningfor", "size", "status")
//
// created := validate.ChoiceValue(&opts.Sort, "command", "created", "id", "image", "names", "runningfor", "size", "status")
// flags.Var(created, "sort", "Sort output by: "+created.Choices())
func Value(p *string, choices ...string) *ChoiceValue {
return &ChoiceValue{
Expand Down
2 changes: 1 addition & 1 deletion libpod/container_path_resolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func findBindMount(c *Container, containerPath string) *specs.Mount {
return nil
}

/// isPathOnMount returns true if the specified containerPath is a subdir of any
// / isPathOnMount returns true if the specified containerPath is a subdir of any
// Mount's destination.
func isPathOnMount(c *Container, containerPath string) bool {
cleanedContainerPath := filepath.Clean(containerPath)
Expand Down
1 change: 1 addition & 0 deletions libpod/define/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ type HealthCheckLog struct {
// as possible from the spec and container config.
// Some things cannot be inferred. These will be populated by spec annotations
// (if available).
//
//nolint:revive,stylecheck // Field names are fixed for compatibility and cannot be changed.
type InspectContainerHostConfig struct {
// Binds contains an array of user-added mounts.
Expand Down
2 changes: 1 addition & 1 deletion libpod/lock/shm/shm_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (

// SHMLocks is a struct enabling POSIX semaphore locking in a shared memory
// segment.
type SHMLocks struct {
type SHMLocks struct { //nolint:revive // linter complains about stutter
lockStruct *C.shm_struct_t
maxLocks uint32
valid bool
Expand Down
2 changes: 1 addition & 1 deletion libpod/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// The code calling the OCIRuntime will manage this.
// TODO: May want to move the conmon cleanup code here - it depends on
// Conmon being in use.
type OCIRuntime interface {
type OCIRuntime interface { //nolint:interfacebloat
// Name returns the name of the runtime.
Name() string
// Path returns the path to the runtime executable.
Expand Down
31 changes: 21 additions & 10 deletions libpod/oci_conmon_attach_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,28 @@ func (r *ConmonOCIRuntime) Attach(c *Container, params *AttachOptions) error {
return readStdio(conn, params.Streams, receiveStdoutError, stdinDone)
}

// Attach to the given container's exec session
// attachFd and startFd must be open file descriptors
// attachFd must be the output side of the fd. attachFd is used for two things:
// conmon will first send a nonce value across the pipe indicating it has set up its side of the console socket
// this ensures attachToExec gets all of the output of the called process
// conmon will then send the exit code of the exec process, or an error in the exec session
// Attach to the given container's exec session.
//
// attachFd and startFd must be open file descriptors. attachFd must be the
// output side of the fd and is used for two things:
//
// 1. conmon will first send a nonce value across the pipe indicating it has
// set up its side of the console socket this ensures attachToExec gets all of
// the output of the called process.
//
// 2. conmon will then send the exit code of the exec process, or an error in the exec session.
//
// startFd must be the input side of the fd.
// newSize resizes the tty to this size before the process is started, must be nil if the exec session has no tty
// conmon will wait to start the exec session until the parent process has set up the console socket.
// Once attachToExec successfully attaches to the console socket, the child conmon process responsible for calling runtime exec
// will read from the output side of start fd, thus learning to start the child process.
//
// newSize resizes the tty to this size before the process is started, must be
// nil if the exec session has no tty
//
// conmon will wait to start the exec session until the parent process has set up the console socket.
//
// Once attachToExec successfully attaches to the console socket, the child
// conmon process responsible for calling runtime exec will read from the
// output side of start fd, thus learning to start the child process.
//
// Thus, the order goes as follow:
// 1. conmon parent process sets up its console socket. sends on attachFd
// 2. attachToExec attaches to the console socket after reading on attachFd and resizes the tty
Expand Down
2 changes: 1 addition & 1 deletion libpod/oci_conmon_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p
case define.PassthroughLogging:
logDriverArg = define.PassthroughLogging
//lint:ignore ST1015 the default case has to be here
default: //nolint:stylecheck,gocritic
default: //nolint:gocritic
// No case here should happen except JSONLogging, but keep this here in case the options are extended
logrus.Errorf("%s logging specified but not supported. Choosing k8s-file logging instead", ctr.LogDriver())
fallthrough
Expand Down
8 changes: 4 additions & 4 deletions libpod/plugin/volume_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type activateResponse struct {
func validatePlugin(newPlugin *VolumePlugin) error {
// It's a socket. Is it a plugin?
// Hit the Activate endpoint to find out if it is, and if so what kind
req, err := http.NewRequest("POST", "http://plugin"+activatePath, nil)
req, err := http.NewRequest(http.MethodPost, "http://plugin"+activatePath, nil)
if err != nil {
return fmt.Errorf("making request to volume plugin %s activation endpoint: %w", newPlugin.Name, err)
}
Expand All @@ -90,7 +90,7 @@ func validatePlugin(newPlugin *VolumePlugin) error {

// Response code MUST be 200. Anything else, we have to assume it's not
// a valid plugin.
if resp.StatusCode != 200 {
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("got status code %d from activation endpoint for plugin %s: %w", resp.StatusCode, newPlugin.Name, ErrNotPlugin)
}

Expand Down Expand Up @@ -216,7 +216,7 @@ func (p *VolumePlugin) sendRequest(toJSON interface{}, endpoint string) (*http.R
}
}

req, err := http.NewRequest("POST", "http://plugin"+endpoint, bytes.NewReader(reqJSON))
req, err := http.NewRequest(http.MethodPost, "http://plugin"+endpoint, bytes.NewReader(reqJSON))
if err != nil {
return nil, fmt.Errorf("making request to volume plugin %s endpoint %s: %w", p.Name, endpoint, err)
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (p *VolumePlugin) handleErrorResponse(resp *http.Response, endpoint, volNam
// errors, but I don't think we can guarantee all plugins do that.
// Let's interpret anything other than 200 as an error.
// If there isn't an error, don't even bother decoding the response.
if resp.StatusCode != 200 {
if resp.StatusCode != http.StatusOK {
errResp, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("reading response body from volume plugin %s: %w", p.Name, err)
Expand Down
2 changes: 1 addition & 1 deletion libpod/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import "github.com/containers/common/libnetwork/types"
// retrieved after they are pulled from the database.
// Generally speaking, the syncContainer() call should be run at the beginning
// of all API operations, which will silently handle this.
type State interface {
type State interface { //nolint:interfacebloat
// Close performs any pre-exit cleanup (e.g. closing database
// connections) that may be required
Close() error
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/handlers/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func NewAPIDecoder() *schema.Decoder {
}

// On client:
// v := map[string][]string{
//
// v := map[string][]string{
// "dangling": {"true"},
// }
//
Expand Down
22 changes: 10 additions & 12 deletions pkg/api/handlers/swagger/doc.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// Package swagger defines the payloads used by the Podman API
//
// - errors.go: declares the errors used in the API. By embedding errors.ErrorModel, more meaningful
// comments can be provided for the developer documentation.
// - models.go: declares the models used in API requests.
// - responses.go: declares the responses used in the API responses.
//
// - errors.go: declares the errors used in the API. By embedding errors.ErrorModel, more meaningful
// comments can be provided for the developer documentation.
// - models.go: declares the models used in API requests.
// - responses.go: declares the responses used in the API responses.
//
// Notes:
// 1. As a developer of the Podman API, you are responsible for maintaining the associations between
// these models and responses, and the handler code.
// 2. There are a number of warnings produces when compiling the swagger yaml file. This is expected.
// Most are because embedded structs have been discovered but not used in the API declarations.
// 3. Response and model references that are exported (start with upper-case letter) imply that they
// exist outside this package and should be found in the entities package.
//
// 1. As a developer of the Podman API, you are responsible for maintaining the associations between
// these models and responses, and the handler code.
// 2. There are a number of warnings produces when compiling the swagger yaml file. This is expected.
// Most are because embedded structs have been discovered but not used in the API declarations.
// 3. Response and model references that are exported (start with upper-case letter) imply that they
// exist outside this package and should be found in the entities package.
package swagger
2 changes: 1 addition & 1 deletion pkg/api/handlers/utils/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func WaitContainerDocker(w http.ResponseWriter, r *http.Request) {
// In docker compatibility mode we have to send headers in advance,
// otherwise docker client would freeze.
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
if flusher, ok := w.(http.Flusher); ok {
flusher.Flush()
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/handlers/utils/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestSupportedVersion(t *testing.T) {
req, err := http.NewRequest("GET",
req, err := http.NewRequest(http.MethodGet,
fmt.Sprintf("/v%s/libpod/testing/versions", version.APIVersion[version.Libpod][version.CurrentAPI]),
nil)
if err != nil {
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestSupportedVersion(t *testing.T) {

func TestUnsupportedVersion(t *testing.T) {
version := "999.999.999"
req, err := http.NewRequest("GET",
req, err := http.NewRequest(http.MethodGet,
fmt.Sprintf("/v%s/libpod/testing/versions", version),
nil)
if err != nil {
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestUnsupportedVersion(t *testing.T) {

func TestEqualVersion(t *testing.T) {
version := "1.30.0"
req, err := http.NewRequest("GET",
req, err := http.NewRequest(http.MethodGet,
fmt.Sprintf("/v%s/libpod/testing/versions", version),
nil)
if err != nil {
Expand Down
56 changes: 28 additions & 28 deletions pkg/api/server/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// To start the service and keep it running for 5,000 seconds (-t 0 runs forever):
//
// podman system service -t 5000 &
// podman system service -t 5000 &
//
// You can then use cURL on the socket using requests documented below.
//
Expand All @@ -23,44 +23,44 @@
//
// See podman-service(1) for more information.
//
// Quick Examples:
// Quick Examples:
//
// 'podman info'
// 'podman info'
//
// curl --unix-socket /run/podman/podman.sock http://d/v4.0.0/libpod/info
// curl --unix-socket /run/podman/podman.sock http://d/v4.0.0/libpod/info
//
// 'podman pull quay.io/containers/podman'
// 'podman pull quay.io/containers/podman'
//
// curl -XPOST --unix-socket /run/podman/podman.sock -v 'http://d/v4.0.0/images/create?fromImage=quay.io%2Fcontainers%2Fpodman'
// curl -XPOST --unix-socket /run/podman/podman.sock -v 'http://d/v4.0.0/images/create?fromImage=quay.io%2Fcontainers%2Fpodman'
//
// 'podman list images'
// 'podman list images'
//
// curl --unix-socket /run/podman/podman.sock -v 'http://d/v4.0.0/libpod/images/json' | jq
// curl --unix-socket /run/podman/podman.sock -v 'http://d/v4.0.0/libpod/images/json' | jq
//
// Terms Of Service:
//
// https://github.com/containers/podman/blob/913caaa9b1de2b63692c9bae15120208194c9eb3/LICENSE
//
// Schemes: http, https
// Host: podman.io
// BasePath: /
// Version: 4.0.0
// License: Apache-2.0 https://opensource.org/licenses/Apache-2.0
// Contact: Podman <[email protected]> https://podman.io/community/
//
// InfoExtensions:
// x-logo:
// - url: https://raw.githubusercontent.com/containers/libpod/main/logo/podman-logo.png
// - altText: "Podman logo"
//
// Produces:
// - application/json
// - application/octet-stream
// - text/plain
//
// Consumes:
// - application/json
// - application/x-tar
// Schemes: http, https
// Host: podman.io
// BasePath: /
// Version: 4.0.0
// License: Apache-2.0 https://opensource.org/licenses/Apache-2.0
// Contact: Podman <[email protected]> https://podman.io/community/
//
// InfoExtensions:
// x-logo:
// - url: https://raw.githubusercontent.com/containers/libpod/main/logo/podman-logo.png
// - altText: "Podman logo"
//
// Produces:
// - application/json
// - application/octet-stream
// - text/plain
//
// Consumes:
// - application/json
// - application/x-tar
//
// swagger:meta
package server
8 changes: 4 additions & 4 deletions pkg/api/server/idle/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func NewTracker(idle time.Duration) *Tracker {
}

// ConnState is called on HTTP connection state changes.
// - Once StateHijacked, StateClose is _NOT_ called on that connection
// - There are two "idle" timeouts, the http idle connection (not to be confused with the TCP/IP idle socket timeout)
// and the API idle window. The caller should set the http idle timeout to 2x the time provided to NewTacker() which
// is the API idle window.
// - Once StateHijacked, StateClose is _NOT_ called on that connection
// - There are two "idle" timeouts, the http idle connection (not to be confused with the TCP/IP idle socket timeout)
// and the API idle window. The caller should set the http idle timeout to 2x the time provided to NewTacker() which
// is the API idle window.
func (t *Tracker) ConnState(conn net.Conn, state http.ConnState) {
t.mux.Lock()
defer t.mux.Unlock()
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/server/listener_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

// ListenUnix follows stdlib net.Listen() API, providing a unix listener for given path
// ListenUnix will delete and create files/directories as needed
//
// ListenUnix will delete and create files/directories as needed
func ListenUnix(network string, path string) (net.Listener, error) {
// set up custom listener for API server
err := os.MkdirAll(filepath.Dir(path), 0770)
Expand Down
2 changes: 1 addition & 1 deletion pkg/autoupdate/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func LookupPolicy(s string) (Policy, error) {
return "", fmt.Errorf("invalid auto-update policy %q: valid policies are %+q", s, keys)
}

/// AutoUpdate looks up containers with a specified auto-update policy and acts
// / AutoUpdate looks up containers with a specified auto-update policy and acts
// accordingly.
//
// If the policy is set to PolicyRegistryImage, it checks if the image
Expand Down
Loading

0 comments on commit cd0c949

Please sign in to comment.