Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v3
with:
version: v1.48.0
version: v1.49.0
skip-cache: true
args: --timeout=8m

Expand Down
17 changes: 8 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
linters:
enable:
- structcheck
- varcheck
- staticcheck
- unconvert
- exportloopref # Checks for pointers to enclosing loop variables
- gofmt
- goimports
- revive
- gosec
- ineffassign
- vet
- unused
- misspell
- gosec
- exportloopref # Checks for pointers to enclosing loop variables
- nolintlint
- revive
- staticcheck
- tenv # Detects using os.Setenv instead of t.Setenv since Go 1.17
- unconvert
- unused
- vet
disable:
- errcheck

Expand Down
3 changes: 1 addition & 2 deletions archive/tar_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func setHeaderForSpecialDevice(hdr *tar.Header, name string, fi os.FileInfo) err
return errors.New("unsupported stat type")
}

// Rdev is int32 on darwin/bsd, int64 on linux/solaris
rdev := uint64(s.Rdev) // nolint: unconvert
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 ||
Expand Down
7 changes: 6 additions & 1 deletion cmd/containerd-stress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ func (c config) newClient() (*containerd.Client, error) {

func serve(c config) error {
go func() {
if err := http.ListenAndServe(c.Metrics, metrics.Handler()); err != nil {
srv := &http.Server{
Addr: c.Metrics,
Handler: metrics.Handler(),
ReadHeaderTimeout: 5 * time.Minute, // "G112: Potential Slowloris Attack (gosec)"; not a real concern for our use, so setting a long timeout.
}
if err := srv.ListenAndServe(); err != nil {
Comment on lines +238 to +243
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking similar approach as I dd in moby/moby#44174 (we discussed this warning there, and considered that it was not an actual problem for how it's used, but setting a timeout doesn't hurt either, and somewhat better than "just add some //nolint comments")

logrus.WithError(err).Error("listen and serve")
}
}()
Expand Down
2 changes: 1 addition & 1 deletion contrib/fuzz/content_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

// nolint: golint
//nolint:golint
package fuzz

import (
Expand Down
3 changes: 1 addition & 2 deletions integration/client/restart_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ import (
exec "golang.org/x/sys/execabs"
)

// the following nolint is for shutting up gometalinter on non-linux.
// nolint: unused
//nolint:unused // Ignore on non-Linux
func newDaemonWithConfig(t *testing.T, configTOML string) (*Client, *daemon, func()) {
if testing.Short() {
t.Skip()
Expand Down
16 changes: 8 additions & 8 deletions integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand All @@ -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{}
Expand All @@ -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{}
Expand All @@ -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{}
Expand All @@ -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{}
Expand Down Expand Up @@ -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{}
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions oci/spec_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func setLinux(s *Spec) {
}
}

// nolint
func setResources(s *Spec) {
if s.Linux != nil {
if s.Linux.Resources == nil {
Expand All @@ -85,7 +84,7 @@ func setResources(s *Spec) {
}
}

// nolint
//nolint:nolintlint,unused // not used on all platforms
func setResourcesWindows(s *Spec) {
if s.Windows != nil {
if s.Windows.Resources == nil {
Expand All @@ -94,7 +93,7 @@ func setResourcesWindows(s *Spec) {
}
}

// nolint
//nolint:nolintlint,unused // not used on all platforms
func setCPU(s *Spec) {
setResources(s)
if s.Linux != nil {
Expand All @@ -104,7 +103,7 @@ func setCPU(s *Spec) {
}
}

// nolint
//nolint:nolintlint,unused // not used on all platforms
func setCPUWindows(s *Spec) {
setResourcesWindows(s)
if s.Windows != nil {
Expand Down
6 changes: 3 additions & 3 deletions oci/spec_opts_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"golang.org/x/sys/unix"
)

// nolint:gosec
//nolint:gosec
func TestWithUserID(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -86,7 +86,7 @@ guest:x:405:100:guest:/dev/null:/sbin/nologin
}
}

// nolint:gosec
//nolint:gosec
func TestWithUsername(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -148,7 +148,7 @@ guest:x:405:100:guest:/dev/null:/sbin/nologin

}

// nolint:gosec
//nolint:gosec
func TestWithAdditionalGIDs(t *testing.T) {
t.Parallel()
expectedPasswd := `root:x:0:0:root:/root:/bin/ash
Expand Down
4 changes: 0 additions & 4 deletions oci/spec_opts_nonlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,23 @@ 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: deadcode, 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: deadcode, 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: deadcode, unused
func WithBlockIO(blockio interface{}) SpecOpts {
return func(ctx context.Context, _ Client, c *containers.Container, s *Spec) error {
return errors.New("blkio not supported")
}
}

// WithCPUShares sets the container's cpu shares
// nolint: deadcode, unused
func WithCPUShares(shares uint64) SpecOpts {
return func(ctx context.Context, _ Client, c *containers.Container, s *Spec) error {
return nil
Expand Down
4 changes: 2 additions & 2 deletions oci/utils_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 // currently unused, but should be included when upstreaming to OCI runtime-spec.
wildcardDevice = "a" //nolint:nolintlint,unused,varcheck // currently unused, but should be included when upstreaming to OCI runtime-spec.
blockDevice = "b"
charDevice = "c" // or "u"
fifoDevice = "p"
Expand All @@ -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)
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/opts/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func WithVolumes(volumeMounts map[string]string) containerd.NewContainerOpts {
// if it fails but not RM snapshot data.
// refer to https://github.com/containerd/containerd/pull/1868
// https://github.com/containerd/containerd/pull/1785
defer os.Remove(root) // nolint: errcheck
defer os.Remove(root)

unmounter := func(mountPath string) {
if uerr := mount.Unmount(mountPath, 0); uerr != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/sbserver/container_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/sbserver/container_stats_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/sbserver/image_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (c *criService) getTLSConfig(registryTLSConfig criconfig.TLSConfig) (*tls.C
if len(cert.Certificate) != 0 {
tlsConfig.Certificates = []tls.Certificate{cert}
}
tlsConfig.BuildNameToCertificate() // nolint:staticcheck
tlsConfig.BuildNameToCertificate() //nolint:staticcheck // TODO(thaJeztah): verify if we should ignore the deprecation; see https://github.com/containerd/containerd/pull/7349/files#r990644833
}

if registryTLSConfig.CAFile != "" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cri/sbserver/sandbox_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cri/sbserver/sandbox_stats_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/sbserver/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/server/container_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/server/container_stats_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/server/image_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (c *criService) getTLSConfig(registryTLSConfig criconfig.TLSConfig) (*tls.C
if len(cert.Certificate) != 0 {
tlsConfig.Certificates = []tls.Certificate{cert}
}
tlsConfig.BuildNameToCertificate() // nolint:staticcheck
tlsConfig.BuildNameToCertificate() //nolint:staticcheck // TODO(thaJeztah): verify if we should ignore the deprecation; see https://github.com/containerd/containerd/pull/7349/files#r990644833
}

if registryTLSConfig.CAFile != "" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cri/server/sandbox_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cri/server/sandbox_stats_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading