diff --git a/internal/factory/container/container.go b/internal/factory/container/container.go index 4d5ab9a4740..1c4960b6830 100644 --- a/internal/factory/container/container.go +++ b/internal/factory/container/container.go @@ -95,7 +95,7 @@ type Container interface { SpecAddMount(rspec.Mount) // SpecAddAnnotations adds annotations to the spec. - SpecAddAnnotations(ctx context.Context, sandbox *sandbox.Sandbox, containerVolume []oci.ContainerVolume, mountPoint, configStopSignal string, imageResult *storage.ImageResult, isSystemd, systemdHasCollectMode bool) error + SpecAddAnnotations(ctx context.Context, sandbox *sandbox.Sandbox, criMounts []*types.Mount, mountPoint, configStopSignal string, imageResult *storage.ImageResult, isSystemd, systemdHasCollectMode bool) error // SpecAddDevices adds devices from the server config, and container CRI config SpecAddDevices([]device.Device, []device.Device, bool, bool) error @@ -150,7 +150,7 @@ func (c *container) SpecAddMount(r rspec.Mount) { } // SpecAddAnnotation adds all annotations to the spec -func (c *container) SpecAddAnnotations(ctx context.Context, sb *sandbox.Sandbox, containerVolumes []oci.ContainerVolume, mountPoint, configStopSignal string, imageResult *storage.ImageResult, isSystemd, systemdHasCollectMode bool) (err error) { +func (c *container) SpecAddAnnotations(ctx context.Context, sb *sandbox.Sandbox, criMounts []*types.Mount, mountPoint, configStopSignal string, imageResult *storage.ImageResult, isSystemd, systemdHasCollectMode bool) (err error) { // Copied from k8s.io/kubernetes/pkg/kubelet/kuberuntime/labels.go const podTerminationGracePeriodLabel = "io.kubernetes.pod.terminationGracePeriod" @@ -227,7 +227,7 @@ func (c *container) SpecAddAnnotations(ctx context.Context, sb *sandbox.Sandbox, } c.spec.AddAnnotation(annotations.Labels, string(labelsJSON)) - volumesJSON, err := json.Marshal(containerVolumes) + volumesJSON, err := json.Marshal(criMounts) if err != nil { return err } diff --git a/internal/factory/container/container_test.go b/internal/factory/container/container_test.go index b2857c170cd..185b42c4f88 100644 --- a/internal/factory/container/container_test.go +++ b/internal/factory/container/container_test.go @@ -12,7 +12,6 @@ import ( "github.com/cri-o/cri-o/internal/hostport" "github.com/cri-o/cri-o/internal/lib" "github.com/cri-o/cri-o/internal/lib/sandbox" - oci "github.com/cri-o/cri-o/internal/oci" "github.com/cri-o/cri-o/internal/storage" crioann "github.com/cri-o/cri-o/pkg/annotations" . "github.com/onsi/ginkgo/v2" @@ -85,7 +84,7 @@ var _ = t.Describe("Container", func() { err := sut.SetConfig(containerConfig, sandboxConfig) Expect(err).To(BeNil()) currentTime := time.Now() - volumes := []oci.ContainerVolume{} + mounts := []*types.Mount{} imageResult := storage.ImageResult{} mountPoint := "test" configStopSignal := "test" @@ -108,7 +107,7 @@ var _ = t.Describe("Container", func() { labelsJSON, err := json.Marshal(sut.Config().Labels) Expect(err).To(BeNil()) - volumesJSON, err := json.Marshal(volumes) + mountsJSON, err := json.Marshal(mounts) Expect(err).To(BeNil()) kubeAnnotationsJSON, err := json.Marshal(sut.Config().Annotations) @@ -117,7 +116,7 @@ var _ = t.Describe("Container", func() { Expect(currentTime).ToNot(BeNil()) Expect(sb).ToNot(BeNil()) - err = sut.SpecAddAnnotations(context.Background(), sb, volumes, mountPoint, configStopSignal, &imageResult, false, false) + err = sut.SpecAddAnnotations(context.Background(), sb, mounts, mountPoint, configStopSignal, &imageResult, false, false) Expect(err).To(BeNil()) Expect(sut.Spec().Config.Annotations[annotations.Image]).To(Equal(image)) @@ -139,7 +138,7 @@ var _ = t.Describe("Container", func() { Expect(sut.Spec().Config.Annotations[annotations.Created]).ToNot(BeNil()) Expect(sut.Spec().Config.Annotations[annotations.Metadata]).To(Equal(string(metadataJSON))) Expect(sut.Spec().Config.Annotations[annotations.Labels]).To(Equal(string(labelsJSON))) - Expect(sut.Spec().Config.Annotations[annotations.Volumes]).To(Equal(string(volumesJSON))) + Expect(sut.Spec().Config.Annotations[annotations.Volumes]).To(Equal(string(mountsJSON))) Expect(sut.Spec().Config.Annotations[annotations.Annotations]).To(Equal(string(kubeAnnotationsJSON))) }) }) diff --git a/internal/lib/container_server.go b/internal/lib/container_server.go index 25e17016578..da3162b6daf 100644 --- a/internal/lib/container_server.go +++ b/internal/lib/container_server.go @@ -268,12 +268,12 @@ func (c *ContainerServer) LoadSandbox(ctx context.Context, id string) (sb *sandb scontainer.SetMountPoint(m.Annotations[annotations.MountPoint]) if m.Annotations[annotations.Volumes] != "" { - containerVolumes := []oci.ContainerVolume{} - if err = json.Unmarshal([]byte(m.Annotations[annotations.Volumes]), &containerVolumes); err != nil { + criMounts := []*types.Mount{} + if err = json.Unmarshal([]byte(m.Annotations[annotations.Volumes]), &criMounts); err != nil { return sb, fmt.Errorf("failed to unmarshal container volumes: %w", err) } - for _, cv := range containerVolumes { - scontainer.AddVolume(cv) + for _, cv := range criMounts { + scontainer.AddMount(cv) } } diff --git a/internal/oci/container.go b/internal/oci/container.go index 8d0d6fad485..70f77154733 100644 --- a/internal/oci/container.go +++ b/internal/oci/container.go @@ -33,6 +33,10 @@ const ( statStartTimeLocation = 22 // The 2nd field is the command, wrapped by () statCommField = 2 + + oomKilledReason = "OOMKilled" + completedReason = "Completed" + errorReason = "Error" ) var ( @@ -44,7 +48,8 @@ var ( // Container represents a runtime container. type Container struct { criContainer *types.Container - volumes []ContainerVolume + criStatus *types.ContainerStatus + criLock sync.RWMutex name string logPath string runtimeHandler string @@ -126,6 +131,19 @@ func NewContainer(id, name, bundlePath, logPath string, labels, crioAnnotations, }, ImageRef: imageRef, }, + criStatus: &types.ContainerStatus{ + Id: id, + CreatedAt: created.UnixNano(), + Metadata: metadata, + Labels: labels, + Annotations: annotations, + ImageRef: imageRef, + Image: &types.ImageSpec{ + Image: imageName, + }, + Mounts: []*types.Mount{}, + LogPath: logPath, + }, name: name, bundlePath: bundlePath, logPath: logPath, @@ -173,21 +191,21 @@ func (c *Container) CRIContainer() *types.Container { // If a protobuf message gets mutated mid-request, then the proto library panics. // We would like to avoid deep copies when possible to avoid excessive garbage // collection, but need to if the container changes state. - newState := types.ContainerState_CONTAINER_UNKNOWN - switch c.StateNoLock().Status { - case ContainerStateCreated: - newState = types.ContainerState_CONTAINER_CREATED - case ContainerStateRunning, ContainerStatePaused: - newState = types.ContainerState_CONTAINER_RUNNING - case ContainerStateStopped: - newState = types.ContainerState_CONTAINER_EXITED - } + return c.criContainer +} + +func (c *Container) CRIStatus() *types.ContainerStatus { + c.criLock.RLock() + defer c.criLock.RUnlock() + return c.criStatus +} + +func (c *Container) updateCRIContainerState(newState types.ContainerState) { if newState != c.criContainer.State { cpy := *c.criContainer cpy.State = newState c.criContainer = &cpy } - return c.criContainer } // SetSpec loads the OCI spec in the container struct @@ -281,11 +299,6 @@ func (c *Container) StatePath() string { return filepath.Join(c.dir, "state.json") } -// CreatedAt returns the container creation time -func (c *Container) CreatedAt() time.Time { - return c.state.Created -} - // Name returns the name of the container. func (c *Container) Name() string { return c.name @@ -392,14 +405,18 @@ func (c *Container) StateNoLock() *ContainerState { return c.state } -// AddVolume adds a volume to list of container volumes. -func (c *Container) AddVolume(v ContainerVolume) { - c.volumes = append(c.volumes, v) +// AddMount adds a mount to list of container mounts. +func (c *Container) AddMount(m *types.Mount) { + c.criLock.Lock() + c.criStatus.Mounts = append(c.criStatus.Mounts, m) + c.criLock.Unlock() } -// Volumes returns the list of container volumes. -func (c *Container) Volumes() []ContainerVolume { - return c.volumes +// Mounts returns the list of container mounts. +func (c *Container) Mounts() []*types.Mount { + c.criLock.RLock() + defer c.criLock.RUnlock() + return c.criStatus.Mounts } // SetMountPoint sets the container mount point @@ -432,14 +449,56 @@ func (c *Container) Created() bool { return c.created } +func (c *Container) SetStarted() { + started := time.Now() + c.state.Started = started + + c.criLock.Lock() + defer c.criLock.Unlock() + c.updateCRIContainerState(types.ContainerState_CONTAINER_RUNNING) + + cpy := *c.criStatus + cpy.State = types.ContainerState_CONTAINER_RUNNING + cpy.StartedAt = started.UnixNano() + c.criStatus = &cpy +} + +func (c *Container) SetStopped(finishedTime time.Time, exitCode int32, oomKilled bool) { + c.state.ExitCode = &exitCode + + c.criLock.Lock() + defer c.criLock.Unlock() + + c.updateCRIContainerState(types.ContainerState_CONTAINER_EXITED) + + cpy := *c.criStatus + if cpy.StartedAt == 0 { + cpy.StartedAt = finishedTime.UnixNano() + } + + cpy.FinishedAt = finishedTime.UnixNano() + cpy.ExitCode = exitCode + switch { + case oomKilled: + cpy.Reason = oomKilledReason + case cpy.ExitCode == 0: + cpy.Reason = completedReason + default: + cpy.Reason = errorReason + cpy.Message = c.state.Error // TODO FIXME + } + c.criStatus = &cpy +} + // SetStartFailed sets the container state appropriately after a start failure func (c *Container) SetStartFailed(err error) { c.opLock.Lock() defer c.opLock.Unlock() // adjust finished and started times c.state.Finished, c.state.Started = c.state.Created, c.state.Created + c.SetStopped(c.state.Created, 0, false) if err != nil { - c.state.Error = err.Error() + c.state.Error = err.Error() // TODO FIXME } } diff --git a/internal/oci/container_test.go b/internal/oci/container_test.go index 174f8ba4061..e9d916b0315 100644 --- a/internal/oci/container_test.go +++ b/internal/oci/container_test.go @@ -89,16 +89,16 @@ var _ = t.Describe("Container", func() { Expect(sut.IDMappings()).To(Equal(mappings)) }) - It("should succeed to add a volume", func() { + It("should succeed to add a mount", func() { // Given - volume := oci.ContainerVolume{ContainerPath: "/"} + mount := &types.Mount{ContainerPath: "/"} // When - sut.AddVolume(volume) + sut.AddMount(mount) // Then - Expect(len(sut.Volumes())).To(BeEquivalentTo(1)) - Expect(sut.Volumes()[0]).To(Equal(volume)) + Expect(len(sut.Mounts())).To(BeEquivalentTo(1)) + Expect(sut.Mounts()[0]).To(Equal(mount)) }) It("should succeed to set the seccomp profile path", func() { diff --git a/internal/oci/runtime_oci.go b/internal/oci/runtime_oci.go index 1dee2973adf..694f8ca741a 100644 --- a/internal/oci/runtime_oci.go +++ b/internal/oci/runtime_oci.go @@ -280,7 +280,7 @@ func (r *runtimeOCI) StartContainer(ctx context.Context, c *Container) error { ); err != nil { return err } - c.state.Started = time.Now() + c.SetStarted() return nil } @@ -791,7 +791,6 @@ func WaitContainerStop(ctx context.Context, c *Container, timeout time.Duration, timeout = newTimeout } } - c.state.Finished = time.Now() // Successfully stopped! This is to prevent other routines from // racing with this one and waiting forever. // Close only the dedicated channel. If we close stopTimeoutChan, @@ -826,14 +825,13 @@ func (r *runtimeOCI) StopContainer(ctx context.Context, c *Container, timeout in } if c.Spoofed() { - c.state.Status = ContainerStateStopped - c.state.Finished = time.Now() + c.SetStopped(time.Now(), 0, false) return nil } // The initial container process either doesn't exist, or isn't ours. if err := c.verifyPid(); err != nil { - c.state.Finished = time.Now() + c.SetStopped(time.Now(), 0, false) return nil } @@ -841,7 +839,7 @@ func (r *runtimeOCI) StopContainer(ctx context.Context, c *Container, timeout in if _, err := utils.ExecCmd( r.handler.RuntimePath, rootFlag, r.root, "kill", c.ID(), c.GetStopSignal(), ); err != nil { - checkProcessGone(c) + log.Debugf(ctx, "Failed to kill container %s with stop signal %s: %v", c.ID(), c.GetStopSignal(), err) } err := WaitContainerStop(ctx, c, time.Duration(timeout)*time.Second, true) if err == nil { @@ -853,20 +851,12 @@ func (r *runtimeOCI) StopContainer(ctx context.Context, c *Container, timeout in if _, err := utils.ExecCmd( r.handler.RuntimePath, rootFlag, r.root, "kill", c.ID(), "KILL", ); err != nil { - checkProcessGone(c) + log.Debugf(ctx, "Failed to kill container %s with stop signal %s: %v", c.ID(), c.GetStopSignal(), err) } return WaitContainerStop(ctx, c, killContainerTimeout, false) } -func checkProcessGone(c *Container) { - if err := c.verifyPid(); err != nil { - // The initial container process either doesn't exist, or isn't ours. - // Set state accordingly. - c.state.Finished = time.Now() - } -} - // DeleteContainer deletes a container. func (r *runtimeOCI) DeleteContainer(ctx context.Context, c *Container) error { c.opLock.Lock() @@ -886,7 +876,7 @@ func updateContainerStatusFromExitFile(c *Container) error { if err != nil { return fmt.Errorf("failed to find container exit file for %s: %w", c.ID(), err) } - c.state.Finished, err = getFinishedTime(fi) + finished, err := getFinishedTime(fi) if err != nil { return fmt.Errorf("failed to get finished time: %w", err) } @@ -898,7 +888,19 @@ func updateContainerStatusFromExitFile(c *Container) error { if err != nil { return fmt.Errorf("status code conversion failed: %w", err) } - c.state.ExitCode = utils.Int32Ptr(int32(statusCode)) + + oomKilled := false + if _, err = os.Stat(filepath.Join(c.bundlePath, "oom")); err == nil { + oomKilled = true + + // Collect total metric + metrics.Instance().MetricContainersOOMTotalInc() + + // Collect metric by container name + metrics.Instance().MetricContainersOOMCountTotalInc(c.Name()) + } + + c.SetStopped(finished, int32(statusCode), oomKilled) return nil } @@ -934,10 +936,8 @@ func (r *runtimeOCI) UpdateContainerStatus(ctx context.Context, c *Container) er } else { log.Errorf(ctx, "Failed to update container state for %s: %v", c.ID(), err) } - c.state.Status = ContainerStateStopped if err := updateContainerStatusFromExitFile(c); err != nil { - c.state.Finished = time.Now() - c.state.ExitCode = utils.Int32Ptr(255) + c.SetStopped(time.Now(), -1, false) } return nil, true, nil } @@ -956,7 +956,7 @@ func (r *runtimeOCI) UpdateContainerStatus(ctx context.Context, c *Container) er } if state.Status != ContainerStateStopped { - *c.state = *state + c.state.Status = state.Status return nil } // release the lock before waiting @@ -985,7 +985,7 @@ func (r *runtimeOCI) UpdateContainerStatus(ctx context.Context, c *Container) er if state == nil { return fmt.Errorf("state command returned nil") } - *c.state = *state + c.state.Status = state.Status if err != nil { log.Warnf(ctx, "Failed to find container exit file for %v: %v", c.ID(), err) } else { @@ -995,16 +995,6 @@ func (r *runtimeOCI) UpdateContainerStatus(ctx context.Context, c *Container) er log.Debugf(ctx, "Found exit code for %s: %d", c.ID(), *c.state.ExitCode) } - oomFilePath := filepath.Join(c.bundlePath, "oom") - if _, err = os.Stat(oomFilePath); err == nil { - c.state.OOMKilled = true - - // Collect total metric - metrics.Instance().MetricContainersOOMTotalInc() - - // Collect metric by container name - metrics.Instance().MetricContainersOOMCountTotalInc(c.Name()) - } // If this container had a node level PID namespace, then any children processes will be leaked to init. // Eventually, the processes will get cleaned up when the pod cgroup is cleaned by the kubelet, // but this situation is atypical and should be avoided. diff --git a/internal/oci/runtime_vm.go b/internal/oci/runtime_vm.go index cf7cb765bcd..3c500e18823 100644 --- a/internal/oci/runtime_vm.go +++ b/internal/oci/runtime_vm.go @@ -261,7 +261,7 @@ func (r *runtimeVM) StartContainer(ctx context.Context, c *Container) error { if err := r.start(c.ID(), ""); err != nil { return err } - c.state.Started = time.Now() + c.SetStarted() // Spawn a goroutine waiting for the container to terminate. Once it // happens, the container status is retrieved to be updated. @@ -675,15 +675,14 @@ func (r *runtimeVM) updateContainerStatus(ctx context.Context, c *Container) err } c.state.Status = status - c.state.Finished = response.ExitedAt exitCode := int32(response.ExitStatus) - c.state.ExitCode = &exitCode c.state.Pid = int(response.Pid) + oomKilled := false if exitCode != 0 { oomFilePath := filepath.Join(c.bundlePath, "oom") if _, err = os.Stat(oomFilePath); err == nil { - c.state.OOMKilled = true + oomKilled = true // Collect total metric metrics.Instance().MetricContainersOOMTotalInc() @@ -692,6 +691,11 @@ func (r *runtimeVM) updateContainerStatus(ctx context.Context, c *Container) err metrics.Instance().MetricContainersOOMCountTotalInc(c.Name()) } } + + if status == ContainerStateStopped { + c.SetStopped(response.ExitedAt, exitCode, oomKilled) + } + return nil } diff --git a/server/container_create_linux.go b/server/container_create_linux.go index deebb81f685..78e3513869f 100644 --- a/server/container_create_linux.go +++ b/server/container_create_linux.go @@ -315,7 +315,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr ctrfactory.Cont cgroup2RW := node.CgroupIsV2() && sb.Annotations()[crioann.Cgroup2RWAnnotation] == "true" - containerVolumes, ociMounts, err := addOCIBindMounts(ctx, ctr, mountLabel, s.config.RuntimeConfig.BindMountPrefix, s.config.AbsentMountSourcesToReject, maybeRelabel, skipRelabel, cgroup2RW) + criMounts, ociMounts, err := addOCIBindMounts(ctx, ctr, mountLabel, s.config.RuntimeConfig.BindMountPrefix, s.config.AbsentMountSourcesToReject, maybeRelabel, skipRelabel, cgroup2RW) if err != nil { return nil, err } @@ -658,7 +658,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr ctrfactory.Cont specgen.Config.Linux.IntelRdt = &rspec.LinuxIntelRdt{ClosID: rdt.ResctrlPrefix + rdtClass} } - err = ctr.SpecAddAnnotations(ctx, sb, containerVolumes, mountPoint, containerImageConfig.Config.StopSignal, imgResult, s.config.CgroupManager().IsSystemd(), node.SystemdHasCollectMode()) + err = ctr.SpecAddAnnotations(ctx, sb, criMounts, mountPoint, containerImageConfig.Config.StopSignal, imgResult, s.config.CgroupManager().IsSystemd(), node.SystemdHasCollectMode()) if err != nil { return nil, err } @@ -839,8 +839,8 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr ctrfactory.Cont ociContainer.SetMountPoint(mountPoint) ociContainer.SetSeccompProfilePath(containerConfig.Linux.SecurityContext.SeccompProfilePath) - for _, cv := range containerVolumes { - ociContainer.AddVolume(cv) + for _, cv := range criMounts { + ociContainer.AddMount(cv) } return ociContainer, nil @@ -885,9 +885,9 @@ func clearReadOnly(m *rspec.Mount) { m.Options = append(m.Options, "rw") } -func addOCIBindMounts(ctx context.Context, ctr ctrfactory.Container, mountLabel, bindMountPrefix string, absentMountSourcesToReject []string, maybeRelabel, skipRelabel, cgroup2RW bool) ([]oci.ContainerVolume, []rspec.Mount, error) { - volumes := []oci.ContainerVolume{} - ociMounts := []rspec.Mount{} +func addOCIBindMounts(ctx context.Context, ctr ctrfactory.Container, mountLabel, bindMountPrefix string, absentMountSourcesToReject []string, maybeRelabel, skipRelabel, cgroup2RW bool) (criMounts []*types.Mount, ociMounts []rspec.Mount, _ error) { + criMounts = []*types.Mount{} + ociMounts = []rspec.Mount{} containerConfig := ctr.Config() specgen := ctr.Spec() mounts := containerConfig.Mounts @@ -1002,7 +1002,7 @@ func addOCIBindMounts(ctx context.Context, ctr ctrfactory.Container, mountLabel, } } - volumes = append(volumes, oci.ContainerVolume{ + criMounts = append(criMounts, &types.Mount{ ContainerPath: dest, HostPath: src, Readonly: m.Readonly, @@ -1033,7 +1033,7 @@ func addOCIBindMounts(ctx context.Context, ctr ctrfactory.Container, mountLabel, specgen.AddMount(m) } - return volumes, ociMounts, nil + return criMounts, ociMounts, nil } // mountExists returns true if dest exists in the list of mounts diff --git a/server/container_status.go b/server/container_status.go index 7e40a0431f3..36ff0053bdf 100644 --- a/server/container_status.go +++ b/server/container_status.go @@ -3,7 +3,6 @@ package server import ( "fmt" - "github.com/cri-o/cri-o/internal/log" oci "github.com/cri-o/cri-o/internal/oci" json "github.com/json-iterator/go" spec "github.com/opencontainers/runtime-spec/specs-go" @@ -13,12 +12,6 @@ import ( types "k8s.io/cri-api/pkg/apis/runtime/v1" ) -const ( - oomKilledReason = "OOMKilled" - completedReason = "Completed" - errorReason = "Error" -) - // ContainerStatus returns status of the container. func (s *Server) ContainerStatus(ctx context.Context, req *types.ContainerStatusRequest) (*types.ContainerStatusResponse, error) { c, err := s.GetContainerFromShortID(req.ContainerId) @@ -26,78 +19,10 @@ func (s *Server) ContainerStatus(ctx context.Context, req *types.ContainerStatus return nil, status.Errorf(codes.NotFound, "could not find container %q: %v", req.ContainerId, err) } - containerID := c.ID() resp := &types.ContainerStatusResponse{ - Status: &types.ContainerStatus{ - Id: containerID, - Metadata: c.Metadata(), - Labels: c.Labels(), - Annotations: c.Annotations(), - ImageRef: c.ImageRef(), - Image: &types.ImageSpec{ - Image: c.ImageName(), - }, - }, - } - - mounts := []*types.Mount{} - for _, cv := range c.Volumes() { - mounts = append(mounts, &types.Mount{ - ContainerPath: cv.ContainerPath, - HostPath: cv.HostPath, - Readonly: cv.Readonly, - Propagation: cv.Propagation, - SelinuxRelabel: cv.SelinuxRelabel, - }) - } - resp.Status.Mounts = mounts - - cState := c.StateNoLock() - rStatus := types.ContainerState_CONTAINER_UNKNOWN - - // 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(ctx, c) - if err != nil { - log.Warnf(ctx, "Failed to UpdateStatus of container %s: %v", c.ID(), err) - } - cState = c.State() + Status: c.CRIStatus(), } - resp.Status.CreatedAt = c.CreatedAt().UnixNano() - switch cState.Status { - case oci.ContainerStateCreated: - rStatus = types.ContainerState_CONTAINER_CREATED - case oci.ContainerStateRunning, oci.ContainerStatePaused: - rStatus = types.ContainerState_CONTAINER_RUNNING - started := cState.Started.UnixNano() - resp.Status.StartedAt = started - case oci.ContainerStateStopped: - rStatus = types.ContainerState_CONTAINER_EXITED - started := cState.Started.UnixNano() - resp.Status.StartedAt = started - finished := cState.Finished.UnixNano() - resp.Status.FinishedAt = finished - if cState.ExitCode == nil { - resp.Status.ExitCode = -1 - } else { - resp.Status.ExitCode = *cState.ExitCode - } - switch { - case cState.OOMKilled: - resp.Status.Reason = oomKilledReason - case resp.Status.ExitCode == 0: - resp.Status.Reason = completedReason - default: - resp.Status.Reason = errorReason - resp.Status.Message = cState.Error - } - } - - resp.Status.State = rStatus - resp.Status.LogPath = c.LogPath() - if req.Verbose { info, err := s.createContainerInfo(c) if err != nil { diff --git a/server/container_status_test.go b/server/container_status_test.go index ce21a3722ab..744a535a7b1 100644 --- a/server/container_status_test.go +++ b/server/container_status_test.go @@ -30,7 +30,7 @@ var _ = t.Describe("ContainerStatus", func() { ) { // Given addContainerAndSandbox() - testContainer.AddVolume(oci.ContainerVolume{}) + testContainer.AddMount(&types.Mount{}) testContainer.SetStateAndSpoofPid(givenState) testContainer.SetSpec(&specs.Spec{Version: "1.0.0"})