diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b863a1d..54cec25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: - go-version: [1.17.x] + go-version: [1.21.x] steps: - uses: actions/setup-go@v2 @@ -60,7 +60,7 @@ jobs: - name: golangci-lint check uses: golangci/golangci-lint-action@v3 with: - version: v1.44.2 + version: v1.55.2 args: --timeout=5m working-directory: src/github.com/fuweid/embedshim @@ -70,7 +70,7 @@ jobs: # based on https://github.com/containerd/project-checks/blob/main/action.yml project: name: Project Checks - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 timeout-minutes: 5 steps: @@ -128,7 +128,7 @@ jobs: # ubuntu-22.04 is used to test cgroupv2 # ubuntu-20.04 is for cgroupv1 (common) matrix: - go-version: [1.17.x] + go-version: [1.21.x] os: [ubuntu-20.04, ubuntu-22.04] runs-on: ${{ matrix.os }} diff --git a/.golangci.yml b/.golangci.yml index 1aa4194..aa6f243 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,8 +19,6 @@ # linters: enable: - - structcheck - - varcheck - staticcheck - unconvert - gofmt diff --git a/cmd/embedshim-runcext/app.go b/cmd/embedshim-runcext/app.go index 0b5d91c..b7c9811 100644 --- a/cmd/embedshim-runcext/app.go +++ b/cmd/embedshim-runcext/app.go @@ -52,10 +52,7 @@ func newApp() *cli.App { } app.Commands = append(app.Commands, execCommand) app.Before = func(_ *cli.Context) error { - if err := reaper.SetSubreaper(1); err != nil { - return err - } - return nil + return reaper.SetSubreaper(1) } return app } diff --git a/delete_state.go b/delete_state.go index a477f43..21a6602 100644 --- a/delete_state.go +++ b/delete_state.go @@ -29,46 +29,46 @@ import ( type deletedState struct { } -func (s *deletedState) Pause(ctx context.Context) error { +func (s *deletedState) Pause(_ context.Context) error { return fmt.Errorf("cannot pause a deleted process") } -func (s *deletedState) Resume(ctx context.Context) error { +func (s *deletedState) Resume(_ context.Context) error { return fmt.Errorf("cannot resume a deleted process") } -func (s *deletedState) Update(context context.Context, r *google_protobuf.Any) error { +func (s *deletedState) Update(_ context.Context, _ *google_protobuf.Any) error { return fmt.Errorf("cannot update a deleted process") } -func (s *deletedState) Checkpoint(ctx context.Context, r *CheckpointConfig) error { +func (s *deletedState) Checkpoint(_ context.Context, _ *CheckpointConfig) error { return fmt.Errorf("cannot checkpoint a deleted process") } -func (s *deletedState) Resize(ws console.WinSize) error { +func (s *deletedState) Resize(_ console.WinSize) error { return fmt.Errorf("cannot resize a deleted process") } -func (s *deletedState) Start(ctx context.Context) error { +func (s *deletedState) Start(_ context.Context) error { return fmt.Errorf("cannot start a deleted process") } -func (s *deletedState) Delete(ctx context.Context) error { +func (s *deletedState) Delete(_ context.Context) error { return fmt.Errorf("cannot delete a deleted process: %w", errdefs.ErrNotFound) } -func (s *deletedState) Kill(ctx context.Context, sig uint32, all bool) error { +func (s *deletedState) Kill(_ context.Context, _ uint32, _ bool) error { return fmt.Errorf("cannot kill a deleted process: %w", errdefs.ErrNotFound) } -func (s *deletedState) SetExited(status int) { +func (s *deletedState) SetExited(_ int) { // no op } -func (s *deletedState) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.Process, error) { +func (s *deletedState) Exec(_ context.Context, _ string, _ runtime.ExecOpts) (runtime.Process, error) { return nil, fmt.Errorf("cannot exec in a deleted state") } -func (s *deletedState) Status(ctx context.Context) (string, error) { +func (s *deletedState) Status(_ context.Context) (string, error) { return "stopped", nil } diff --git a/exec_process.go b/exec_process.go index a654e41..1859f7d 100644 --- a/exec_process.go +++ b/exec_process.go @@ -108,7 +108,7 @@ func (e *execProcess) setExited(status int) { close(e.waitBlock) } -func (e *execProcess) CloseIO(ctx context.Context) error { +func (e *execProcess) CloseIO(_ context.Context) error { if stdin := e.Stdin(); stdin != nil { if err := stdin.Close(); err != nil { return err @@ -214,7 +214,7 @@ func (e *execProcess) Kill(ctx context.Context, sig uint32, _ bool) error { return e.execState.Kill(ctx, sig, false) } -func (e *execProcess) kill(ctx context.Context, sig uint32, _ bool) error { +func (e *execProcess) kill(_ context.Context, sig uint32, _ bool) error { pid := e.pid.get() switch { case pid == 0: diff --git a/exec_process_state.go b/exec_process_state.go index d13c26e..c9602bc 100644 --- a/exec_process_state.go +++ b/exec_process_state.go @@ -82,7 +82,7 @@ func (s *execCreatedState) SetExited(status int) { } } -func (s *execCreatedState) Status(ctx context.Context) (string, error) { +func (s *execCreatedState) Status(_ context.Context) (string, error) { return "created", nil } @@ -104,11 +104,11 @@ func (s *execRunningState) Resize(ws console.WinSize) error { return s.p.resize(ws) } -func (s *execRunningState) Start(ctx context.Context) error { +func (s *execRunningState) Start(_ context.Context) error { return fmt.Errorf("cannot start a running process") } -func (s *execRunningState) Delete(ctx context.Context) error { +func (s *execRunningState) Delete(_ context.Context) error { return fmt.Errorf("cannot delete a running process") } @@ -124,7 +124,7 @@ func (s *execRunningState) SetExited(status int) { } } -func (s *execRunningState) Status(ctx context.Context) (string, error) { +func (s *execRunningState) Status(_ context.Context) (string, error) { return "running", nil } @@ -142,11 +142,11 @@ func (s *execStoppedState) transition(name string) error { return nil } -func (s *execStoppedState) Resize(ws console.WinSize) error { +func (s *execStoppedState) Resize(_ console.WinSize) error { return fmt.Errorf("cannot resize a stopped container") } -func (s *execStoppedState) Start(ctx context.Context) error { +func (s *execStoppedState) Start(_ context.Context) error { return fmt.Errorf("cannot start a stopped process") } @@ -162,10 +162,10 @@ func (s *execStoppedState) Kill(ctx context.Context, sig uint32, all bool) error return s.p.kill(ctx, sig, all) } -func (s *execStoppedState) SetExited(status int) { +func (s *execStoppedState) SetExited(_ int) { // no op } -func (s *execStoppedState) Status(ctx context.Context) (string, error) { +func (s *execStoppedState) Status(_ context.Context) (string, error) { return "stopped", nil } diff --git a/init_process.go b/init_process.go index 3bbed80..04b02e1 100644 --- a/init_process.go +++ b/init_process.go @@ -437,7 +437,7 @@ func (p *initProcess) exec(ctx context.Context, execID string, opts runtime.Exec } // Checkpoint the init process -func (p *initProcess) Checkpoint(ctx context.Context, r *CheckpointConfig) error { +func (p *initProcess) Checkpoint(_ context.Context, _ *CheckpointConfig) error { return fmt.Errorf("checkpoint not implemented yet") } diff --git a/init_process_state.go b/init_process_state.go index 57820df..dd0aaee 100644 --- a/init_process_state.go +++ b/init_process_state.go @@ -69,11 +69,11 @@ func (s *createdState) transition(name string) error { return nil } -func (s *createdState) Pause(ctx context.Context) error { +func (s *createdState) Pause(_ context.Context) error { return fmt.Errorf("cannot pause task in created state") } -func (s *createdState) Resume(ctx context.Context) error { +func (s *createdState) Resume(_ context.Context) error { return fmt.Errorf("cannot resume task in created state") } @@ -81,7 +81,7 @@ func (s *createdState) Update(ctx context.Context, r *google_protobuf.Any) error return s.p.update(ctx, r) } -func (s *createdState) Checkpoint(ctx context.Context, r *CheckpointConfig) error { +func (s *createdState) Checkpoint(_ context.Context, _ *CheckpointConfig) error { return fmt.Errorf("cannot checkpoint a task in created state") } @@ -115,7 +115,7 @@ func (s *createdState) Exec(ctx context.Context, id string, opts runtime.ExecOpt return s.p.exec(ctx, id, opts) } -func (s *createdState) Status(ctx context.Context) (string, error) { +func (s *createdState) Status(_ context.Context) (string, error) { return "created", nil } @@ -135,11 +135,11 @@ func (s *runningState) transition(name string) error { return nil } -func (s *runningState) Pause(ctx context.Context) error { +func (s *runningState) Pause(_ context.Context) error { return fmt.Errorf("pause not implemented yet") } -func (s *runningState) Resume(ctx context.Context) error { +func (s *runningState) Resume(_ context.Context) error { return fmt.Errorf("cannot resume a running process") } @@ -147,15 +147,15 @@ func (s *runningState) Update(ctx context.Context, r *google_protobuf.Any) error return s.p.update(ctx, r) } -func (s *runningState) Checkpoint(ctx context.Context, r *CheckpointConfig) error { +func (s *runningState) Checkpoint(_ context.Context, _ *CheckpointConfig) error { return fmt.Errorf("checkpoint not implemented yet") } -func (s *runningState) Start(ctx context.Context) error { +func (s *runningState) Start(_ context.Context) error { return fmt.Errorf("cannot start a running process") } -func (s *runningState) Delete(ctx context.Context) error { +func (s *runningState) Delete(_ context.Context) error { return fmt.Errorf("cannot delete a running process") } @@ -175,7 +175,7 @@ func (s *runningState) Exec(ctx context.Context, id string, opts runtime.ExecOpt return s.p.exec(ctx, id, opts) } -func (s *runningState) Status(ctx context.Context) (string, error) { +func (s *runningState) Status(_ context.Context) (string, error) { return "running", nil } @@ -195,11 +195,11 @@ func (s *pausedState) transition(name string) error { return nil } -func (s *pausedState) Pause(ctx context.Context) error { +func (s *pausedState) Pause(_ context.Context) error { return fmt.Errorf("cannot pause a paused container") } -func (s *pausedState) Resume(ctx context.Context) error { +func (s *pausedState) Resume(_ context.Context) error { return fmt.Errorf("resume not implemented yet") } @@ -207,15 +207,15 @@ func (s *pausedState) Update(ctx context.Context, r *google_protobuf.Any) error return s.p.update(ctx, r) } -func (s *pausedState) Checkpoint(ctx context.Context, r *CheckpointConfig) error { +func (s *pausedState) Checkpoint(_ context.Context, _ *CheckpointConfig) error { return fmt.Errorf("checkpoint not implemented yet") } -func (s *pausedState) Start(ctx context.Context) error { +func (s *pausedState) Start(_ context.Context) error { return fmt.Errorf("cannot start a paused process") } -func (s *pausedState) Delete(ctx context.Context) error { +func (s *pausedState) Delete(_ context.Context) error { return fmt.Errorf("cannot delete a paused process") } @@ -235,11 +235,11 @@ func (s *pausedState) SetExited(status int) { } } -func (s *pausedState) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.Process, error) { +func (s *pausedState) Exec(_ context.Context, _ string, _ runtime.ExecOpts) (runtime.Process, error) { return nil, fmt.Errorf("cannot exec in a paused state") } -func (s *pausedState) Status(ctx context.Context) (string, error) { +func (s *pausedState) Status(_ context.Context) (string, error) { return "paused", nil } @@ -257,23 +257,23 @@ func (s *stoppedState) transition(name string) error { return nil } -func (s *stoppedState) Pause(ctx context.Context) error { +func (s *stoppedState) Pause(_ context.Context) error { return fmt.Errorf("cannot pause a stopped container") } -func (s *stoppedState) Resume(ctx context.Context) error { +func (s *stoppedState) Resume(_ context.Context) error { return fmt.Errorf("cannot resume a stopped container") } -func (s *stoppedState) Update(ctx context.Context, r *google_protobuf.Any) error { +func (s *stoppedState) Update(_ context.Context, _ *google_protobuf.Any) error { return fmt.Errorf("cannot update a stopped container") } -func (s *stoppedState) Checkpoint(ctx context.Context, r *CheckpointConfig) error { +func (s *stoppedState) Checkpoint(_ context.Context, _ *CheckpointConfig) error { return fmt.Errorf("cannot checkpoint a stopped container") } -func (s *stoppedState) Start(ctx context.Context) error { +func (s *stoppedState) Start(_ context.Context) error { return fmt.Errorf("cannot start a stopped process") } @@ -288,15 +288,15 @@ func (s *stoppedState) Kill(ctx context.Context, sig uint32, all bool) error { return s.p.kill(ctx, sig, all) } -func (s *stoppedState) SetExited(status int) { +func (s *stoppedState) SetExited(_ int) { // no op } -func (s *stoppedState) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.Process, error) { +func (s *stoppedState) Exec(_ context.Context, _ string, _ runtime.ExecOpts) (runtime.Process, error) { return nil, fmt.Errorf("cannot exec in a stopped state") } -func (s *stoppedState) Status(ctx context.Context) (string, error) { +func (s *stoppedState) Status(_ context.Context) (string, error) { return "stopped", nil } diff --git a/io.go b/io.go index f6b6b50..c795480 100644 --- a/io.go +++ b/io.go @@ -176,7 +176,7 @@ func (p *processIO) CopyStdin() error { return nil } -func createIO(ctx context.Context, id string, ioUID, ioGID int, stdio stdio.Stdio) (*processIO, error) { +func createIO(_ context.Context, _ string, ioUID, ioGID int, stdio stdio.Stdio) (*processIO, error) { pio := &processIO{ stdio: stdio, } @@ -289,7 +289,7 @@ func withConditionalIO(c stdio.Stdio) runc.IOOpt { } } -func openRWFifo(ctx context.Context, fn string, perm os.FileMode) (*os.File, error) { +func openRWFifo(_ context.Context, fn string, perm os.FileMode) (*os.File, error) { if _, err := os.Stat(fn); err != nil { if os.IsNotExist(err) { if err := syscall.Mkfifo(fn, uint32(perm&os.ModePerm)); err != nil && !os.IsExist(err) { diff --git a/platform.go b/platform.go index 28020da..8990d15 100644 --- a/platform.go +++ b/platform.go @@ -45,7 +45,7 @@ type linuxPlatform struct { epoller *console.Epoller } -func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console, id, stdin, stdout, stderr string, wg *sync.WaitGroup) (cons console.Console, retErr error) { +func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console, _, stdin, stdout, _ string, wg *sync.WaitGroup) (cons console.Console, retErr error) { if p.epoller == nil { return nil, fmt.Errorf("uninitialized epoller") } @@ -95,7 +95,7 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console return epollConsole, nil } -func (p *linuxPlatform) ShutdownConsole(ctx context.Context, cons console.Console) error { +func (p *linuxPlatform) ShutdownConsole(_ context.Context, cons console.Console) error { if p.epoller == nil { return fmt.Errorf("uninitialized epoller") } diff --git a/reload.go b/reload.go index 84cc660..261a56d 100644 --- a/reload.go +++ b/reload.go @@ -88,7 +88,7 @@ func (manager *TaskManager) loadTasks(ctx context.Context) error { return nil } -func (manager *TaskManager) loadShim(ctx context.Context, bundle *pkgbundle.Bundle) (_ *shim, retErr error) { +func (manager *TaskManager) loadShim(_ context.Context, bundle *pkgbundle.Bundle) (_ *shim, retErr error) { init, err := renewInitProcess(bundle) if err != nil { return nil, err diff --git a/shim.go b/shim.go index f6898db..cb0a366 100644 --- a/shim.go +++ b/shim.go @@ -135,11 +135,11 @@ func (s *shim) Namespace() string { return s.bundle.Namespace } -func (s *shim) Pause(ctx context.Context) error { +func (s *shim) Pause(_ context.Context) error { return fmt.Errorf("pause not implemented yet") } -func (s *shim) Resume(ctx context.Context) error { +func (s *shim) Resume(_ context.Context) error { return fmt.Errorf("resume not implemented yet") } @@ -173,20 +173,20 @@ func (s *shim) Exec(ctx context.Context, execID string, opts runtime.ExecOpts) ( return process, nil } -func (s *shim) Pids(ctx context.Context) ([]runtime.ProcessInfo, error) { +func (s *shim) Pids(_ context.Context) ([]runtime.ProcessInfo, error) { return []runtime.ProcessInfo{ {Pid: s.PID()}, }, nil } -func (s *shim) ResizePty(ctx context.Context, size runtime.ConsoleSize) error { +func (s *shim) ResizePty(_ context.Context, size runtime.ConsoleSize) error { return s.init.Resize(console.WinSize{ Width: uint16(size.Width), Height: uint16(size.Height), }) } -func (s *shim) CloseIO(ctx context.Context) error { +func (s *shim) CloseIO(_ context.Context) error { if stdin := s.init.Stdin(); stdin != nil { if err := stdin.Close(); err != nil { return err @@ -195,7 +195,7 @@ func (s *shim) CloseIO(ctx context.Context) error { return nil } -func (s *shim) Wait(ctx context.Context) (*runtime.Exit, error) { +func (s *shim) Wait(_ context.Context) (*runtime.Exit, error) { taskPid := s.PID() // TODO: use ctx @@ -208,7 +208,7 @@ func (s *shim) Wait(ctx context.Context) (*runtime.Exit, error) { }, nil } -func (s *shim) Checkpoint(ctx context.Context, path string, options *ptypes.Any) error { +func (s *shim) Checkpoint(_ context.Context, _ string, _ *ptypes.Any) error { return fmt.Errorf("checkpoint not implemented yet") } @@ -220,7 +220,7 @@ func (s *shim) Update(ctx context.Context, resources *ptypes.Any, _ map[string]s return s.init.Update(ctx, resources) } -func (s *shim) Stats(ctx context.Context) (*ptypes.Any, error) { +func (s *shim) Stats(_ context.Context) (*ptypes.Any, error) { cgx := s.cg if cgx == nil { return nil, fmt.Errorf("cgroup does not exist: %w", errdefs.ErrNotFound)