Add network namespaces to SQL state

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #109
Approved by: mheon
This commit is contained in:
Matthew Heon
2017-12-06 15:54:59 -05:00
committed by Atomic Bot
parent 824a648fcb
commit 0ff92f8e20
4 changed files with 101 additions and 24 deletions

View File

@ -200,6 +200,7 @@ func prepareDB(db *sql.DB) (err error) {
ExitCode INTEGER NOT NULL,
OomKilled INTEGER NOT NULL,
Pid INTEGER NOT NULL,
NetNSPath TEXT NOT NULL,
CHECK (State>0),
CHECK (OomKilled IN (0, 1)),
FOREIGN KEY (Id) REFERENCES containers(Id) DEFERRABLE INITIALLY DEFERRED
@ -296,6 +297,7 @@ func ctrFromScannable(row scannable, runtime *Runtime, specsDir string, lockDir
exitCode int32
oomKilled int
pid int
netNSPath string
)
err := row.Scan(
@ -323,7 +325,8 @@ func ctrFromScannable(row scannable, runtime *Runtime, specsDir string, lockDir
&finishedTimeString,
&exitCode,
&oomKilled,
&pid)
&pid,
&netNSPath)
if err != nil {
if err == sql.ErrNoRows {
return nil, ErrNoSuchCtr
@ -394,6 +397,15 @@ func ctrFromScannable(row scannable, runtime *Runtime, specsDir string, lockDir
}
ctr.state.FinishedTime = finishedTime
// Join the network namespace, if there is one
if netNSPath != "" {
netNS, err := joinNetNS(netNSPath)
if err != nil {
return nil, errors.Wrapf(err, "error joining network namespace for container %s", id)
}
ctr.state.NetNS = netNS
}
ctr.valid = true
ctr.runtime = runtime