From 41b3cd2535a8ab749edc1907b2f5962917cb24cd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 31 Aug 2022 09:43:17 +0200 Subject: [PATCH] remove unneeded nolint-comments (nolintlint), disable deprecated linters Remove nolint-comments that weren't hit by linters, and remove the "structcheck" and "varcheck" linters, as they have been deprecated: WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused. WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused. WARN [linters context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649. Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 3 +-- archive/tar_unix.go | 2 +- integration/main_test.go | 16 ++++++++-------- oci/spec_opts.go | 6 +++--- oci/spec_opts_nonlinux.go | 8 -------- oci/utils_unix.go | 4 ++-- pkg/cri/sbserver/container_stats.go | 2 +- pkg/cri/sbserver/container_stats_list.go | 2 +- pkg/cri/sbserver/sandbox_stats.go | 4 ++-- pkg/cri/sbserver/sandbox_stats_list.go | 4 ++-- pkg/cri/sbserver/service.go | 2 +- pkg/cri/server/container_stats.go | 2 +- pkg/cri/server/container_stats_list.go | 2 +- pkg/cri/server/sandbox_stats.go | 4 ++-- pkg/cri/server/sandbox_stats_list.go | 4 ++-- pkg/cri/server/service.go | 2 +- pkg/cri/store/container/metadata.go | 3 +-- pkg/cri/store/container/status.go | 3 +-- pkg/cri/store/sandbox/metadata.go | 3 +-- pkg/progress/escape.go | 2 +- 20 files changed, 33 insertions(+), 45 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 748863672c2c6..08699988a3556 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,13 +6,12 @@ linters: - gosec - ineffassign - misspell + - nolintlint - revive - staticcheck - - structcheck - tenv # Detects using os.Setenv instead of t.Setenv since Go 1.17 - unconvert - unused - - varcheck - vet disable: - errcheck diff --git a/archive/tar_unix.go b/archive/tar_unix.go index ac80df34939b1..7029e56e627d7 100644 --- a/archive/tar_unix.go +++ b/archive/tar_unix.go @@ -58,7 +58,7 @@ func setHeaderForSpecialDevice(hdr *tar.Header, name string, fi os.FileInfo) err return errors.New("unsupported stat type") } - rdev := uint64(s.Rdev) //nolint:unconvert // rdev is int32 on darwin/bsd, int64 on linux/solaris + rdev := uint64(s.Rdev) //nolint:nolintlint,unconvert // rdev is int32 on darwin/bsd, int64 on linux/solaris // Currently go does not fill in the major/minors if s.Mode&syscall.S_IFBLK != 0 || diff --git a/integration/main_test.go b/integration/main_test.go index 1bb097c0e8ac4..dc07d669790e1 100644 --- a/integration/main_test.go +++ b/integration/main_test.go @@ -210,7 +210,7 @@ func PodSandboxConfigWithCleanup(t *testing.T, name, ns string, opts ...PodSandb } // Set Windows HostProcess on the pod. -func WithWindowsHostProcessPod(p *runtime.PodSandboxConfig) { //nolint:unused +func WithWindowsHostProcessPod(p *runtime.PodSandboxConfig) { if p.Windows == nil { p.Windows = &runtime.WindowsPodSandboxConfig{} } @@ -237,7 +237,7 @@ func WithTestAnnotations() ContainerOpts { } // Add container resource limits. -func WithResources(r *runtime.LinuxContainerResources) ContainerOpts { //nolint:unused +func WithResources(r *runtime.LinuxContainerResources) ContainerOpts { return func(c *runtime.ContainerConfig) { if c.Linux == nil { c.Linux = &runtime.LinuxContainerConfig{} @@ -247,7 +247,7 @@ func WithResources(r *runtime.LinuxContainerResources) ContainerOpts { //nolint: } // Adds Windows container resource limits. -func WithWindowsResources(r *runtime.WindowsContainerResources) ContainerOpts { //nolint:unused +func WithWindowsResources(r *runtime.WindowsContainerResources) ContainerOpts { return func(c *runtime.ContainerConfig) { if c.Windows == nil { c.Windows = &runtime.WindowsContainerConfig{} @@ -265,7 +265,7 @@ func WithVolumeMount(hostPath, containerPath string) ContainerOpts { } } -func WithWindowsUsername(username string) ContainerOpts { //nolint:unused +func WithWindowsUsername(username string) ContainerOpts { return func(c *runtime.ContainerConfig) { if c.Windows == nil { c.Windows = &runtime.WindowsContainerConfig{} @@ -277,7 +277,7 @@ func WithWindowsUsername(username string) ContainerOpts { //nolint:unused } } -func WithWindowsHostProcessContainer() ContainerOpts { //nolint:unused +func WithWindowsHostProcessContainer() ContainerOpts { return func(c *runtime.ContainerConfig) { if c.Windows == nil { c.Windows = &runtime.WindowsContainerConfig{} @@ -322,7 +322,7 @@ func WithLogPath(path string) ContainerOpts { } // WithSupplementalGroups adds supplemental groups. -func WithSupplementalGroups(gids []int64) ContainerOpts { //nolint:unused +func WithSupplementalGroups(gids []int64) ContainerOpts { return func(c *runtime.ContainerConfig) { if c.Linux == nil { c.Linux = &runtime.LinuxContainerConfig{} @@ -335,7 +335,7 @@ func WithSupplementalGroups(gids []int64) ContainerOpts { //nolint:unused } // WithDevice adds a device mount. -func WithDevice(containerPath, hostPath, permissions string) ContainerOpts { //nolint:unused +func WithDevice(containerPath, hostPath, permissions string) ContainerOpts { return func(c *runtime.ContainerConfig) { c.Devices = append(c.Devices, &runtime.Device{ ContainerPath: containerPath, HostPath: hostPath, Permissions: permissions, @@ -558,7 +558,7 @@ func CRIConfig() (*criconfig.Config, error) { } // SandboxInfo gets sandbox info. -func SandboxInfo(id string) (*runtime.PodSandboxStatus, *server.SandboxInfo, error) { //nolint:unused +func SandboxInfo(id string) (*runtime.PodSandboxStatus, *server.SandboxInfo, error) { client, err := RawRuntimeClient() if err != nil { return nil, nil, fmt.Errorf("failed to get raw runtime client: %w", err) diff --git a/oci/spec_opts.go b/oci/spec_opts.go index 45c4fc180be8a..f5e69860f7dd5 100644 --- a/oci/spec_opts.go +++ b/oci/spec_opts.go @@ -84,7 +84,7 @@ func setResources(s *Spec) { } } -//nolint:unused // not used on all platforms +//nolint:nolintlint,unused // not used on all platforms func setResourcesWindows(s *Spec) { if s.Windows != nil { if s.Windows.Resources == nil { @@ -93,7 +93,7 @@ func setResourcesWindows(s *Spec) { } } -//nolint:unused // not used on all platforms +//nolint:nolintlint,unused // not used on all platforms func setCPU(s *Spec) { setResources(s) if s.Linux != nil { @@ -103,7 +103,7 @@ func setCPU(s *Spec) { } } -//nolint:deadcode,unused // not used on all platforms +//nolint:deadcode,nolintlint,unused // not used on all platforms func setCPUWindows(s *Spec) { setResourcesWindows(s) if s.Windows != nil { diff --git a/oci/spec_opts_nonlinux.go b/oci/spec_opts_nonlinux.go index e376a86b3bbc1..30aedd6cdd28a 100644 --- a/oci/spec_opts_nonlinux.go +++ b/oci/spec_opts_nonlinux.go @@ -28,22 +28,16 @@ import ( // WithAllCurrentCapabilities propagates the effective capabilities of the caller process to the container process. // The capability set may differ from WithAllKnownCapabilities when running in a container. -// -//nolint:unused var WithAllCurrentCapabilities = func(ctx context.Context, client Client, c *containers.Container, s *Spec) error { return WithCapabilities(nil)(ctx, client, c, s) } // WithAllKnownCapabilities sets all the known linux capabilities for the container process -// -//nolint:unused var WithAllKnownCapabilities = func(ctx context.Context, client Client, c *containers.Container, s *Spec) error { return WithCapabilities(nil)(ctx, client, c, s) } // WithBlockIO sets the container's blkio parameters -// -//nolint:unused func WithBlockIO(blockio interface{}) SpecOpts { return func(ctx context.Context, _ Client, c *containers.Container, s *Spec) error { return errors.New("blkio not supported") @@ -51,8 +45,6 @@ func WithBlockIO(blockio interface{}) SpecOpts { } // WithCPUShares sets the container's cpu shares -// -//nolint:unused func WithCPUShares(shares uint64) SpecOpts { return func(ctx context.Context, _ Client, c *containers.Container, s *Spec) error { return nil diff --git a/oci/utils_unix.go b/oci/utils_unix.go index 921e882b2fcab..798680ab9f7bf 100644 --- a/oci/utils_unix.go +++ b/oci/utils_unix.go @@ -127,7 +127,7 @@ func getDevices(path, containerPath string) ([]specs.LinuxDevice, error) { // TODO consider adding these consts to the OCI runtime-spec. const ( - wildcardDevice = "a" //nolint:deadcode,unused,varcheck // currently unused, but should be included when upstreaming to OCI runtime-spec. + wildcardDevice = "a" //nolint:deadcode,nolintlint,unused,varcheck // currently unused, but should be included when upstreaming to OCI runtime-spec. blockDevice = "b" charDevice = "c" // or "u" fifoDevice = "p" @@ -148,7 +148,7 @@ func DeviceFromPath(path string) (*specs.LinuxDevice, error) { } var ( - devNumber = uint64(stat.Rdev) //nolint:unconvert // the type is 32bit on mips. + devNumber = uint64(stat.Rdev) //nolint:nolintlint,unconvert // the type is 32bit on mips. major = unix.Major(devNumber) minor = unix.Minor(devNumber) ) diff --git a/pkg/cri/sbserver/container_stats.go b/pkg/cri/sbserver/container_stats.go index a41e4da4f9e3c..cf870c77c8b72 100644 --- a/pkg/cri/sbserver/container_stats.go +++ b/pkg/cri/sbserver/container_stats.go @@ -41,7 +41,7 @@ func (c *criService) ContainerStats(ctx context.Context, in *runtime.ContainerSt } cs, err := c.containerMetrics(cntr.Metadata, resp.Metrics[0]) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (stats unimplemented) + if err != nil { return nil, fmt.Errorf("failed to decode container metrics: %w", err) } return &runtime.ContainerStatsResponse{Stats: cs}, nil diff --git a/pkg/cri/sbserver/container_stats_list.go b/pkg/cri/sbserver/container_stats_list.go index aae5f849a878c..ec482340f5963 100644 --- a/pkg/cri/sbserver/container_stats_list.go +++ b/pkg/cri/sbserver/container_stats_list.go @@ -58,7 +58,7 @@ func (c *criService) toCRIContainerStats( containerStats := new(runtime.ListContainerStatsResponse) for _, cntr := range containers { cs, err := c.containerMetrics(cntr.Metadata, statsMap[cntr.ID]) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (metrics unimplemented) + if err != nil { return nil, fmt.Errorf("failed to decode container metrics for %q: %w", cntr.ID, err) } containerStats.Stats = append(containerStats.Stats, cs) diff --git a/pkg/cri/sbserver/sandbox_stats.go b/pkg/cri/sbserver/sandbox_stats.go index 3e805e09f114a..bf59846d11da3 100644 --- a/pkg/cri/sbserver/sandbox_stats.go +++ b/pkg/cri/sbserver/sandbox_stats.go @@ -34,12 +34,12 @@ func (c *criService) PodSandboxStats( } metrics, err := metricsForSandbox(sandbox) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (unimplemented metrics) + if err != nil { return nil, fmt.Errorf("failed getting metrics for sandbox %s: %w", r.GetPodSandboxId(), err) } podSandboxStats, err := c.podSandboxStats(ctx, sandbox, metrics) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (unimplemented metrics) + if err != nil { return nil, fmt.Errorf("failed to decode pod sandbox metrics %s: %w", r.GetPodSandboxId(), err) } diff --git a/pkg/cri/sbserver/sandbox_stats_list.go b/pkg/cri/sbserver/sandbox_stats_list.go index 69d4336a3da28..3cff21b65f407 100644 --- a/pkg/cri/sbserver/sandbox_stats_list.go +++ b/pkg/cri/sbserver/sandbox_stats_list.go @@ -34,12 +34,12 @@ func (c *criService) ListPodSandboxStats( podSandboxStats := new(runtime.ListPodSandboxStatsResponse) for _, sandbox := range sandboxes { metrics, err := metricsForSandbox(sandbox) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (unimplemented metrics) + if err != nil { return nil, fmt.Errorf("failed to obtain metrics for sandbox %q: %w", sandbox.ID, err) } sandboxStats, err := c.podSandboxStats(ctx, sandbox, metrics) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (unimplemented metrics) + if err != nil { return nil, fmt.Errorf("failed to decode sandbox container metrics for sandbox %q: %w", sandbox.ID, err) } podSandboxStats.Stats = append(podSandboxStats.Stats, sandboxStats) diff --git a/pkg/cri/sbserver/service.go b/pkg/cri/sbserver/service.go index 1d5b5d2794143..9479d4e9fe7a0 100644 --- a/pkg/cri/sbserver/service.go +++ b/pkg/cri/sbserver/service.go @@ -117,7 +117,7 @@ type criService struct { baseOCISpecs map[string]*oci.Spec // allCaps is the list of the capabilities. // When nil, parsed from CapEff of /proc/self/status. - allCaps []string //nolint:unused // Ignore on non-Linux + allCaps []string //nolint:nolintlint,unused // Ignore on non-Linux // unpackDuplicationSuppressor is used to make sure that there is only // one in-flight fetch request or unpack handler for a given descriptor's // or chain ID. diff --git a/pkg/cri/server/container_stats.go b/pkg/cri/server/container_stats.go index db62c342b4805..0ca66eef393b2 100644 --- a/pkg/cri/server/container_stats.go +++ b/pkg/cri/server/container_stats.go @@ -41,7 +41,7 @@ func (c *criService) ContainerStats(ctx context.Context, in *runtime.ContainerSt } cs, err := c.containerMetrics(cntr.Metadata, resp.Metrics[0]) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (stats unimplemented) + if err != nil { return nil, fmt.Errorf("failed to decode container metrics: %w", err) } return &runtime.ContainerStatsResponse{Stats: cs}, nil diff --git a/pkg/cri/server/container_stats_list.go b/pkg/cri/server/container_stats_list.go index 9459b64b19395..cb61eecb3bd4a 100644 --- a/pkg/cri/server/container_stats_list.go +++ b/pkg/cri/server/container_stats_list.go @@ -61,7 +61,7 @@ func (c *criService) toCRIContainerStats( containerStats := new(runtime.ListContainerStatsResponse) for _, cntr := range containers { cs, err := c.containerMetrics(cntr.Metadata, statsMap[cntr.ID]) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (metrics unimplemented) + if err != nil { return nil, fmt.Errorf("failed to decode container metrics for %q: %w", cntr.ID, err) } diff --git a/pkg/cri/server/sandbox_stats.go b/pkg/cri/server/sandbox_stats.go index b74dd0ff5ff9b..feb19120c7917 100644 --- a/pkg/cri/server/sandbox_stats.go +++ b/pkg/cri/server/sandbox_stats.go @@ -34,12 +34,12 @@ func (c *criService) PodSandboxStats( } metrics, err := metricsForSandbox(sandbox) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (unimplemented metrics) + if err != nil { return nil, fmt.Errorf("failed getting metrics for sandbox %s: %w", r.GetPodSandboxId(), err) } podSandboxStats, err := c.podSandboxStats(ctx, sandbox, metrics) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (unimplemented metrics) + if err != nil { return nil, fmt.Errorf("failed to decode pod sandbox metrics %s: %w", r.GetPodSandboxId(), err) } diff --git a/pkg/cri/server/sandbox_stats_list.go b/pkg/cri/server/sandbox_stats_list.go index 1cd4f2db89573..c989bbfa9b0e6 100644 --- a/pkg/cri/server/sandbox_stats_list.go +++ b/pkg/cri/server/sandbox_stats_list.go @@ -34,12 +34,12 @@ func (c *criService) ListPodSandboxStats( podSandboxStats := new(runtime.ListPodSandboxStatsResponse) for _, sandbox := range sandboxes { metrics, err := metricsForSandbox(sandbox) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (unimplemented metrics) + if err != nil { return nil, fmt.Errorf("failed to obtain metrics for sandbox %q: %w", sandbox.ID, err) } sandboxStats, err := c.podSandboxStats(ctx, sandbox, metrics) - if err != nil { //nolint:staticcheck // Ignore SA4023 as some platforms always return nil (unimplemented metrics) + if err != nil { return nil, fmt.Errorf("failed to decode sandbox container metrics for sandbox %q: %w", sandbox.ID, err) } podSandboxStats.Stats = append(podSandboxStats.Stats, sandboxStats) diff --git a/pkg/cri/server/service.go b/pkg/cri/server/service.go index 0e411fa442f55..04ec294d361c5 100644 --- a/pkg/cri/server/service.go +++ b/pkg/cri/server/service.go @@ -113,7 +113,7 @@ type criService struct { baseOCISpecs map[string]*oci.Spec // allCaps is the list of the capabilities. // When nil, parsed from CapEff of /proc/self/status. - allCaps []string //nolint:unused // Ignore on non-Linux + allCaps []string //nolint:nolintlint,unused // Ignore on non-Linux // unpackDuplicationSuppressor is used to make sure that there is only // one in-flight fetch request or unpack handler for a given descriptor's // or chain ID. diff --git a/pkg/cri/store/container/metadata.go b/pkg/cri/store/container/metadata.go index f21914a2080e3..698e495aecfca 100644 --- a/pkg/cri/store/container/metadata.go +++ b/pkg/cri/store/container/metadata.go @@ -28,10 +28,9 @@ import ( // 2) Metadata is checkpointed as containerd container label. // metadataVersion is current version of container metadata. -const metadataVersion = "v1" // nolint +const metadataVersion = "v1" // versionedMetadata is the internal versioned container metadata. -// nolint type versionedMetadata struct { // Version indicates the version of the versioned container metadata. Version string diff --git a/pkg/cri/store/container/status.go b/pkg/cri/store/container/status.go index 1cf9a204e03a3..b50dc5c542c71 100644 --- a/pkg/cri/store/container/status.go +++ b/pkg/cri/store/container/status.go @@ -61,10 +61,9 @@ import ( // DELETED // statusVersion is current version of container status. -const statusVersion = "v1" // nolint +const statusVersion = "v1" // versionedStatus is the internal used versioned container status. -// nolint type versionedStatus struct { // Version indicates the version of the versioned container status. Version string diff --git a/pkg/cri/store/sandbox/metadata.go b/pkg/cri/store/sandbox/metadata.go index 80e39c68c2a32..20fe2f1d18fc0 100644 --- a/pkg/cri/store/sandbox/metadata.go +++ b/pkg/cri/store/sandbox/metadata.go @@ -29,10 +29,9 @@ import ( // 2) Metadata is checkpointed as containerd container label. // metadataVersion is current version of sandbox metadata. -const metadataVersion = "v1" // nolint +const metadataVersion = "v1" // versionedMetadata is the internal versioned sandbox metadata. -// nolint type versionedMetadata struct { // Version indicates the version of the versioned sandbox metadata. Version string diff --git a/pkg/progress/escape.go b/pkg/progress/escape.go index e648fdda35e62..6455c305ea999 100644 --- a/pkg/progress/escape.go +++ b/pkg/progress/escape.go @@ -19,6 +19,6 @@ package progress const ( escape = "\x1b" reset = escape + "[0m" - red = escape + "[31m" //nolint:deadcode,unused,varcheck + red = escape + "[31m" //nolint:deadcode,nolintlint,unused,varcheck green = escape + "[32m" )