server: refactor to use Config struct

This paves the way for having a configuration file that is loaded rather
than everything being set via the command-line.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
Aleksa Sarai 2016-10-10 20:57:40 +11:00
parent 3f48986ea0
commit 7bf5110b76
No known key found for this signature in database
GPG key ID: 9E18AA267DDB8DB4
5 changed files with 230 additions and 45 deletions

View file

@ -20,15 +20,12 @@ import (
const (
runtimeAPIVersion = "v1alpha1"
imageStore = "/var/lib/ocid/images"
)
// Server implements the RuntimeService and ImageService
type Server struct {
root string
config Config
runtime *oci.Runtime
sandboxDir string
pausePath string
stateLock sync.Mutex
state *serverState
netPlugin ocicni.CNIPlugin
@ -82,7 +79,7 @@ func (s *Server) loadContainer(id string) error {
}
func (s *Server) loadSandbox(id string) error {
config, err := ioutil.ReadFile(filepath.Join(s.sandboxDir, id, "config.json"))
config, err := ioutil.ReadFile(filepath.Join(s.config.SandboxDir, id, "config.json"))
if err != nil {
return err
}
@ -113,7 +110,7 @@ func (s *Server) loadSandbox(id string) error {
processLabel: processLabel,
mountLabel: mountLabel,
})
sandboxPath := filepath.Join(s.sandboxDir, id)
sandboxPath := filepath.Join(s.config.SandboxDir, id)
if err := label.ReserveLabel(processLabel); err != nil {
return err
@ -141,7 +138,7 @@ func (s *Server) loadSandbox(id string) error {
}
func (s *Server) restore() {
sandboxDir, err := ioutil.ReadDir(s.sandboxDir)
sandboxDir, err := ioutil.ReadDir(s.config.SandboxDir)
if err != nil && !os.IsNotExist(err) {
logrus.Warnf("could not read sandbox directory %s: %v", sandboxDir, err)
}
@ -207,7 +204,7 @@ func (s *Server) releaseContainerName(name string) {
}
// New creates a new Server with options provided
func New(runtimePath, root, sandboxDir, containerDir, conmonPath, pausePath string) (*Server, error) {
func New(config *Config) (*Server, error) {
// TODO: This will go away later when we have wrapper process or systemd acting as
// subreaper.
if err := utils.SetSubreaper(1); err != nil {
@ -216,15 +213,15 @@ func New(runtimePath, root, sandboxDir, containerDir, conmonPath, pausePath stri
utils.StartReaper()
if err := os.MkdirAll(imageStore, 0755); err != nil {
if err := os.MkdirAll(config.ImageStore, 0755); err != nil {
return nil, err
}
if err := os.MkdirAll(sandboxDir, 0755); err != nil {
if err := os.MkdirAll(config.SandboxDir, 0755); err != nil {
return nil, err
}
r, err := oci.New(runtimePath, containerDir, conmonPath)
r, err := oci.New(config.Runtime, config.ContainerDir, config.Conmon)
if err != nil {
return nil, err
}
@ -235,11 +232,9 @@ func New(runtimePath, root, sandboxDir, containerDir, conmonPath, pausePath stri
return nil, err
}
s := &Server{
root: root,
runtime: r,
netPlugin: netPlugin,
sandboxDir: sandboxDir,
pausePath: pausePath,
runtime: r,
netPlugin: netPlugin,
config: *config,
state: &serverState{
sandboxes: sandboxes,
containers: containers,