diff --git a/cmd/crio/main.go b/cmd/crio/main.go index 9820d0ab04b..2e1ecb2cfbe 100644 --- a/cmd/crio/main.go +++ b/cmd/crio/main.go @@ -262,7 +262,7 @@ func main() { notifySystem() go func() { - crioServer.StartExitMonitor() + crioServer.StartExitMonitor(ctx) }() hookSync := make(chan error, 2) if crioServer.ContainerServer.Hooks == nil { diff --git a/internal/lib/container_server.go b/internal/lib/container_server.go index 1058d5ac269..66e538a0d07 100644 --- a/internal/lib/container_server.go +++ b/internal/lib/container_server.go @@ -144,7 +144,7 @@ func New(ctx context.Context, configIface libconfig.Iface) (*ContainerServer, er } // LoadSandbox loads a sandbox from the disk into the sandbox store -func (c *ContainerServer) LoadSandbox(id string) (retErr error) { +func (c *ContainerServer) LoadSandbox(ctx context.Context, id string) (retErr error) { config, err := c.store.FromContainerDirectory(id, "config.json") if err != nil { return err @@ -298,13 +298,13 @@ func (c *ContainerServer) LoadSandbox(id string) (retErr error) { scontainer = oci.NewSpoofedContainer(cID, cname, labels, created, sandboxPath) } - if err := c.ContainerStateFromDisk(scontainer); err != nil { + if err := c.ContainerStateFromDisk(ctx, scontainer); err != nil { return fmt.Errorf("error reading sandbox state from disk %q: %v", scontainer.ID(), err) } // We write back the state because it is possible that crio did not have a chance to // read the exit file and persist exit code into the state on reboot. - if err := c.ContainerStateToDisk(scontainer); err != nil { + if err := c.ContainerStateToDisk(ctx, scontainer); err != nil { return fmt.Errorf("failed to write container %q state to disk: %v", scontainer.ID(), err) } @@ -376,7 +376,7 @@ func configNsPath(spec *rspec.Spec, nsType rspec.LinuxNamespaceType) (string, er var ErrIsNonCrioContainer = errors.New("non CRI-O container") // LoadContainer loads a container from the disk into the container store -func (c *ContainerServer) LoadContainer(id string) (retErr error) { +func (c *ContainerServer) LoadContainer(ctx context.Context, id string) (retErr error) { config, err := c.store.FromContainerDirectory(id, "config.json") if err != nil { return err @@ -464,13 +464,13 @@ func (c *ContainerServer) LoadContainer(id string) (retErr error) { spp := m.Annotations[annotations.SeccompProfilePath] ctr.SetSeccompProfilePath(spp) - if err := c.ContainerStateFromDisk(ctr); err != nil { + if err := c.ContainerStateFromDisk(ctx, ctr); err != nil { return fmt.Errorf("error reading container state from disk %q: %v", ctr.ID(), err) } // We write back the state because it is possible that crio did not have a chance to // read the exit file and persist exit code into the state on reboot. - if err := c.ContainerStateToDisk(ctr); err != nil { + if err := c.ContainerStateToDisk(ctx, ctr); err != nil { return fmt.Errorf("failed to write container state to disk %q: %v", ctr.ID(), err) } ctr.SetCreated() @@ -486,11 +486,11 @@ func isTrue(annotaton string) bool { // ContainerStateFromDisk retrieves information on the state of a running container // from the disk -func (c *ContainerServer) ContainerStateFromDisk(ctr *oci.Container) error { +func (c *ContainerServer) ContainerStateFromDisk(ctx context.Context, ctr *oci.Container) error { if err := ctr.FromDisk(); err != nil { return err } - if err := c.runtime.UpdateContainerStatus(ctr); err != nil { + if err := c.runtime.UpdateContainerStatus(ctx, ctr); err != nil { return err } @@ -499,8 +499,8 @@ func (c *ContainerServer) ContainerStateFromDisk(ctr *oci.Container) error { // ContainerStateToDisk writes the container's state information to a JSON file // on disk -func (c *ContainerServer) ContainerStateToDisk(ctr *oci.Container) error { - if err := c.Runtime().UpdateContainerStatus(ctr); err != nil { +func (c *ContainerServer) ContainerStateToDisk(ctx context.Context, ctr *oci.Container) error { + if err := c.Runtime().UpdateContainerStatus(ctx, ctr); err != nil { logrus.Warnf("error updating the container status %q: %v", ctr.ID(), err) } diff --git a/internal/lib/container_server_test.go b/internal/lib/container_server_test.go index dee98b2de8a..1b661cc046c 100644 --- a/internal/lib/container_server_test.go +++ b/internal/lib/container_server_test.go @@ -165,7 +165,7 @@ var _ = t.Describe("ContainerServer", func() { mockDirs(testManifest) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).To(BeNil()) @@ -181,7 +181,7 @@ var _ = t.Describe("ContainerServer", func() { mockDirs(manifest) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).To(BeNil()) @@ -197,7 +197,7 @@ var _ = t.Describe("ContainerServer", func() { mockDirs(manifest) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).To(BeNil()) @@ -208,7 +208,7 @@ var _ = t.Describe("ContainerServer", func() { mockDirs(testManifest) // When - err := sut.LoadSandbox("") + err := sut.LoadSandbox(context.Background(), "") // Then Expect(err).NotTo(BeNil()) @@ -223,7 +223,7 @@ var _ = t.Describe("ContainerServer", func() { mockDirs(manifest) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -238,7 +238,7 @@ var _ = t.Describe("ContainerServer", func() { mockDirs(manifest) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -257,7 +257,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -274,7 +274,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -293,7 +293,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -312,7 +312,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -331,7 +331,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -350,7 +350,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -369,7 +369,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -388,7 +388,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -403,7 +403,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadSandbox("id") + err := sut.LoadSandbox(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -418,7 +418,7 @@ var _ = t.Describe("ContainerServer", func() { mockDirs(testManifest) // When - err := sut.LoadContainer("id") + err := sut.LoadContainer(context.Background(), "id") // Then Expect(err).To(BeNil()) @@ -433,7 +433,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadContainer("id") + err := sut.LoadContainer(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -451,7 +451,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadContainer("id") + err := sut.LoadContainer(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -471,7 +471,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadContainer("id") + err := sut.LoadContainer(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -486,7 +486,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadContainer("id") + err := sut.LoadContainer(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -505,7 +505,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadContainer("id") + err := sut.LoadContainer(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -524,7 +524,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadContainer("id") + err := sut.LoadContainer(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -543,7 +543,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadContainer("id") + err := sut.LoadContainer(context.Background(), "id") // Then Expect(err).NotTo(BeNil()) @@ -563,7 +563,7 @@ var _ = t.Describe("ContainerServer", func() { ) // When - err := sut.LoadContainer("id") + err := sut.LoadContainer(context.Background(), "id") // Then Expect(err).To(Equal(lib.ErrIsNonCrioContainer)) @@ -574,7 +574,7 @@ var _ = t.Describe("ContainerServer", func() { It("should fail when file not found", func() { // Given // When - err := sut.ContainerStateFromDisk(myContainer) + err := sut.ContainerStateFromDisk(context.Background(), myContainer) // Then Expect(err).NotTo(BeNil()) @@ -592,7 +592,7 @@ var _ = t.Describe("ContainerServer", func() { Expect(err).To(BeNil()) // When - err = sut.ContainerStateToDisk(container) + err = sut.ContainerStateToDisk(context.Background(), container) // Then Expect(err).NotTo(BeNil()) diff --git a/internal/lib/kill.go b/internal/lib/kill.go index 942ac06de89..60df4ada964 100644 --- a/internal/lib/kill.go +++ b/internal/lib/kill.go @@ -1,6 +1,7 @@ package lib import ( + "context" "syscall" "github.com/cri-o/cri-o/internal/oci" @@ -9,12 +10,12 @@ import ( ) // ContainerKill sends the user provided signal to the containers primary process. -func (c *ContainerServer) ContainerKill(container string, killSignal syscall.Signal) (string, error) { +func (c *ContainerServer) ContainerKill(ctx context.Context, container string, killSignal syscall.Signal) (string, error) { ctr, err := c.LookupContainer(container) if err != nil { return "", errors.Wrapf(err, "failed to find container %s", container) } - if err := c.runtime.UpdateContainerStatus(ctr); err != nil { + if err := c.runtime.UpdateContainerStatus(ctx, ctr); err != nil { logrus.Warnf("unable to update containers %s status: %v", ctr.ID(), err) } cStatus := ctr.State() @@ -24,11 +25,11 @@ func (c *ContainerServer) ContainerKill(container string, killSignal syscall.Sig return "", errors.Errorf("cannot kill container %s: it is not running", container) } - if err := c.runtime.SignalContainer(ctr, killSignal); err != nil { + if err := c.runtime.SignalContainer(ctx, ctr, killSignal); err != nil { return "", err } - if err := c.ContainerStateToDisk(ctr); err != nil { + if err := c.ContainerStateToDisk(ctx, ctr); err != nil { logrus.Warnf("unable to write containers %s state to disk: %v", ctr.ID(), err) } return ctr.ID(), nil diff --git a/internal/lib/kill_test.go b/internal/lib/kill_test.go index 8fa2e6777a8..1d4817499ae 100644 --- a/internal/lib/kill_test.go +++ b/internal/lib/kill_test.go @@ -1,6 +1,7 @@ package lib_test import ( + "context" "syscall" . "github.com/onsi/ginkgo" @@ -16,7 +17,7 @@ var _ = t.Describe("ContainerServer", func() { It("should fail when not found", func() { // Given // When - res, err := sut.ContainerKill("", syscall.SIGINT) + res, err := sut.ContainerKill(context.Background(), "", syscall.SIGINT) // Then Expect(err).NotTo(BeNil()) diff --git a/internal/lib/pause.go b/internal/lib/pause.go index 37d5e345254..6ce485c4d43 100644 --- a/internal/lib/pause.go +++ b/internal/lib/pause.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "github.com/cri-o/cri-o/internal/oci" @@ -9,7 +10,7 @@ import ( ) // ContainerPause pauses a running container. -func (c *ContainerServer) ContainerPause(container string) (string, error) { +func (c *ContainerServer) ContainerPause(ctx context.Context, container string) (string, error) { ctr, err := c.LookupContainer(container) if err != nil { return "", errors.Wrapf(err, "failed to find container %s", container) @@ -17,10 +18,10 @@ func (c *ContainerServer) ContainerPause(container string) (string, error) { cStatus := ctr.State() if cStatus.Status != oci.ContainerStatePaused { - if err := c.runtime.PauseContainer(ctr); err != nil { + if err := c.runtime.PauseContainer(ctx, ctr); err != nil { return "", errors.Wrapf(err, "failed to pause container %s", ctr.ID()) } - if err := c.ContainerStateToDisk(ctr); err != nil { + if err := c.ContainerStateToDisk(ctx, ctr); err != nil { logrus.Warnf("unable to write containers %s state to disk: %v", ctr.ID(), err) } } else { @@ -31,7 +32,7 @@ func (c *ContainerServer) ContainerPause(container string) (string, error) { } // ContainerUnpause unpauses a running container with a grace period (i.e., timeout). -func (c *ContainerServer) ContainerUnpause(container string) (string, error) { +func (c *ContainerServer) ContainerUnpause(ctx context.Context, container string) (string, error) { ctr, err := c.LookupContainer(container) if err != nil { return "", errors.Wrapf(err, "failed to find container %s", container) @@ -39,10 +40,10 @@ func (c *ContainerServer) ContainerUnpause(container string) (string, error) { cStatus := ctr.State() if cStatus.Status == oci.ContainerStatePaused { - if err := c.runtime.UnpauseContainer(ctr); err != nil { + if err := c.runtime.UnpauseContainer(ctx, ctr); err != nil { return "", errors.Wrapf(err, "failed to unpause container %s", ctr.ID()) } - if err := c.ContainerStateToDisk(ctr); err != nil { + if err := c.ContainerStateToDisk(ctx, ctr); err != nil { logrus.Warnf("unable to write containers %s state to disk: %v", ctr.ID(), err) } } else { diff --git a/internal/lib/pause_test.go b/internal/lib/pause_test.go index 07ae911eb4e..7a137ba5ceb 100644 --- a/internal/lib/pause_test.go +++ b/internal/lib/pause_test.go @@ -1,6 +1,8 @@ package lib_test import ( + "context" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -15,7 +17,7 @@ var _ = t.Describe("ContainerServer", func() { // Given // When - res, err := sut.ContainerPause("") + res, err := sut.ContainerPause(context.Background(), "") // Then Expect(err).NotTo(BeNil()) @@ -27,7 +29,7 @@ var _ = t.Describe("ContainerServer", func() { It("should fail on invalid container", func() { // Given // When - res, err := sut.ContainerUnpause("") + res, err := sut.ContainerUnpause(context.Background(), "") // Then Expect(err).NotTo(BeNil()) diff --git a/internal/lib/remove.go b/internal/lib/remove.go index 15080572f05..533415a247c 100644 --- a/internal/lib/remove.go +++ b/internal/lib/remove.go @@ -32,7 +32,7 @@ func (c *ContainerServer) Remove(ctx context.Context, container string, force bo } } - if err := c.runtime.DeleteContainer(ctr); err != nil { + if err := c.runtime.DeleteContainer(ctx, ctr); err != nil { return "", errors.Wrapf(err, "failed to delete container %s", ctrID) } if err := os.Remove(filepath.Join(c.Config().RuntimeConfig.ContainerExitsDir, ctrID)); err != nil && !os.IsNotExist(err) { diff --git a/internal/lib/stop.go b/internal/lib/stop.go index 13b08a2c152..87479d42f13 100644 --- a/internal/lib/stop.go +++ b/internal/lib/stop.go @@ -35,7 +35,7 @@ func (c *ContainerServer) ContainerStop(ctx context.Context, container string, t } } - if err := c.ContainerStateToDisk(ctr); err != nil { + if err := c.ContainerStateToDisk(ctx, ctr); err != nil { logrus.Warnf("unable to write containers %s state to disk: %v", ctr.ID(), err) } diff --git a/internal/lib/wait.go b/internal/lib/wait.go index 5fca9174c4a..259450eb4ba 100644 --- a/internal/lib/wait.go +++ b/internal/lib/wait.go @@ -1,14 +1,16 @@ package lib import ( + "context" + "github.com/cri-o/cri-o/internal/oci" "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/util/wait" ) -func isStopped(c *ContainerServer, ctr *oci.Container) bool { - if err := c.runtime.UpdateContainerStatus(ctr); err != nil { +func isStopped(ctx context.Context, c *ContainerServer, ctr *oci.Container) bool { + if err := c.runtime.UpdateContainerStatus(ctx, ctr); err != nil { logrus.Warnf("unable to update containers %s status: %v", ctr.ID(), err) } cStatus := ctr.State() @@ -16,7 +18,7 @@ func isStopped(c *ContainerServer, ctr *oci.Container) bool { } // ContainerWait stops a running container with a grace period (i.e., timeout). -func (c *ContainerServer) ContainerWait(container string) (int32, error) { +func (c *ContainerServer) ContainerWait(ctx context.Context, container string) (int32, error) { ctr, err := c.LookupContainer(container) if err != nil { return 0, errors.Wrapf(err, "failed to find container %s", container) @@ -24,7 +26,7 @@ func (c *ContainerServer) ContainerWait(container string) (int32, error) { err = wait.PollImmediateInfinite(1, func() (bool, error) { - return isStopped(c, ctr), nil + return isStopped(ctx, c, ctr), nil }, ) @@ -32,7 +34,7 @@ func (c *ContainerServer) ContainerWait(container string) (int32, error) { return 0, err } exitCode := ctr.State().ExitCode - if err := c.ContainerStateToDisk(ctr); err != nil { + if err := c.ContainerStateToDisk(ctx, ctr); err != nil { logrus.Warnf("unable to write containers %s state to disk: %v", ctr.ID(), err) } if exitCode == nil { diff --git a/internal/lib/wait_test.go b/internal/lib/wait_test.go index 9b3924e339f..9941a98a8a3 100644 --- a/internal/lib/wait_test.go +++ b/internal/lib/wait_test.go @@ -1,6 +1,8 @@ package lib_test import ( + "context" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -14,7 +16,7 @@ var _ = t.Describe("ContainerServer", func() { It("should fail on invalid container ID", func() { // Given // When - res, err := sut.ContainerWait("") + res, err := sut.ContainerWait(context.Background(), "") // Then Expect(err).NotTo(BeNil()) diff --git a/internal/oci/oci.go b/internal/oci/oci.go index be9ebf276cb..080538adb74 100644 --- a/internal/oci/oci.go +++ b/internal/oci/oci.go @@ -49,24 +49,24 @@ type Runtime struct { // runtimes. Assumptions based on the fact that a container process runs // on the host will be limited to the RuntimeOCI implementation. type RuntimeImpl interface { - CreateContainer(*Container, string) error - StartContainer(*Container) error - ExecContainer(*Container, []string, io.Reader, io.WriteCloser, io.WriteCloser, + CreateContainer(context.Context, *Container, string) error + StartContainer(context.Context, *Container) error + ExecContainer(context.Context, *Container, []string, io.Reader, io.WriteCloser, io.WriteCloser, bool, <-chan remotecommand.TerminalSize) error - ExecSyncContainer(*Container, []string, int64) (*ExecSyncResponse, error) - UpdateContainer(*Container, *rspec.LinuxResources) error + ExecSyncContainer(context.Context, *Container, []string, int64) (*ExecSyncResponse, error) + UpdateContainer(context.Context, *Container, *rspec.LinuxResources) error StopContainer(context.Context, *Container, int64) error - DeleteContainer(*Container) error - UpdateContainerStatus(*Container) error - PauseContainer(*Container) error - UnpauseContainer(*Container) error - ContainerStats(*Container, string) (*ContainerStats, error) - SignalContainer(*Container, syscall.Signal) error - AttachContainer(*Container, io.Reader, io.WriteCloser, io.WriteCloser, + DeleteContainer(context.Context, *Container) error + UpdateContainerStatus(context.Context, *Container) error + PauseContainer(context.Context, *Container) error + UnpauseContainer(context.Context, *Container) error + ContainerStats(context.Context, *Container, string) (*ContainerStats, error) + SignalContainer(context.Context, *Container, syscall.Signal) error + AttachContainer(context.Context, *Container, io.Reader, io.WriteCloser, io.WriteCloser, bool, <-chan remotecommand.TerminalSize) error PortForwardContainer(context.Context, *Container, string, int32, io.ReadWriteCloser) error - ReopenContainerLog(*Container) error + ReopenContainerLog(context.Context, *Container) error WaitContainerStateStopped(context.Context, *Container) error } @@ -127,7 +127,7 @@ func (r *Runtime) WaitContainerStateStopped(ctx context.Context, c *Container) e return default: // Check if the container is stopped - if err := impl.UpdateContainerStatus(c); err != nil { + if err := impl.UpdateContainerStatus(ctx, c); err != nil { done <- err return } @@ -292,7 +292,7 @@ func (r *Runtime) RuntimeImpl(c *Container) (RuntimeImpl, error) { } // CreateContainer creates a container. -func (r *Runtime) CreateContainer(c *Container, cgroupParent string) error { +func (r *Runtime) CreateContainer(ctx context.Context, c *Container, cgroupParent string) error { // Instantiate a new runtime implementation for this new container impl, err := r.newRuntimeImpl(c) if err != nil { @@ -304,47 +304,47 @@ func (r *Runtime) CreateContainer(c *Container, cgroupParent string) error { r.runtimeImplMap[c.ID()] = impl r.runtimeImplMapMutex.Unlock() - return impl.CreateContainer(c, cgroupParent) + return impl.CreateContainer(ctx, c, cgroupParent) } // StartContainer starts a container. -func (r *Runtime) StartContainer(c *Container) error { +func (r *Runtime) StartContainer(ctx context.Context, c *Container) error { impl, err := r.RuntimeImpl(c) if err != nil { return err } - return impl.StartContainer(c) + return impl.StartContainer(ctx, c) } // ExecContainer prepares a streaming endpoint to execute a command in the container. -func (r *Runtime) ExecContainer(c *Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { +func (r *Runtime) ExecContainer(ctx context.Context, c *Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { impl, err := r.RuntimeImpl(c) if err != nil { return err } - return impl.ExecContainer(c, cmd, stdin, stdout, stderr, tty, resize) + return impl.ExecContainer(ctx, c, cmd, stdin, stdout, stderr, tty, resize) } // ExecSyncContainer execs a command in a container and returns it's stdout, stderr and return code. -func (r *Runtime) ExecSyncContainer(c *Container, command []string, timeout int64) (*ExecSyncResponse, error) { +func (r *Runtime) ExecSyncContainer(ctx context.Context, c *Container, command []string, timeout int64) (*ExecSyncResponse, error) { impl, err := r.RuntimeImpl(c) if err != nil { return nil, err } - return impl.ExecSyncContainer(c, command, timeout) + return impl.ExecSyncContainer(ctx, c, command, timeout) } // UpdateContainer updates container resources -func (r *Runtime) UpdateContainer(c *Container, res *rspec.LinuxResources) error { +func (r *Runtime) UpdateContainer(ctx context.Context, c *Container, res *rspec.LinuxResources) error { impl, err := r.RuntimeImpl(c) if err != nil { return err } - return impl.UpdateContainer(c, res) + return impl.UpdateContainer(ctx, c, res) } // StopContainer stops a container. Timeout is given in seconds. @@ -358,7 +358,7 @@ func (r *Runtime) StopContainer(ctx context.Context, c *Container, timeout int64 } // DeleteContainer deletes a container. -func (r *Runtime) DeleteContainer(c *Container) (err error) { +func (r *Runtime) DeleteContainer(ctx context.Context, c *Container) (err error) { r.runtimeImplMapMutex.RLock() impl, ok := r.runtimeImplMap[c.ID()] r.runtimeImplMapMutex.RUnlock() @@ -376,67 +376,67 @@ func (r *Runtime) DeleteContainer(c *Container) (err error) { }() } - return impl.DeleteContainer(c) + return impl.DeleteContainer(ctx, c) } // UpdateContainerStatus refreshes the status of the container. -func (r *Runtime) UpdateContainerStatus(c *Container) error { +func (r *Runtime) UpdateContainerStatus(ctx context.Context, c *Container) error { impl, err := r.RuntimeImpl(c) if err != nil { return err } - return impl.UpdateContainerStatus(c) + return impl.UpdateContainerStatus(ctx, c) } // PauseContainer pauses a container. -func (r *Runtime) PauseContainer(c *Container) error { +func (r *Runtime) PauseContainer(ctx context.Context, c *Container) error { impl, err := r.RuntimeImpl(c) if err != nil { return err } - return impl.PauseContainer(c) + return impl.PauseContainer(ctx, c) } // UnpauseContainer unpauses a container. -func (r *Runtime) UnpauseContainer(c *Container) error { +func (r *Runtime) UnpauseContainer(ctx context.Context, c *Container) error { impl, err := r.RuntimeImpl(c) if err != nil { return err } - return impl.UnpauseContainer(c) + return impl.UnpauseContainer(ctx, c) } // ContainerStats provides statistics of a container. -func (r *Runtime) ContainerStats(c *Container, cgroup string) (*ContainerStats, error) { +func (r *Runtime) ContainerStats(ctx context.Context, c *Container, cgroup string) (*ContainerStats, error) { impl, err := r.RuntimeImpl(c) if err != nil { return nil, err } - return impl.ContainerStats(c, cgroup) + return impl.ContainerStats(ctx, c, cgroup) } // SignalContainer sends a signal to a container process. -func (r *Runtime) SignalContainer(c *Container, sig syscall.Signal) error { +func (r *Runtime) SignalContainer(ctx context.Context, c *Container, sig syscall.Signal) error { impl, err := r.RuntimeImpl(c) if err != nil { return err } - return impl.SignalContainer(c, sig) + return impl.SignalContainer(ctx, c, sig) } // AttachContainer attaches IO to a running container. -func (r *Runtime) AttachContainer(c *Container, inputStream io.Reader, outputStream, errorStream io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { +func (r *Runtime) AttachContainer(ctx context.Context, c *Container, inputStream io.Reader, outputStream, errorStream io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { impl, err := r.RuntimeImpl(c) if err != nil { return err } - return impl.AttachContainer(c, inputStream, outputStream, errorStream, tty, resize) + return impl.AttachContainer(ctx, c, inputStream, outputStream, errorStream, tty, resize) } // PortForwardContainer forwards the specified port provides statistics of a container. @@ -450,13 +450,13 @@ func (r *Runtime) PortForwardContainer(ctx context.Context, c *Container, netNsP } // ReopenContainerLog reopens the log file of a container. -func (r *Runtime) ReopenContainerLog(c *Container) error { +func (r *Runtime) ReopenContainerLog(ctx context.Context, c *Container) error { impl, err := r.RuntimeImpl(c) if err != nil { return err } - return impl.ReopenContainerLog(c) + return impl.ReopenContainerLog(ctx, c) } // ExecSyncResponse is returned from ExecSync. diff --git a/internal/oci/runtime_oci.go b/internal/oci/runtime_oci.go index ff9f9c40f19..f35c931e00f 100644 --- a/internal/oci/runtime_oci.go +++ b/internal/oci/runtime_oci.go @@ -76,7 +76,7 @@ type exitCodeInfo struct { } // CreateContainer creates a container. -func (r *runtimeOCI) CreateContainer(c *Container, cgroupParent string) (retErr error) { +func (r *runtimeOCI) CreateContainer(ctx context.Context, c *Container, cgroupParent string) (retErr error) { if c.Spoofed() { return nil } @@ -186,7 +186,7 @@ func (r *runtimeOCI) CreateContainer(c *Container, cgroupParent string) (retErr // We will delete all container resources if creation fails defer func() { if retErr != nil { - if err := r.DeleteContainer(c); err != nil { + if err := r.DeleteContainer(ctx, c); err != nil { logrus.Warnf("unable to delete container %s: %v", c.ID(), err) } } @@ -238,7 +238,7 @@ func (r *runtimeOCI) CreateContainer(c *Container, cgroupParent string) (retErr } // StartContainer starts a container. -func (r *runtimeOCI) StartContainer(c *Container) error { +func (r *runtimeOCI) StartContainer(ctx context.Context, c *Container) error { c.opLock.Lock() defer c.opLock.Unlock() @@ -319,7 +319,7 @@ func parseLog(l []byte) (stdout, stderr []byte) { } // ExecContainer prepares a streaming endpoint to execute a command in the container. -func (r *runtimeOCI) ExecContainer(c *Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { +func (r *runtimeOCI) ExecContainer(ctx context.Context, c *Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { if c.Spoofed() { return nil } @@ -389,7 +389,7 @@ func (r *runtimeOCI) ExecContainer(c *Container, cmd []string, stdin io.Reader, } // ExecSyncContainer execs a command in a container and returns it's stdout, stderr and return code. -func (r *runtimeOCI) ExecSyncContainer(c *Container, command []string, timeout int64) (*ExecSyncResponse, error) { +func (r *runtimeOCI) ExecSyncContainer(ctx context.Context, c *Container, command []string, timeout int64) (*ExecSyncResponse, error) { if c.Spoofed() { return nil, nil } @@ -562,7 +562,7 @@ func (r *runtimeOCI) ExecSyncContainer(c *Container, command []string, timeout i } // UpdateContainer updates container resources -func (r *runtimeOCI) UpdateContainer(c *Container, res *rspec.LinuxResources) error { +func (r *runtimeOCI) UpdateContainer(ctx context.Context, c *Container, res *rspec.LinuxResources) error { if c.Spoofed() { return nil } @@ -728,7 +728,7 @@ func checkProcessGone(c *Container) { } // DeleteContainer deletes a container. -func (r *runtimeOCI) DeleteContainer(c *Container) error { +func (r *runtimeOCI) DeleteContainer(ctx context.Context, c *Container) error { c.opLock.Lock() defer c.opLock.Unlock() @@ -763,7 +763,7 @@ func updateContainerStatusFromExitFile(c *Container) error { } // UpdateContainerStatus refreshes the status of the container. -func (r *runtimeOCI) UpdateContainerStatus(c *Container) error { +func (r *runtimeOCI) UpdateContainerStatus(ctx context.Context, c *Container) error { c.opLock.Lock() defer c.opLock.Unlock() @@ -876,7 +876,7 @@ func (r *runtimeOCI) UpdateContainerStatus(c *Container) error { } // PauseContainer pauses a container. -func (r *runtimeOCI) PauseContainer(c *Container) error { +func (r *runtimeOCI) PauseContainer(ctx context.Context, c *Container) error { c.opLock.Lock() defer c.opLock.Unlock() @@ -889,7 +889,7 @@ func (r *runtimeOCI) PauseContainer(c *Container) error { } // UnpauseContainer unpauses a container. -func (r *runtimeOCI) UnpauseContainer(c *Container) error { +func (r *runtimeOCI) UnpauseContainer(ctx context.Context, c *Container) error { c.opLock.Lock() defer c.opLock.Unlock() @@ -906,14 +906,14 @@ func (r *runtimeOCI) WaitContainerStateStopped(ctx context.Context, c *Container } // ContainerStats provides statistics of a container. -func (r *runtimeOCI) ContainerStats(c *Container, cgroup string) (*ContainerStats, error) { +func (r *runtimeOCI) ContainerStats(ctx context.Context, c *Container, cgroup string) (*ContainerStats, error) { c.opLock.Lock() defer c.opLock.Unlock() return r.containerStats(c, cgroup) } // SignalContainer sends a signal to a container process. -func (r *runtimeOCI) SignalContainer(c *Container, sig syscall.Signal) error { +func (r *runtimeOCI) SignalContainer(ctx context.Context, c *Container, sig syscall.Signal) error { c.opLock.Lock() defer c.opLock.Unlock() @@ -932,7 +932,7 @@ func (r *runtimeOCI) SignalContainer(c *Container, sig syscall.Signal) error { } // AttachContainer attaches IO to a running container. -func (r *runtimeOCI) AttachContainer(c *Container, inputStream io.Reader, outputStream, errorStream io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { +func (r *runtimeOCI) AttachContainer(ctx context.Context, c *Container, inputStream io.Reader, outputStream, errorStream io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { if c.Spoofed() { return nil } @@ -1095,7 +1095,7 @@ func (r *runtimeOCI) PortForwardContainer(ctx context.Context, c *Container, net } // ReopenContainerLog reopens the log file of a container. -func (r *runtimeOCI) ReopenContainerLog(c *Container) error { +func (r *runtimeOCI) ReopenContainerLog(ctx context.Context, c *Container) error { if c.Spoofed() { return nil } diff --git a/internal/oci/runtime_vm.go b/internal/oci/runtime_vm.go index c7e94d71fe0..7812d194e5a 100644 --- a/internal/oci/runtime_vm.go +++ b/internal/oci/runtime_vm.go @@ -38,10 +38,8 @@ import ( type runtimeVM struct { path string fifoDir string - - ctx context.Context - client *ttrpc.Client - task task.TaskService + client *ttrpc.Client + task task.TaskService sync.Mutex ctrs map[string]containerInfo @@ -52,7 +50,7 @@ type containerInfo struct { } // newRuntimeVM creates a new runtimeVM instance -func newRuntimeVM(path string, root string) RuntimeImpl { +func newRuntimeVM(path, root string) RuntimeImpl { logrus.Debug("oci.newRuntimeVM() start") defer logrus.Debug("oci.newRuntimeVM() end") @@ -71,13 +69,12 @@ func newRuntimeVM(path string, root string) RuntimeImpl { return &runtimeVM{ path: path, fifoDir: filepath.Join(root, "crio", "fifo"), - ctx: context.Background(), ctrs: make(map[string]containerInfo), } } // CreateContainer creates a container. -func (r *runtimeVM) CreateContainer(c *Container, cgroupParent string) (retErr error) { +func (r *runtimeVM) CreateContainer(ctx context.Context, c *Container, cgroupParent string) (retErr error) { logrus.Debug("runtimeVM.CreateContainer() start") defer logrus.Debug("runtimeVM.CreateContainer() end") @@ -86,7 +83,7 @@ func (r *runtimeVM) CreateContainer(c *Container, cgroupParent string) (retErr e defer c.opLock.Unlock() // First thing, we need to start the runtime daemon - if err := r.startRuntimeDaemon(c); err != nil { + if err := r.startRuntimeDaemon(ctx, c); err != nil { return err } @@ -136,7 +133,7 @@ func (r *runtimeVM) CreateContainer(c *Container, cgroupParent string) (retErr e defer func() { if retErr != nil { logrus.WithError(err).Warnf("Cleaning up container %s", c.ID()) - if cleanupErr := r.deleteContainer(c, true); cleanupErr != nil { + if cleanupErr := r.deleteContainer(ctx, c, true); cleanupErr != nil { logrus.WithError(cleanupErr).Infof("deleteContainer failed for container %s", c.ID()) } } @@ -155,7 +152,7 @@ func (r *runtimeVM) CreateContainer(c *Container, cgroupParent string) (retErr e createdCh := make(chan error) go func() { // Create the container - if resp, err := r.task.Create(r.ctx, request); err != nil { + if resp, err := r.task.Create(ctx, request); err != nil { createdCh <- errdefs.FromGRPC(err) } else if err := c.state.SetInitPid(int(resp.Pid)); err != nil { createdCh <- err @@ -170,7 +167,7 @@ func (r *runtimeVM) CreateContainer(c *Container, cgroupParent string) (retErr e return errors.Errorf("CreateContainer failed: %v", err) } case <-time.After(ContainerCreateTimeout): - if err := r.remove(r.ctx, c.ID(), ""); err != nil { + if err := r.remove(ctx, c.ID(), ""); err != nil { return err } <-createdCh @@ -180,7 +177,7 @@ func (r *runtimeVM) CreateContainer(c *Container, cgroupParent string) (retErr e return nil } -func (r *runtimeVM) startRuntimeDaemon(c *Container) error { +func (r *runtimeVM) startRuntimeDaemon(ctx context.Context, c *Container) error { logrus.Debug("runtimeVM.startRuntimeDaemon() start") defer logrus.Debug("runtimeVM.startRuntimeDaemon() end") @@ -194,12 +191,11 @@ func (r *runtimeVM) startRuntimeDaemon(c *Container) error { // Modify the runtime path so that it complies with v2 shim API newRuntimePath := strings.ReplaceAll(r.path, "-", ".") - // Setup default namespace - r.ctx = namespaces.WithNamespace(r.ctx, namespaces.Default) + ctx = namespaces.WithNamespace(ctx, namespaces.Default) // Prepare the command to exec cmd, err := client.Command( - r.ctx, + ctx, newRuntimePath, "", "", @@ -212,7 +208,7 @@ func (r *runtimeVM) startRuntimeDaemon(c *Container) error { } // Create the log file expected by shim-v2 API - f, err := fifo.OpenFifo(r.ctx, filepath.Join(c.BundlePath(), "log"), + f, err := fifo.OpenFifo(ctx, filepath.Join(c.BundlePath(), "log"), unix.O_RDONLY|unix.O_CREAT|unix.O_NONBLOCK, 0o700) if err != nil { return err @@ -254,7 +250,7 @@ func (r *runtimeVM) startRuntimeDaemon(c *Container) error { } // StartContainer starts a container. -func (r *runtimeVM) StartContainer(c *Container) error { +func (r *runtimeVM) StartContainer(ctx context.Context, c *Container) error { logrus.Debug("runtimeVM.StartContainer() start") defer logrus.Debug("runtimeVM.StartContainer() end") @@ -262,7 +258,7 @@ func (r *runtimeVM) StartContainer(c *Container) error { c.opLock.Lock() defer c.opLock.Unlock() - if err := r.start(r.ctx, c.ID(), ""); err != nil { + if err := r.start(ctx, c.ID(), ""); err != nil { return err } c.state.Started = time.Now() @@ -270,9 +266,9 @@ func (r *runtimeVM) StartContainer(c *Container) error { // Spawn a goroutine waiting for the container to terminate. Once it // happens, the container status is retrieved to be updated. go func() { - _, err := r.wait(r.ctx, c.ID(), "") + _, err := r.wait(ctx, c.ID(), "") if err == nil { - if err1 := r.updateContainerStatus(c); err1 != nil { + if err1 := r.updateContainerStatus(ctx, c); err1 != nil { logrus.Warningf("error updating container status %v", err1) } } else { @@ -284,11 +280,11 @@ func (r *runtimeVM) StartContainer(c *Container) error { } // ExecContainer prepares a streaming endpoint to execute a command in the container. -func (r *runtimeVM) ExecContainer(c *Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { +func (r *runtimeVM) ExecContainer(ctx context.Context, c *Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { logrus.Debug("runtimeVM.ExecContainer() start") defer logrus.Debug("runtimeVM.ExecContainer() end") - exitCode, err := r.execContainerCommon(c, cmd, 0, stdin, stdout, stderr, tty, resize) + exitCode, err := r.execContainerCommon(ctx, c, cmd, 0, stdin, stdout, stderr, tty, resize) if err != nil { return err } @@ -303,7 +299,7 @@ func (r *runtimeVM) ExecContainer(c *Container, cmd []string, stdin io.Reader, s } // ExecSyncContainer execs a command in a container and returns it's stdout, stderr and return code. -func (r *runtimeVM) ExecSyncContainer(c *Container, command []string, timeout int64) (*ExecSyncResponse, error) { +func (r *runtimeVM) ExecSyncContainer(ctx context.Context, c *Container, command []string, timeout int64) (*ExecSyncResponse, error) { logrus.Debug("runtimeVM.ExecSyncContainer() start") defer logrus.Debug("runtimeVM.ExecSyncContainer() end") @@ -311,7 +307,7 @@ func (r *runtimeVM) ExecSyncContainer(c *Container, command []string, timeout in stdout := cioutil.NewNopWriteCloser(&stdoutBuf) stderr := cioutil.NewNopWriteCloser(&stderrBuf) - exitCode, err := r.execContainerCommon(c, command, timeout, nil, stdout, stderr, c.terminal, nil) + exitCode, err := r.execContainerCommon(ctx, c, command, timeout, nil, stdout, stderr, c.terminal, nil) if err != nil { return nil, &ExecSyncError{ ExitCode: -1, @@ -326,12 +322,12 @@ func (r *runtimeVM) ExecSyncContainer(c *Container, command []string, timeout in }, nil } -func (r *runtimeVM) execContainerCommon(c *Container, cmd []string, timeout int64, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) (exitCode int32, retErr error) { +func (r *runtimeVM) execContainerCommon(ctx context.Context, c *Container, cmd []string, timeout int64, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) (exitCode int32, retErr error) { logrus.Debug("runtimeVM.execContainerCommon() start") defer logrus.Debug("runtimeVM.execContainerCommon() end") // Cancel the context before returning to ensure goroutines are stopped. - ctx, cancel := context.WithCancel(r.ctx) + ctx, cancel := context.WithCancel(ctx) defer cancel() // Generate a unique execID @@ -468,7 +464,7 @@ func (r *runtimeVM) execContainerCommon(c *Container, cmd []string, timeout int6 } // UpdateContainer updates container resources -func (r *runtimeVM) UpdateContainer(c *Container, res *rspec.LinuxResources) error { +func (r *runtimeVM) UpdateContainer(ctx context.Context, c *Container, res *rspec.LinuxResources) error { logrus.Debug("runtimeVM.UpdateContainer() start") defer logrus.Debug("runtimeVM.UpdateContainer() end") @@ -482,7 +478,7 @@ func (r *runtimeVM) UpdateContainer(c *Container, res *rspec.LinuxResources) err return err } - if _, err := r.task.Update(r.ctx, &task.UpdateTaskRequest{ + if _, err := r.task.Update(ctx, &task.UpdateTaskRequest{ ID: c.ID(), Resources: any, }); err != nil { @@ -506,7 +502,7 @@ func (r *runtimeVM) StopContainer(ctx context.Context, c *Container, timeout int } // Cancel the context before returning to ensure goroutines are stopped. - ctx, cancel := context.WithCancel(r.ctx) + ctx, cancel := context.WithCancel(ctx) defer cancel() stopCh := make(chan error) @@ -565,7 +561,7 @@ func (r *runtimeVM) waitCtrTerminate(sig syscall.Signal, stopCh chan error, time } // DeleteContainer deletes a container. -func (r *runtimeVM) DeleteContainer(c *Container) error { +func (r *runtimeVM) DeleteContainer(ctx context.Context, c *Container) error { logrus.Debug("runtimeVM.DeleteContainer() start") defer logrus.Debug("runtimeVM.DeleteContainer() end") @@ -573,13 +569,13 @@ func (r *runtimeVM) DeleteContainer(c *Container) error { c.opLock.Lock() defer c.opLock.Unlock() - return r.deleteContainer(c, false) + return r.deleteContainer(ctx, c, false) } // deleteContainer performs all the operations needed to delete a container. // force must only be used on clean-up cases. // It does **not** Lock the container, thus it's the caller responsibility to do so, when needed. -func (r *runtimeVM) deleteContainer(c *Container, force bool) error { +func (r *runtimeVM) deleteContainer(ctx context.Context, c *Container, force bool) error { r.Lock() cInfo, ok := r.ctrs[c.ID()] r.Unlock() @@ -591,11 +587,11 @@ func (r *runtimeVM) deleteContainer(c *Container, force bool) error { return err } - if err := r.remove(r.ctx, c.ID(), ""); err != nil && !force { + if err := r.remove(ctx, c.ID(), ""); err != nil && !force { return err } - _, err := r.task.Shutdown(r.ctx, &task.ShutdownRequest{ID: c.ID()}) + _, err := r.task.Shutdown(ctx, &task.ShutdownRequest{ID: c.ID()}) if err != nil && !errors.Is(err, ttrpc.ErrClosed) && !force { return err } @@ -608,7 +604,7 @@ func (r *runtimeVM) deleteContainer(c *Container, force bool) error { } // UpdateContainerStatus refreshes the status of the container. -func (r *runtimeVM) UpdateContainerStatus(c *Container) error { +func (r *runtimeVM) UpdateContainerStatus(ctx context.Context, c *Container) error { logrus.Debug("runtimeVM.UpdateContainerStatus() start") defer logrus.Debug("runtimeVM.UpdateContainerStatus() end") @@ -616,13 +612,13 @@ func (r *runtimeVM) UpdateContainerStatus(c *Container) error { c.opLock.Lock() defer c.opLock.Unlock() - return r.updateContainerStatus(c) + return r.updateContainerStatus(ctx, c) } // updateContainerStatus is a UpdateContainerStatus helper, which actually does the container's // status refresh. // It does **not** Lock the container, thus it's the caller responsibility to do so, when needed. -func (r *runtimeVM) updateContainerStatus(c *Container) error { +func (r *runtimeVM) updateContainerStatus(ctx context.Context, c *Container) error { logrus.Debug("runtimeVM.updateContainerStatus() start") defer logrus.Debug("runtimeVM.updateContainerStatus() end") @@ -632,7 +628,7 @@ func (r *runtimeVM) updateContainerStatus(c *Container) error { return errors.New("runtime not correctly setup") } - response, err := r.task.State(r.ctx, &task.StateRequest{ + response, err := r.task.State(ctx, &task.StateRequest{ ID: c.ID(), }) if err != nil { @@ -670,7 +666,7 @@ func (r *runtimeVM) updateContainerStatus(c *Container) error { } // PauseContainer pauses a container. -func (r *runtimeVM) PauseContainer(c *Container) error { +func (r *runtimeVM) PauseContainer(ctx context.Context, c *Container) error { logrus.Debug("runtimeVM.PauseContainer() start") defer logrus.Debug("runtimeVM.PauseContainer() end") @@ -678,7 +674,7 @@ func (r *runtimeVM) PauseContainer(c *Container) error { c.opLock.Lock() defer c.opLock.Unlock() - if _, err := r.task.Pause(r.ctx, &task.PauseRequest{ + if _, err := r.task.Pause(ctx, &task.PauseRequest{ ID: c.ID(), }); err != nil { return errdefs.FromGRPC(err) @@ -688,7 +684,7 @@ func (r *runtimeVM) PauseContainer(c *Container) error { } // UnpauseContainer unpauses a container. -func (r *runtimeVM) UnpauseContainer(c *Container) error { +func (r *runtimeVM) UnpauseContainer(ctx context.Context, c *Container) error { logrus.Debug("runtimeVM.UnpauseContainer() start") defer logrus.Debug("runtimeVM.UnpauseContainer() end") @@ -696,7 +692,7 @@ func (r *runtimeVM) UnpauseContainer(c *Container) error { c.opLock.Lock() defer c.opLock.Unlock() - if _, err := r.task.Resume(r.ctx, &task.ResumeRequest{ + if _, err := r.task.Resume(ctx, &task.ResumeRequest{ ID: c.ID(), }); err != nil { return errdefs.FromGRPC(err) @@ -706,7 +702,7 @@ func (r *runtimeVM) UnpauseContainer(c *Container) error { } // ContainerStats provides statistics of a container. -func (r *runtimeVM) ContainerStats(c *Container, _ string) (*ContainerStats, error) { +func (r *runtimeVM) ContainerStats(ctx context.Context, c *Container, _ string) (*ContainerStats, error) { logrus.Debug("runtimeVM.ContainerStats() start") defer logrus.Debug("runtimeVM.ContainerStats() end") @@ -714,7 +710,7 @@ func (r *runtimeVM) ContainerStats(c *Container, _ string) (*ContainerStats, err c.opLock.RLock() defer c.opLock.RUnlock() - resp, err := r.task.Stats(r.ctx, &task.StatsRequest{ + resp, err := r.task.Stats(ctx, &task.StatsRequest{ ID: c.ID(), }) if err != nil { @@ -738,7 +734,7 @@ func (r *runtimeVM) ContainerStats(c *Container, _ string) (*ContainerStats, err } // SignalContainer sends a signal to a container process. -func (r *runtimeVM) SignalContainer(c *Container, sig syscall.Signal) error { +func (r *runtimeVM) SignalContainer(ctx context.Context, c *Container, sig syscall.Signal) error { logrus.Debug("runtimeVM.SignalContainer() start") defer logrus.Debug("runtimeVM.SignalContainer() end") @@ -746,11 +742,11 @@ func (r *runtimeVM) SignalContainer(c *Container, sig syscall.Signal) error { c.opLock.Lock() defer c.opLock.Unlock() - return r.kill(r.ctx, c.ID(), "", sig, true) + return r.kill(ctx, c.ID(), "", sig, true) } // AttachContainer attaches IO to a running container. -func (r *runtimeVM) AttachContainer(c *Container, inputStream io.Reader, outputStream, errorStream io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { +func (r *runtimeVM) AttachContainer(ctx context.Context, c *Container, inputStream io.Reader, outputStream, errorStream io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { logrus.Debug("runtimeVM.AttachContainer() start") defer logrus.Debug("runtimeVM.AttachContainer() end") @@ -758,7 +754,7 @@ func (r *runtimeVM) AttachContainer(c *Container, inputStream io.Reader, outputS kubecontainer.HandleResizing(resize, func(size remotecommand.TerminalSize) { logrus.Debugf("Got a resize event: %+v", size) - if err := r.resizePty(r.ctx, c.ID(), "", size); err != nil { + if err := r.resizePty(ctx, c.ID(), "", size); err != nil { logrus.Warnf("Failed to resize terminal: %v", err) } }) @@ -777,7 +773,7 @@ func (r *runtimeVM) AttachContainer(c *Container, inputStream io.Reader, outputS Tty: tty, StdinOnce: c.stdinOnce, CloseStdin: func() error { - return r.closeIO(r.ctx, c.ID(), "") + return r.closeIO(ctx, c.ID(), "") }, } @@ -793,7 +789,7 @@ func (r *runtimeVM) PortForwardContainer(context.Context, *Container, string, in } // ReopenContainerLog reopens the log file of a container. -func (r *runtimeVM) ReopenContainerLog(c *Container) error { +func (r *runtimeVM) ReopenContainerLog(ctx context.Context, c *Container) error { logrus.Debug("runtimeVM.ReopenContainerLog() start") defer logrus.Debug("runtimeVM.ReopenContainerLog() end") diff --git a/server/container_attach.go b/server/container_attach.go index cc8455db675..c4cad708154 100644 --- a/server/container_attach.go +++ b/server/container_attach.go @@ -29,7 +29,7 @@ func (s StreamService) Attach(containerID string, inputStream io.Reader, outputS return status.Errorf(codes.NotFound, "could not find container %q: %v", containerID, err) } - if err := s.runtimeServer.Runtime().UpdateContainerStatus(c); err != nil { + if err := s.runtimeServer.Runtime().UpdateContainerStatus(s.ctx, c); err != nil { return err } @@ -38,5 +38,5 @@ func (s StreamService) Attach(containerID string, inputStream io.Reader, outputS return fmt.Errorf("container is not created or running") } - return s.runtimeServer.Runtime().AttachContainer(c, inputStream, outputStream, errorStream, tty, resize) + return s.runtimeServer.Runtime().AttachContainer(s.ctx, c, inputStream, outputStream, errorStream, tty, resize) } diff --git a/server/container_create.go b/server/container_create.go index 8bfbe1e4e01..b5b30d115a0 100644 --- a/server/container_create.go +++ b/server/container_create.go @@ -530,19 +530,19 @@ func (s *Server) CreateContainer(ctx context.Context, req *types.CreateContainer return nil, err } - if err := s.createContainerPlatform(newContainer, sb.CgroupParent(), mappings); err != nil { + if err := s.createContainerPlatform(ctx, newContainer, sb.CgroupParent(), mappings); err != nil { return nil, err } cleanupFuncs = append(cleanupFuncs, func() { if retErr != nil { log.Infof(ctx, "createCtr: removing container ID %s from runtime", ctr.ID()) - if err := s.Runtime().DeleteContainer(newContainer); err != nil { + if err := s.Runtime().DeleteContainer(ctx, newContainer); err != nil { log.Warnf(ctx, "failed to delete container in runtime %s: %v", ctr.ID(), err) } } }) - if err := s.ContainerStateToDisk(newContainer); err != nil { + if err := s.ContainerStateToDisk(ctx, newContainer); err != nil { log.Warnf(ctx, "unable to write containers %s state to disk: %v", newContainer.ID(), err) } diff --git a/server/container_create_generic.go b/server/container_create_generic.go index 44a2d0c7b04..e5f0a31fcc8 100644 --- a/server/container_create_generic.go +++ b/server/container_create_generic.go @@ -3,11 +3,13 @@ package server import ( + "context" + "github.com/containers/storage/pkg/idtools" "github.com/cri-o/cri-o/internal/oci" ) // createContainerPlatform performs platform dependent intermediate steps before calling the container's oci.Runtime().CreateContainer() -func (s *Server) createContainerPlatform(container *oci.Container, cgroupParent string, idMappings *idtools.IDMappings) error { - return s.Runtime().CreateContainer(container, cgroupParent) +func (s *Server) createContainerPlatform(ctx context.Context, container *oci.Container, cgroupParent string, idMappings *idtools.IDMappings) error { + return s.Runtime().CreateContainer(ctx, container, cgroupParent) } diff --git a/server/container_create_linux.go b/server/container_create_linux.go index 988a92790d2..fbe6d075780 100644 --- a/server/container_create_linux.go +++ b/server/container_create_linux.go @@ -36,7 +36,7 @@ import ( ) // createContainerPlatform performs platform dependent intermediate steps before calling the container's oci.Runtime().CreateContainer() -func (s *Server) createContainerPlatform(container *oci.Container, cgroupParent string, idMappings *idtools.IDMappings) error { +func (s *Server) createContainerPlatform(ctx context.Context, container *oci.Container, cgroupParent string, idMappings *idtools.IDMappings) error { if idMappings != nil && !container.Spoofed() { rootPair := idMappings.RootPair() for _, path := range []string{container.BundlePath(), container.MountPoint()} { @@ -48,7 +48,7 @@ func (s *Server) createContainerPlatform(container *oci.Container, cgroupParent return err } } - return s.Runtime().CreateContainer(container, cgroupParent) + return s.Runtime().CreateContainer(ctx, container, cgroupParent) } // makeAccessible changes the path permission and each parent directory to have --x--x--x diff --git a/server/container_exec.go b/server/container_exec.go index 51b9be262ce..0e8427bab7c 100644 --- a/server/container_exec.go +++ b/server/container_exec.go @@ -29,7 +29,7 @@ func (s StreamService) Exec(containerID string, cmd []string, stdin io.Reader, s return status.Errorf(codes.NotFound, "could not find container %q: %v", containerID, err) } - if err := s.runtimeServer.Runtime().UpdateContainerStatus(c); err != nil { + if err := s.runtimeServer.Runtime().UpdateContainerStatus(s.ctx, c); err != nil { return err } @@ -38,5 +38,5 @@ func (s StreamService) Exec(containerID string, cmd []string, stdin io.Reader, s return fmt.Errorf("container is not created or running") } - return s.runtimeServer.Runtime().ExecContainer(c, cmd, stdin, stdout, stderr, tty, resize) + return s.runtimeServer.Runtime().ExecContainer(s.ctx, c, cmd, stdin, stdout, stderr, tty, resize) } diff --git a/server/container_execsync.go b/server/container_execsync.go index 2aaba83c03a..baa294793ad 100644 --- a/server/container_execsync.go +++ b/server/container_execsync.go @@ -24,7 +24,7 @@ func (s *Server) ExecSync(ctx context.Context, req *types.ExecSyncRequest) (*typ return nil, errors.New("exec command cannot be empty") } - execResp, err := s.Runtime().ExecSyncContainer(c, cmd, req.Timeout) + execResp, err := s.Runtime().ExecSyncContainer(ctx, c, cmd, req.Timeout) if err != nil { return nil, err } diff --git a/server/container_reopen_log.go b/server/container_reopen_log.go index 9da284cb3f7..096611b3500 100644 --- a/server/container_reopen_log.go +++ b/server/container_reopen_log.go @@ -16,7 +16,7 @@ func (s *Server) ReopenContainerLog(ctx context.Context, req *types.ReopenContai return errors.Wrapf(err, "could not find container %s", req.ContainerID) } - if err := s.ContainerServer.Runtime().UpdateContainerStatus(c); err != nil { + if err := s.ContainerServer.Runtime().UpdateContainerStatus(ctx, c); err != nil { return err } @@ -25,7 +25,7 @@ func (s *Server) ReopenContainerLog(ctx context.Context, req *types.ReopenContai return fmt.Errorf("container is not created or running") } - if err := s.ContainerServer.Runtime().ReopenContainerLog(c); err != nil { + if err := s.ContainerServer.Runtime().ReopenContainerLog(ctx, c); err != nil { return err } return nil diff --git a/server/container_start.go b/server/container_start.go index baa03abde5f..47974bb88f9 100644 --- a/server/container_start.go +++ b/server/container_start.go @@ -43,7 +43,7 @@ func (s *Server) StartContainer(ctx context.Context, req *types.StartContainerRe } } } - if err := s.ContainerStateToDisk(c); err != nil { + if err := s.ContainerStateToDisk(ctx, c); err != nil { log.Warnf(ctx, "unable to write containers %s state to disk: %v", c.ID(), err) } }() @@ -54,7 +54,7 @@ func (s *Server) StartContainer(ctx context.Context, req *types.StartContainerRe } } - if err := s.Runtime().StartContainer(c); err != nil { + if err := s.Runtime().StartContainer(ctx, c); err != nil { return fmt.Errorf("failed to start container %s: %v", c.ID(), err) } diff --git a/server/container_stats.go b/server/container_stats.go index 502a2f9b4cf..95ada8b6407 100644 --- a/server/container_stats.go +++ b/server/container_stats.go @@ -62,7 +62,7 @@ func (s *Server) ContainerStats(ctx context.Context, req *types.ContainerStatsRe } cgroup := sb.CgroupParent() - stats, err := s.Runtime().ContainerStats(container, cgroup) + stats, err := s.Runtime().ContainerStats(ctx, container, cgroup) if err != nil { return nil, err } diff --git a/server/container_stats_list.go b/server/container_stats_list.go index b7138a5c1af..341da774940 100644 --- a/server/container_stats_list.go +++ b/server/container_stats_list.go @@ -35,7 +35,7 @@ func (s *Server) ListContainerStats(ctx context.Context, req *types.ListContaine continue } cgroup := sb.CgroupParent() - stats, err := s.Runtime().ContainerStats(container, cgroup) + stats, err := s.Runtime().ContainerStats(ctx, container, cgroup) if err != nil { log.Warnf(ctx, "unable to get stats for container %s: %v", container.ID(), err) continue diff --git a/server/container_status.go b/server/container_status.go index 146c5219245..99bb8315583 100644 --- a/server/container_status.go +++ b/server/container_status.go @@ -58,7 +58,7 @@ func (s *Server) ContainerStatus(ctx context.Context, req *types.ContainerStatus // If we defaulted to exit code not set earlier then we attempt to // get the exit code from the exit file again. if cState.Status == oci.ContainerStateStopped && cState.ExitCode == nil { - err := s.Runtime().UpdateContainerStatus(c) + err := s.Runtime().UpdateContainerStatus(ctx, c) if err != nil { log.Warnf(ctx, "Failed to UpdateStatus of container %s: %v", c.ID(), err) } diff --git a/server/container_update_resources.go b/server/container_update_resources.go index 5abcb0dc676..b42f32f5912 100644 --- a/server/container_update_resources.go +++ b/server/container_update_resources.go @@ -25,7 +25,7 @@ func (s *Server) UpdateContainerResources(ctx context.Context, req *types.Update if req.Linux != nil { resources := toOCIResources(req.Linux) - if err := s.Runtime().UpdateContainer(c, resources); err != nil { + if err := s.Runtime().UpdateContainer(ctx, c, resources); err != nil { return err } diff --git a/server/sandbox_list_test.go b/server/sandbox_list_test.go index 892769392be..457d6a4a2cc 100644 --- a/server/sandbox_list_test.go +++ b/server/sandbox_list_test.go @@ -75,7 +75,7 @@ var _ = t.Describe("ListPodSandbox", func() { // Given mockDirs(testManifest) createDummyState() - Expect(sut.LoadSandbox(sandboxID)).To(BeNil()) + Expect(sut.LoadSandbox(context.Background(), sandboxID)).To(BeNil()) // When response, err := sut.ListPodSandbox(context.Background(), @@ -93,7 +93,7 @@ var _ = t.Describe("ListPodSandbox", func() { // Given mockDirs(testManifest) createDummyState() - Expect(sut.LoadSandbox(sandboxID)).To(BeNil()) + Expect(sut.LoadSandbox(context.Background(), sandboxID)).To(BeNil()) // When response, err := sut.ListPodSandbox(context.Background(), @@ -114,7 +114,7 @@ var _ = t.Describe("ListPodSandbox", func() { // Given mockDirs(testManifest) createDummyState() - Expect(sut.LoadSandbox(sandboxID)).To(BeNil()) + Expect(sut.LoadSandbox(context.Background(), sandboxID)).To(BeNil()) // When response, err := sut.ListPodSandbox(context.Background(), diff --git a/server/sandbox_remove.go b/server/sandbox_remove.go index c37ee1d776f..15f4f2066a1 100644 --- a/server/sandbox_remove.go +++ b/server/sandbox_remove.go @@ -53,7 +53,7 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *types.RemovePodSandb } } - if err := s.Runtime().DeleteContainer(c); err != nil { + if err := s.Runtime().DeleteContainer(ctx, c); err != nil { return fmt.Errorf("failed to delete container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err) } diff --git a/server/sandbox_run_linux.go b/server/sandbox_run_linux.go index 2c663f399f5..d0784cf4f38 100644 --- a/server/sandbox_run_linux.go +++ b/server/sandbox_run_linux.go @@ -909,11 +909,11 @@ func (s *Server) runPodSandbox(ctx context.Context, req *types.RunPodSandboxRequ } } - if err := s.createContainerPlatform(container, sb.CgroupParent(), sandboxIDMappings); err != nil { + if err := s.createContainerPlatform(ctx, container, sb.CgroupParent(), sandboxIDMappings); err != nil { return nil, err } - if err := s.Runtime().StartContainer(container); err != nil { + if err := s.Runtime().StartContainer(ctx, container); err != nil { return nil, err } @@ -927,16 +927,16 @@ func (s *Server) runPodSandbox(ctx context.Context, req *types.RunPodSandboxRequ log.Warnf(ctx, "failed to get container 'stopped' status %s in pod sandbox %s: %v", container.Name(), sb.ID(), err2) } log.Infof(ctx, "runSandbox: deleting container %s", container.ID()) - if err2 := s.Runtime().DeleteContainer(container); err2 != nil { + if err2 := s.Runtime().DeleteContainer(ctx, container); err2 != nil { log.Warnf(ctx, "failed to delete container %s in pod sandbox %s: %v", container.Name(), sb.ID(), err2) } log.Infof(ctx, "runSandbox: writing container %s state to disk", container.ID()) - if err2 := s.ContainerStateToDisk(container); err2 != nil { + if err2 := s.ContainerStateToDisk(ctx, container); err2 != nil { log.Warnf(ctx, "failed to write container state %s in pod sandbox %s: %v", container.Name(), sb.ID(), err2) } }) - if err := s.ContainerStateToDisk(container); err != nil { + if err := s.ContainerStateToDisk(ctx, container); err != nil { log.Warnf(ctx, "unable to write containers %s state to disk: %v", container.ID(), err) } diff --git a/server/sandbox_stop_linux.go b/server/sandbox_stop_linux.go index 236166e53dc..594e5f247b0 100644 --- a/server/sandbox_stop_linux.go +++ b/server/sandbox_stop_linux.go @@ -81,7 +81,7 @@ func (s *Server) stopPodSandbox(ctx context.Context, req *types.StopPodSandboxRe // assume container already umounted log.Warnf(ctx, "failed to stop container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err) } - if err := s.ContainerStateToDisk(c); err != nil { + if err := s.ContainerStateToDisk(ctx, c); err != nil { return errors.Wrapf(err, "write container %q state do disk", c.Name()) } return nil @@ -114,7 +114,7 @@ func (s *Server) stopPodSandbox(ctx context.Context, req *types.StopPodSandboxRe if err := s.StorageRuntimeServer().StopContainer(sb.ID()); err != nil && !errors.Is(err, storage.ErrContainerUnknown) { log.Warnf(ctx, "failed to stop sandbox container in pod sandbox %s: %v", sb.ID(), err) } - if err := s.ContainerStateToDisk(podInfraContainer); err != nil { + if err := s.ContainerStateToDisk(ctx, podInfraContainer); err != nil { log.Warnf(ctx, "error writing pod infra container %q state to disk: %v", podInfraContainer.ID(), err) } diff --git a/server/server.go b/server/server.go index dedca83ef46..23daea33019 100644 --- a/server/server.go +++ b/server/server.go @@ -47,6 +47,7 @@ var errSandboxNotCreated = errors.New("sandbox not created") // StreamService implements streaming.Runtime. type StreamService struct { + ctx context.Context runtimeServer *Server // needed by Exec() endpoint streamServer streaming.Server streamServerCloseCh chan struct{} @@ -187,7 +188,7 @@ func (s *Server) restore(ctx context.Context) { // Go through all the pods and check if it can be restored. If an error occurs, delete the pod and any containers // associated with it. Release the pod and container names as well. for sbID, metadata := range pods { - if err = s.LoadSandbox(sbID); err == nil { + if err = s.LoadSandbox(ctx, sbID); err == nil { continue } logrus.Warnf("could not restore sandbox %s container %s: %v", metadata.PodID, sbID, err) @@ -222,7 +223,7 @@ func (s *Server) restore(ctx context.Context) { // Go through all the containers and check if it can be restored. If an error occurs, delete the conainer and // release the name associated with you. for containerID := range podContainers { - if err := s.LoadContainer(containerID); err != nil { + if err := s.LoadContainer(ctx, containerID); err != nil { // containers of other runtimes should not be deleted if err == lib.ErrIsNonCrioContainer { logrus.Infof("ignoring non CRI-O container %s", containerID) @@ -459,8 +460,9 @@ func New( Certificates: []tls.Certificate{cert}, } } + s.stream.ctx = ctx s.stream.runtimeServer = s - s.stream.streamServer, err = streaming.NewServer(streamServerConfig, s.stream) + s.stream.streamServer, err = streaming.NewServer(ctx, streamServerConfig, s.stream) if err != nil { return nil, fmt.Errorf("unable to create streaming server") } @@ -606,7 +608,7 @@ func (s *Server) MonitorsCloseChan() chan struct{} { // StartExitMonitor start a routine that monitors container exits // and updates the container status -func (s *Server) StartExitMonitor() { +func (s *Server) StartExitMonitor(ctx context.Context) { watcher, err := fsnotify.NewWatcher() if err != nil { logrus.Fatalf("Failed to create new watch: %v", err) @@ -625,10 +627,10 @@ func (s *Server) StartExitMonitor() { c := s.GetContainer(containerID) if c != nil { logrus.Debugf("container exited and found: %v", containerID) - err := s.Runtime().UpdateContainerStatus(c) + err := s.Runtime().UpdateContainerStatus(ctx, c) if err != nil { logrus.Warnf("Failed to update container status %s: %v", containerID, err) - } else if err := s.ContainerStateToDisk(c); err != nil { + } else if err := s.ContainerStateToDisk(ctx, c); err != nil { logrus.Warnf("unable to write containers %s state to disk: %v", c.ID(), err) } } else { @@ -640,10 +642,10 @@ func (s *Server) StartExitMonitor() { continue } logrus.Debugf("sandbox exited and found: %v", containerID) - err := s.Runtime().UpdateContainerStatus(c) + err := s.Runtime().UpdateContainerStatus(ctx, c) if err != nil { logrus.Warnf("Failed to update sandbox infra container status %s: %v", c.ID(), err) - } else if err := s.ContainerStateToDisk(c); err != nil { + } else if err := s.ContainerStateToDisk(ctx, c); err != nil { logrus.Warnf("unable to write containers %s state to disk: %v", c.ID(), err) } } diff --git a/server/server_test.go b/server/server_test.go index 996112423f3..b5b4ecc42e3 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -248,7 +248,7 @@ var _ = t.Describe("Server", func() { It("should succeed", func() { // Given - go sut.StartExitMonitor() + go sut.StartExitMonitor(context.Background()) closeChan := sut.MonitorsCloseChan() Expect(closeChan).NotTo(BeNil()) diff --git a/server/streaming/streaming.go b/server/streaming/streaming.go index a6e63264c73..644b65d0451 100644 --- a/server/streaming/streaming.go +++ b/server/streaming/streaming.go @@ -20,6 +20,7 @@ limitations under the License. package streaming import ( + "context" "crypto/tls" "errors" "io" @@ -106,7 +107,7 @@ var DefaultConfig = Config{ // NewServer creates a new Server for stream requests. // TODO(tallclair): Add auth(n/z) interface & handling. -func NewServer(config Config, runtime Runtime) (Server, error) { // nolint +func NewServer(ctx context.Context, config Config, runtime Runtime) (Server, error) { // nolint s := &server{ config: config, runtime: &criAdapter{runtime}, diff --git a/test/mocks/oci/oci.go b/test/mocks/oci/oci.go index 635539bbe3f..ed4b13a7e4a 100644 --- a/test/mocks/oci/oci.go +++ b/test/mocks/oci/oci.go @@ -39,103 +39,103 @@ func (m *MockRuntimeImpl) EXPECT() *MockRuntimeImplMockRecorder { } // AttachContainer mocks base method -func (m *MockRuntimeImpl) AttachContainer(arg0 *oci.Container, arg1 io.Reader, arg2, arg3 io.WriteCloser, arg4 bool, arg5 <-chan remotecommand.TerminalSize) error { +func (m *MockRuntimeImpl) AttachContainer(arg0 context.Context, arg1 *oci.Container, arg2 io.Reader, arg3, arg4 io.WriteCloser, arg5 bool, arg6 <-chan remotecommand.TerminalSize) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AttachContainer", arg0, arg1, arg2, arg3, arg4, arg5) + ret := m.ctrl.Call(m, "AttachContainer", arg0, arg1, arg2, arg3, arg4, arg5, arg6) ret0, _ := ret[0].(error) return ret0 } // AttachContainer indicates an expected call of AttachContainer -func (mr *MockRuntimeImplMockRecorder) AttachContainer(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) AttachContainer(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AttachContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).AttachContainer), arg0, arg1, arg2, arg3, arg4, arg5) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AttachContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).AttachContainer), arg0, arg1, arg2, arg3, arg4, arg5, arg6) } // ContainerStats mocks base method -func (m *MockRuntimeImpl) ContainerStats(arg0 *oci.Container, arg1 string) (*oci.ContainerStats, error) { +func (m *MockRuntimeImpl) ContainerStats(arg0 context.Context, arg1 *oci.Container, arg2 string) (*oci.ContainerStats, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ContainerStats", arg0, arg1) + ret := m.ctrl.Call(m, "ContainerStats", arg0, arg1, arg2) ret0, _ := ret[0].(*oci.ContainerStats) ret1, _ := ret[1].(error) return ret0, ret1 } // ContainerStats indicates an expected call of ContainerStats -func (mr *MockRuntimeImplMockRecorder) ContainerStats(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) ContainerStats(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerStats", reflect.TypeOf((*MockRuntimeImpl)(nil).ContainerStats), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerStats", reflect.TypeOf((*MockRuntimeImpl)(nil).ContainerStats), arg0, arg1, arg2) } // CreateContainer mocks base method -func (m *MockRuntimeImpl) CreateContainer(arg0 *oci.Container, arg1 string) error { +func (m *MockRuntimeImpl) CreateContainer(arg0 context.Context, arg1 *oci.Container, arg2 string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateContainer", arg0, arg1) + ret := m.ctrl.Call(m, "CreateContainer", arg0, arg1, arg2) ret0, _ := ret[0].(error) return ret0 } // CreateContainer indicates an expected call of CreateContainer -func (mr *MockRuntimeImplMockRecorder) CreateContainer(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) CreateContainer(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).CreateContainer), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).CreateContainer), arg0, arg1, arg2) } // DeleteContainer mocks base method -func (m *MockRuntimeImpl) DeleteContainer(arg0 *oci.Container) error { +func (m *MockRuntimeImpl) DeleteContainer(arg0 context.Context, arg1 *oci.Container) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteContainer", arg0) + ret := m.ctrl.Call(m, "DeleteContainer", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } // DeleteContainer indicates an expected call of DeleteContainer -func (mr *MockRuntimeImplMockRecorder) DeleteContainer(arg0 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) DeleteContainer(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).DeleteContainer), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).DeleteContainer), arg0, arg1) } // ExecContainer mocks base method -func (m *MockRuntimeImpl) ExecContainer(arg0 *oci.Container, arg1 []string, arg2 io.Reader, arg3, arg4 io.WriteCloser, arg5 bool, arg6 <-chan remotecommand.TerminalSize) error { +func (m *MockRuntimeImpl) ExecContainer(arg0 context.Context, arg1 *oci.Container, arg2 []string, arg3 io.Reader, arg4, arg5 io.WriteCloser, arg6 bool, arg7 <-chan remotecommand.TerminalSize) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExecContainer", arg0, arg1, arg2, arg3, arg4, arg5, arg6) + ret := m.ctrl.Call(m, "ExecContainer", arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ret0, _ := ret[0].(error) return ret0 } // ExecContainer indicates an expected call of ExecContainer -func (mr *MockRuntimeImplMockRecorder) ExecContainer(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) ExecContainer(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).ExecContainer), arg0, arg1, arg2, arg3, arg4, arg5, arg6) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).ExecContainer), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) } // ExecSyncContainer mocks base method -func (m *MockRuntimeImpl) ExecSyncContainer(arg0 *oci.Container, arg1 []string, arg2 int64) (*oci.ExecSyncResponse, error) { +func (m *MockRuntimeImpl) ExecSyncContainer(arg0 context.Context, arg1 *oci.Container, arg2 []string, arg3 int64) (*oci.ExecSyncResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExecSyncContainer", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "ExecSyncContainer", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(*oci.ExecSyncResponse) ret1, _ := ret[1].(error) return ret0, ret1 } // ExecSyncContainer indicates an expected call of ExecSyncContainer -func (mr *MockRuntimeImplMockRecorder) ExecSyncContainer(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) ExecSyncContainer(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecSyncContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).ExecSyncContainer), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecSyncContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).ExecSyncContainer), arg0, arg1, arg2, arg3) } // PauseContainer mocks base method -func (m *MockRuntimeImpl) PauseContainer(arg0 *oci.Container) error { +func (m *MockRuntimeImpl) PauseContainer(arg0 context.Context, arg1 *oci.Container) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PauseContainer", arg0) + ret := m.ctrl.Call(m, "PauseContainer", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } // PauseContainer indicates an expected call of PauseContainer -func (mr *MockRuntimeImplMockRecorder) PauseContainer(arg0 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) PauseContainer(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PauseContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).PauseContainer), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PauseContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).PauseContainer), arg0, arg1) } // PortForwardContainer mocks base method @@ -153,45 +153,45 @@ func (mr *MockRuntimeImplMockRecorder) PortForwardContainer(arg0, arg1, arg2, ar } // ReopenContainerLog mocks base method -func (m *MockRuntimeImpl) ReopenContainerLog(arg0 *oci.Container) error { +func (m *MockRuntimeImpl) ReopenContainerLog(arg0 context.Context, arg1 *oci.Container) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ReopenContainerLog", arg0) + ret := m.ctrl.Call(m, "ReopenContainerLog", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } // ReopenContainerLog indicates an expected call of ReopenContainerLog -func (mr *MockRuntimeImplMockRecorder) ReopenContainerLog(arg0 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) ReopenContainerLog(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReopenContainerLog", reflect.TypeOf((*MockRuntimeImpl)(nil).ReopenContainerLog), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReopenContainerLog", reflect.TypeOf((*MockRuntimeImpl)(nil).ReopenContainerLog), arg0, arg1) } // SignalContainer mocks base method -func (m *MockRuntimeImpl) SignalContainer(arg0 *oci.Container, arg1 syscall.Signal) error { +func (m *MockRuntimeImpl) SignalContainer(arg0 context.Context, arg1 *oci.Container, arg2 syscall.Signal) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SignalContainer", arg0, arg1) + ret := m.ctrl.Call(m, "SignalContainer", arg0, arg1, arg2) ret0, _ := ret[0].(error) return ret0 } // SignalContainer indicates an expected call of SignalContainer -func (mr *MockRuntimeImplMockRecorder) SignalContainer(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) SignalContainer(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SignalContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).SignalContainer), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SignalContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).SignalContainer), arg0, arg1, arg2) } // StartContainer mocks base method -func (m *MockRuntimeImpl) StartContainer(arg0 *oci.Container) error { +func (m *MockRuntimeImpl) StartContainer(arg0 context.Context, arg1 *oci.Container) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StartContainer", arg0) + ret := m.ctrl.Call(m, "StartContainer", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } // StartContainer indicates an expected call of StartContainer -func (mr *MockRuntimeImplMockRecorder) StartContainer(arg0 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) StartContainer(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).StartContainer), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).StartContainer), arg0, arg1) } // StopContainer mocks base method @@ -209,45 +209,45 @@ func (mr *MockRuntimeImplMockRecorder) StopContainer(arg0, arg1, arg2 interface{ } // UnpauseContainer mocks base method -func (m *MockRuntimeImpl) UnpauseContainer(arg0 *oci.Container) error { +func (m *MockRuntimeImpl) UnpauseContainer(arg0 context.Context, arg1 *oci.Container) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UnpauseContainer", arg0) + ret := m.ctrl.Call(m, "UnpauseContainer", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } // UnpauseContainer indicates an expected call of UnpauseContainer -func (mr *MockRuntimeImplMockRecorder) UnpauseContainer(arg0 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) UnpauseContainer(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnpauseContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).UnpauseContainer), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnpauseContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).UnpauseContainer), arg0, arg1) } // UpdateContainer mocks base method -func (m *MockRuntimeImpl) UpdateContainer(arg0 *oci.Container, arg1 *specs.LinuxResources) error { +func (m *MockRuntimeImpl) UpdateContainer(arg0 context.Context, arg1 *oci.Container, arg2 *specs.LinuxResources) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateContainer", arg0, arg1) + ret := m.ctrl.Call(m, "UpdateContainer", arg0, arg1, arg2) ret0, _ := ret[0].(error) return ret0 } // UpdateContainer indicates an expected call of UpdateContainer -func (mr *MockRuntimeImplMockRecorder) UpdateContainer(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) UpdateContainer(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).UpdateContainer), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateContainer", reflect.TypeOf((*MockRuntimeImpl)(nil).UpdateContainer), arg0, arg1, arg2) } // UpdateContainerStatus mocks base method -func (m *MockRuntimeImpl) UpdateContainerStatus(arg0 *oci.Container) error { +func (m *MockRuntimeImpl) UpdateContainerStatus(arg0 context.Context, arg1 *oci.Container) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateContainerStatus", arg0) + ret := m.ctrl.Call(m, "UpdateContainerStatus", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } // UpdateContainerStatus indicates an expected call of UpdateContainerStatus -func (mr *MockRuntimeImplMockRecorder) UpdateContainerStatus(arg0 interface{}) *gomock.Call { +func (mr *MockRuntimeImplMockRecorder) UpdateContainerStatus(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateContainerStatus", reflect.TypeOf((*MockRuntimeImpl)(nil).UpdateContainerStatus), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateContainerStatus", reflect.TypeOf((*MockRuntimeImpl)(nil).UpdateContainerStatus), arg0, arg1) } // WaitContainerStateStopped mocks base method