diff --git a/cmd/containerd-stress/cri_worker.go b/cmd/containerd-stress/cri_worker.go index 6aa7ee824..64fb6814e 100644 --- a/cmd/containerd-stress/cri_worker.go +++ b/cmd/containerd-stress/cri_worker.go @@ -158,8 +158,13 @@ func criCleanup(ctx context.Context, client internalapi.RuntimeService) error { } for _, sb := range sandboxes { - client.StopPodSandbox(sb.Id) - client.RemovePodSandbox(sb.Id) + if err := client.StopPodSandbox(sb.Id); err != nil { + return err + } + + if err := client.RemovePodSandbox(sb.Id); err != nil { + return err + } } return nil diff --git a/cmd/containerd-stress/rlimit_freebsd.go b/cmd/containerd-stress/rlimit_freebsd.go index 92b299a37..85c574380 100644 --- a/cmd/containerd-stress/rlimit_freebsd.go +++ b/cmd/containerd-stress/rlimit_freebsd.go @@ -22,17 +22,15 @@ import ( func setRlimit() error { rlimit := int64(100000) - if rlimit > 0 { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit syscall.Rlimit + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + return err + } + if limit.Cur < rlimit { + limit.Cur = rlimit + if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { return err } - if limit.Cur < rlimit { - limit.Cur = rlimit - if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { - return err - } - } } return nil } diff --git a/cmd/containerd-stress/rlimit_unix.go b/cmd/containerd-stress/rlimit_unix.go index 7c53f2adf..681a92e7e 100644 --- a/cmd/containerd-stress/rlimit_unix.go +++ b/cmd/containerd-stress/rlimit_unix.go @@ -24,19 +24,17 @@ import ( func setRlimit() error { rlimit := uint64(100000) - if rlimit > 0 { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { - return err + var limit syscall.Rlimit + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + return err + } + if limit.Cur < rlimit { + limit.Cur = rlimit + if limit.Max < limit.Cur { + limit.Max = limit.Cur } - if limit.Cur < rlimit { - limit.Cur = rlimit - if limit.Max < limit.Cur { - limit.Max = limit.Cur - } - if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { - return err - } + if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + return err } } return nil diff --git a/cmd/containerd-stress/size.go b/cmd/containerd-stress/size.go index 46fba62c5..abc54e575 100644 --- a/cmd/containerd-stress/size.go +++ b/cmd/containerd-stress/size.go @@ -18,27 +18,34 @@ package main import ( "os" - "path/filepath" "github.com/sirupsen/logrus" ) +const defaultPath = "/usr/local/bin/" + var binaries = []string{ - "ctr", - "containerd", - "containerd-shim", - "containerd-shim-runc-v1", - "containerd-shim-runc-v2", + defaultPath + "ctr", + defaultPath + "containerd", + defaultPath + "containerd-shim", + defaultPath + "containerd-shim-runc-v1", + defaultPath + "containerd-shim-runc-v2", } // checkBinarySizes checks and reports the binary sizes for the containerd compiled binaries to prometheus func checkBinarySizes() { for _, name := range binaries { - fi, err := os.Stat(filepath.Join("/usr/local/bin", name)) + fi, err := os.Stat(name) if err != nil { logrus.WithError(err).Error("stat binary") continue } + + if fi.IsDir() { + logrus.Error(name, "is not a file") + continue + } + binarySizeGauge.WithValues(name).Set(float64(fi.Size())) } }