mirror of
https://github.com/containers/podman.git
synced 2025-08-06 03:19:52 +08:00
libpod/container: Replace containerState* with containerPlatformState
This way we don't need to stub in structures for other OSes (e.g. the Darwin stub in a Linux-only file). Matthew was concerned about errors unmarshalling, say, a Linux state object on a Windows box [1], but we can address that in checks when loading the database [2]. [1]: https://github.com/projectatomic/libpod/pull/1015#discussion_r198649043 [2]: https://github.com/projectatomic/libpod/pull/1015#discussion_r198802956 Signed-off-by: W. Trevor King <wking@tremily.us> Closes: #1033 Approved by: mheon
This commit is contained in:

committed by
Atomic Bot

parent
49fe03c626
commit
baa42fd4bd
@ -3,6 +3,7 @@ package libpod
|
||||
import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
@ -48,13 +49,14 @@ var (
|
||||
// Check if the configuration of the database is compatible with the
|
||||
// configuration of the runtime opening it
|
||||
// If there is no runtime configuration loaded, load our own
|
||||
func checkRuntimeConfig(db *bolt.DB, runtime *Runtime) error {
|
||||
func checkRuntimeConfig(db *bolt.DB, rt *Runtime) error {
|
||||
var (
|
||||
staticDir = []byte("static-dir")
|
||||
tmpDir = []byte("tmp-dir")
|
||||
runRoot = []byte("run-root")
|
||||
graphRoot = []byte("graph-root")
|
||||
graphDriverName = []byte("graph-driver-name")
|
||||
osKey = []byte("os")
|
||||
)
|
||||
|
||||
err := db.Update(func(tx *bolt.Tx) error {
|
||||
@ -63,30 +65,34 @@ func checkRuntimeConfig(db *bolt.DB, runtime *Runtime) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateDBAgainstConfig(configBkt, "OS", runtime.GOOS, osKey, runtime.GOOS); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateDBAgainstConfig(configBkt, "static dir",
|
||||
runtime.config.StaticDir, staticDir, ""); err != nil {
|
||||
rt.config.StaticDir, staticDir, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateDBAgainstConfig(configBkt, "tmp dir",
|
||||
runtime.config.TmpDir, tmpDir, ""); err != nil {
|
||||
rt.config.TmpDir, tmpDir, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateDBAgainstConfig(configBkt, "run root",
|
||||
runtime.config.StorageConfig.RunRoot, runRoot,
|
||||
rt.config.StorageConfig.RunRoot, runRoot,
|
||||
storage.DefaultStoreOptions.RunRoot); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateDBAgainstConfig(configBkt, "graph root",
|
||||
runtime.config.StorageConfig.GraphRoot, graphRoot,
|
||||
rt.config.StorageConfig.GraphRoot, graphRoot,
|
||||
storage.DefaultStoreOptions.GraphRoot); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return validateDBAgainstConfig(configBkt, "graph driver name",
|
||||
runtime.config.StorageConfig.GraphDriverName,
|
||||
rt.config.StorageConfig.GraphDriverName,
|
||||
graphDriverName,
|
||||
storage.DefaultStoreOptions.GraphDriverName)
|
||||
})
|
||||
|
@ -173,12 +173,8 @@ type containerState struct {
|
||||
// and not delegated to the OCI runtime.
|
||||
ExtensionStageHooks map[string][]spec.Hook `json:"extensionStageHooks,omitempty"`
|
||||
|
||||
// Special container state attributes for Linux
|
||||
containerStateLinux
|
||||
// Special container state attributes for Windows
|
||||
containerStateWindows
|
||||
// Special container state attributes for Darwin
|
||||
containerStateDarwin
|
||||
// containerPlatformState holds platform-specific container state.
|
||||
containerPlatformState
|
||||
}
|
||||
|
||||
// ExecSession contains information on an active exec session
|
||||
|
@ -1,14 +0,0 @@
|
||||
// +build darwin
|
||||
|
||||
package libpod
|
||||
|
||||
type containerStateDarwin struct {
|
||||
}
|
||||
|
||||
// containerStateLinux is intentionally left as a blank stub
|
||||
type containerStateLinux struct {
|
||||
}
|
||||
|
||||
// containerStateWindows is intentionally left as a blank stub
|
||||
type containerStateWindows struct {
|
||||
}
|
@ -6,18 +6,10 @@ import (
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
)
|
||||
|
||||
type containerStateLinux struct {
|
||||
type containerPlatformState struct {
|
||||
|
||||
// NetNSPath is the path of the container's network namespace
|
||||
// Will only be set if config.CreateNetNS is true, or the container was
|
||||
// told to join another container's network namespace
|
||||
NetNS ns.NetNS `json:"-"`
|
||||
}
|
||||
|
||||
// containerStateWindows is intentionally left as a blank stub
|
||||
type containerStateWindows struct {
|
||||
}
|
||||
|
||||
// containerStateDarwin is intentionally left as a blank stub
|
||||
type containerStateDarwin struct {
|
||||
}
|
||||
|
5
libpod/container_unsupported.go
Normal file
5
libpod/container_unsupported.go
Normal file
@ -0,0 +1,5 @@
|
||||
// +build !linux
|
||||
|
||||
package libpod
|
||||
|
||||
type containerPlatformState struct{}
|
@ -1,14 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package libpod
|
||||
|
||||
type containerStateWindows struct {
|
||||
}
|
||||
|
||||
// containerStateLinux is intentionally left as a blank stub
|
||||
type containerStateLinux struct {
|
||||
}
|
||||
|
||||
// containerStateDarwin is intentionally left as a blank stub
|
||||
type containerStateDarwin struct {
|
||||
}
|
Reference in New Issue
Block a user