summaryrefslogtreecommitdiff
path: root/libpod/sql_state.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-03-02 11:10:37 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-03-02 19:20:26 +0000
commitedb1609c6121a550a3c882529e44387c217d2b03 (patch)
treed533567351dd70b8bcffe17174a8edc1fefa199d /libpod/sql_state.go
parent29d650a3799b76b08094b6dc90fe8500c76fa6de (diff)
downloadpodman-edb1609c6121a550a3c882529e44387c217d2b03.tar.gz
podman-edb1609c6121a550a3c882529e44387c217d2b03.tar.bz2
podman-edb1609c6121a550a3c882529e44387c217d2b03.zip
Update DB to hold CNI network information
Replace our old IP and Subnet fields in state with CNI types that contain a lot more information. Retrieve these structs from the CNI plugins themselves. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #440 Approved by: baude
Diffstat (limited to 'libpod/sql_state.go')
-rw-r--r--libpod/sql_state.go70
1 files changed, 48 insertions, 22 deletions
diff --git a/libpod/sql_state.go b/libpod/sql_state.go
index 20aa7c0ac..41cc435cc 100644
--- a/libpod/sql_state.go
+++ b/libpod/sql_state.go
@@ -5,6 +5,8 @@ import (
"encoding/json"
"os"
+ "github.com/containernetworking/cni/pkg/types"
+ cnitypes "github.com/containernetworking/cni/pkg/types/current"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -14,7 +16,7 @@ import (
// DBSchema is the current DB schema version
// Increments every time a change is made to the database's tables
-const DBSchema = 12
+const DBSchema = 13
// SQLState is a state implementation backed by a persistent SQLite3 database
type SQLState struct {
@@ -101,9 +103,9 @@ func (s *SQLState) Refresh() (err error) {
Mountpoint=?,
Pid=?,
NetNSPath=?,
- IPAddress=?,
- SubnetMask=?,
- ExecSessions=?;`
+ ExecSessions=?,
+ IPs=?,
+ Routes=?;`
if !s.valid {
return ErrDBClosed
@@ -132,9 +134,9 @@ func (s *SQLState) Refresh() (err error) {
"",
0,
"",
- "",
- "",
- "{}")
+ "{}",
+ "[]",
+ "[]")
if err != nil {
return errors.Wrapf(err, "error refreshing database state")
}
@@ -270,9 +272,9 @@ func (s *SQLState) UpdateContainer(ctr *Container) error {
OomKilled,
Pid,
NetNSPath,
- IPAddress,
- SubnetMask,
- ExecSessions
+ ExecSessions,
+ IPs,
+ Routes
FROM containerState WHERE ID=?;`
var (
@@ -286,9 +288,9 @@ func (s *SQLState) UpdateContainer(ctr *Container) error {
oomKilled int
pid int
netNSPath string
- ipAddress string
- subnetMask string
execSessions string
+ ipsJSON string
+ routesJSON string
)
if !s.valid {
@@ -311,9 +313,9 @@ func (s *SQLState) UpdateContainer(ctr *Container) error {
&oomKilled,
&pid,
&netNSPath,
- &ipAddress,
- &subnetMask,
- &execSessions)
+ &execSessions,
+ &ipsJSON,
+ &routesJSON)
if err != nil {
// The container may not exist in the database
if err == sql.ErrNoRows {
@@ -335,14 +337,28 @@ func (s *SQLState) UpdateContainer(ctr *Container) error {
newState.ExitCode = exitCode
newState.OOMKilled = boolFromSQL(oomKilled)
newState.PID = pid
- newState.IPAddress = ipAddress
- newState.SubnetMask = subnetMask
newState.ExecSessions = make(map[string]*ExecSession)
if err := json.Unmarshal([]byte(execSessions), &newState.ExecSessions); err != nil {
return errors.Wrapf(err, "error parsing container %s exec sessions", ctr.ID())
}
+ ips := []*cnitypes.IPConfig{}
+ if err := json.Unmarshal([]byte(ipsJSON), &ips); err != nil {
+ return errors.Wrapf(err, "error parsing container %s IPs JSON", ctr.ID())
+ }
+ if len(ips) > 0 {
+ newState.IPs = ips
+ }
+
+ routes := []*types.Route{}
+ if err := json.Unmarshal([]byte(routesJSON), &routes); err != nil {
+ return errors.Wrapf(err, "error parsing container %s routes JSON", ctr.ID())
+ }
+ if len(routes) > 0 {
+ newState.Routes = routes
+ }
+
if newState.Mountpoint != "" {
newState.Mounted = true
}
@@ -404,9 +420,9 @@ func (s *SQLState) SaveContainer(ctr *Container) (err error) {
OomKilled=?,
Pid=?,
NetNSPath=?,
- IPAddress=?,
- SubnetMask=?,
- ExecSessions=?
+ ExecSessions=?,
+ IPs=?,
+ Routes=?
WHERE Id=?;`
if !ctr.valid {
@@ -423,6 +439,16 @@ func (s *SQLState) SaveContainer(ctr *Container) (err error) {
netNSPath = ctr.state.NetNS.Path()
}
+ ipsJSON, err := json.Marshal(ctr.state.IPs)
+ if err != nil {
+ return errors.Wrapf(err, "error marshalling container %s IPs to JSON", ctr.ID())
+ }
+
+ routesJSON, err := json.Marshal(ctr.state.Routes)
+ if err != nil {
+ return errors.Wrapf(err, "error marshalling container %s routes to JSON", ctr.ID())
+ }
+
if !s.valid {
return ErrDBClosed
}
@@ -453,9 +479,9 @@ func (s *SQLState) SaveContainer(ctr *Container) (err error) {
boolToSQL(ctr.state.OOMKilled),
ctr.state.PID,
netNSPath,
- ctr.state.IPAddress,
- ctr.state.SubnetMask,
execSessionsJSON,
+ ipsJSON,
+ routesJSON,
ctr.ID())
if err != nil {
return errors.Wrapf(err, "error updating container %s state in database", ctr.ID())