summaryrefslogtreecommitdiff
path: root/libpod/container.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2020-02-04 16:56:07 -0500
committerMatthew Heon <matthew.heon@pm.me>2020-03-18 11:02:14 -0400
commit118e78c5d69caade9e69a7f9d57dc53eee1840db (patch)
tree660545902a499eccdcd84c78b75f123908606bad /libpod/container.go
parentf138405b46cdeb1cd8848ffc169a355433def9e2 (diff)
downloadpodman-118e78c5d69caade9e69a7f9d57dc53eee1840db.tar.gz
podman-118e78c5d69caade9e69a7f9d57dc53eee1840db.tar.bz2
podman-118e78c5d69caade9e69a7f9d57dc53eee1840db.zip
Add structure for new exec session tracking to DB
As part of the rework of exec sessions, we need to address them independently of containers. In the new API, we need to be able to fetch them by their ID, regardless of what container they are associated with. Unfortunately, our existing exec sessions are tied to individual containers; there's no way to tell what container a session belongs to and retrieve it without getting every exec session for every container. This adds a pointer to the container an exec session is associated with to the database. The sessions themselves are still stored in the container. Exec-related APIs have been restructured to work with the new database representation. The originally monolithic API has been split into a number of smaller calls to allow more fine-grained control of lifecycle. Support for legacy exec sessions has been retained, but in a deprecated fashion; we should remove this in a few releases. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/container.go')
-rw-r--r--libpod/container.go66
1 files changed, 11 insertions, 55 deletions
diff --git a/libpod/container.go b/libpod/container.go
index d3359e24d..89cf83707 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -181,9 +181,13 @@ type ContainerState struct {
PID int `json:"pid,omitempty"`
// ConmonPID is the PID of the container's conmon
ConmonPID int `json:"conmonPid,omitempty"`
- // ExecSessions contains active exec sessions for container
- // Exec session ID is mapped to PID of exec process
- ExecSessions map[string]*ExecSession `json:"execSessions,omitempty"`
+ // ExecSessions contains all exec sessions that are associated with this
+ // container.
+ ExecSessions map[string]*ExecSession `json:"newExecSessions,omitempty"`
+ // LegacyExecSessions are legacy exec sessions from older versions of
+ // Podman.
+ // These are DEPRECATED and will be removed in a future release.
+ LegacyExecSessions map[string]*legacyExecSession `json:"execSessions,omitempty"`
// NetworkStatus contains the configuration results for all networks
// the pod is attached to. Only populated if we created a network
// namespace for the container, and the network namespace is currently
@@ -214,54 +218,6 @@ type ContainerState struct {
containerPlatformState
}
-// ExecSession contains information on an active exec session
-type ExecSession struct {
- // ID is the ID of the exec session.
- ID string `json:"id"`
- // Command the the command that will be invoked in the exec session.
- Command []string `json:"command"`
- // State is the state of the exec session.
- State define.ContainerExecStatus `json:"state"`
- // PID is the PID of the process created by the exec session.
- PID int `json:"pid,omitempty"`
-
- // Terminal is whether the exec session will allocate a pseudoterminal.
- Terminal bool `json:"terminal,omitempty"`
- // AttachStdin is whether the STDIN stream will be forwarded to the exec
- // session's first process when attaching. Only available if Terminal is
- // false.
- AttachStdin bool `json:"attachStdin,omitempty"`
- // AttachStdout is whether the STDOUT stream will be forwarded to the
- // exec session's first process when attaching. Only available if
- // Terminal is false.
- AttachStdout bool `json:"attachStdout,omitempty"`
- // AttachStderr is whether the STDERR stream will be forwarded to the
- // exec session's first process when attaching. Only available if
- // Terminal is false.
- AttachStderr bool `json:"attachStderr,omitempty"`
- // DetachKeys are keys that will be used to detach from the exec
- // session. Here, nil will use the default detach keys, where a pointer
- // to the empty string ("") will disable detaching via detach keys.
- DetachKeys *string `json:"detachKeys,omitempty"`
- // Environment is a set of environment variables that will be set for
- // the first process started by the exec session.
- Environment map[string]string `json:"environment,omitempty"`
- // Privileged is whether the exec session will be privileged - that is,
- // will be granted additional capabilities.
- Privileged bool `json:"privileged,omitempty"`
- // User is the user the exec session will be run as.
- User string `json:"user,omitempty"`
- // WorkDir is the working directory for the first process that will be
- // launched by the exec session.
- WorkDir string `json:"workDir,omitempty"`
- // PreserveFDs indicates that a number of extra FDs from the process
- // running libpod will be passed into the container. These are assumed
- // to begin at 3 (immediately after the standard streams). The number
- // given is the number that will be passed into the exec session,
- // starting at 3.
- PreserveFDs uint `json:"preserveFds,omitempty"`
-}
-
// ContainerConfig contains all information that was used to create the
// container. It may not be changed once created.
// It is stored, read-only, on disk
@@ -973,13 +929,13 @@ func (c *Container) ExecSession(id string) (*ExecSession, error) {
session, ok := c.state.ExecSessions[id]
if !ok {
- return nil, errors.Wrapf(define.ErrNoSuchCtr, "no exec session with ID %s found in container %s", id, c.ID())
+ return nil, errors.Wrapf(define.ErrNoSuchExecSession, "no exec session with ID %s found in container %s", id, c.ID())
}
returnSession := new(ExecSession)
- returnSession.ID = session.ID
- returnSession.Command = session.Command
- returnSession.PID = session.PID
+ if err := JSONDeepCopy(session, returnSession); err != nil {
+ return nil, errors.Wrapf(err, "error copying contents of container %s exec session %s", c.ID(), session.ID())
+ }
return returnSession, nil
}