move shutdown function into libkpod and have server call in to it
Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
parent
4fe17ee16d
commit
314d55f284
2 changed files with 32 additions and 38 deletions
|
@ -3,20 +3,16 @@ package libkpod
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
cstorage "github.com/containers/storage"
|
cstorage "github.com/containers/storage"
|
||||||
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/docker/docker/pkg/registrar"
|
"github.com/docker/docker/pkg/registrar"
|
||||||
"github.com/docker/docker/pkg/truncindex"
|
"github.com/docker/docker/pkg/truncindex"
|
||||||
"github.com/kubernetes-incubator/cri-o/oci"
|
"github.com/kubernetes-incubator/cri-o/oci"
|
||||||
"github.com/kubernetes-incubator/cri-o/pkg/annotations"
|
|
||||||
"github.com/kubernetes-incubator/cri-o/pkg/storage"
|
"github.com/kubernetes-incubator/cri-o/pkg/storage"
|
||||||
"github.com/moby/moby/pkg/ioutils"
|
|
||||||
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerServer implements the ImageServer
|
// ContainerServer implements the ImageServer
|
||||||
|
@ -27,7 +23,6 @@ type ContainerServer struct {
|
||||||
ctrNameIndex *registrar.Registrar
|
ctrNameIndex *registrar.Registrar
|
||||||
ctrIDIndex *truncindex.TruncIndex
|
ctrIDIndex *truncindex.TruncIndex
|
||||||
imageContext *types.SystemContext
|
imageContext *types.SystemContext
|
||||||
updateLock *sync.RWMutex
|
|
||||||
stateLock sync.Locker
|
stateLock sync.Locker
|
||||||
state *containerServerState
|
state *containerServerState
|
||||||
}
|
}
|
||||||
|
@ -63,44 +58,19 @@ func (c *ContainerServer) ImageContext() *types.SystemContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new ContainerServer with options provided
|
// New creates a new ContainerServer with options provided
|
||||||
func New(config *server.Config) (*ContainerServer, error) {
|
func New(runtime *oci.Runtime, store cstorage.Store, imageService storage.ImageServer, signaturePolicyPath string) *ContainerServer {
|
||||||
store, err := cstorage.GetStore(cstorage.StoreOptions{
|
return &ContainerServer{
|
||||||
RunRoot: config.RunRoot,
|
runtime: runtime,
|
||||||
GraphRoot: config.Root,
|
|
||||||
GraphDriverName: config.Storage,
|
|
||||||
GraphDriverOptions: config.StorageOptions,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
imageService, err := storage.GetImageService(store, config.DefaultTransport, config.InsecureRegistries)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
r, err := oci.New(config.Runtime, config.RuntimeUntrustedWorkload, config.DefaultWorkloadTrust, config.Conmon, config.ConmonEnv, config.CgroupManager)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new container server struct here
|
|
||||||
containers := oci.NewMemoryStore()
|
|
||||||
c := &ContainerServer{
|
|
||||||
runtime: r,
|
|
||||||
store: store,
|
store: store,
|
||||||
storageImageServer: imageService,
|
storageImageServer: imageService,
|
||||||
ctrNameIndex: registrar.NewRegistrar(),
|
ctrNameIndex: registrar.NewRegistrar(),
|
||||||
ctrIDIndex: truncindex.NewTruncIndex([]string{}),
|
ctrIDIndex: truncindex.NewTruncIndex([]string{}),
|
||||||
imageContext: &types.SystemContext{SignaturePolicyPath: config.ImageConfig.SignaturePolicyPath},
|
imageContext: &types.SystemContext{SignaturePolicyPath: signaturePolicyPath},
|
||||||
stateLock: new(sync.Mutex),
|
stateLock: new(sync.Mutex),
|
||||||
state: &containerServerState{
|
state: &containerServerState{
|
||||||
containers: containers,
|
containers: oci.NewMemoryStore(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf("containers: %v", c.ListContainers())
|
|
||||||
return c, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerStateFromDisk retrieves information on the state of a running container
|
// ContainerStateFromDisk retrieves information on the state of a running container
|
||||||
|
@ -154,6 +124,12 @@ func (c *ContainerServer) ReleaseContainerName(name string) {
|
||||||
c.ctrNameIndex.Release(name)
|
c.ctrNameIndex.Release(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shutdown attempts to shut down the server's storage cleanly
|
||||||
|
func (c *ContainerServer) Shutdown() error {
|
||||||
|
_, err := c.store.Shutdown(false)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
type containerServerState struct {
|
type containerServerState struct {
|
||||||
containers oci.ContainerStorer
|
containers oci.ContainerStorer
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
cstorage "github.com/containers/storage"
|
||||||
"github.com/docker/docker/pkg/registrar"
|
"github.com/docker/docker/pkg/registrar"
|
||||||
"github.com/docker/docker/pkg/truncindex"
|
"github.com/docker/docker/pkg/truncindex"
|
||||||
"github.com/kubernetes-incubator/cri-o/libkpod"
|
"github.com/kubernetes-incubator/cri-o/libkpod"
|
||||||
|
@ -480,12 +481,27 @@ func (s *Server) Shutdown() error {
|
||||||
|
|
||||||
// New creates a new Server with options provided
|
// New creates a new Server with options provided
|
||||||
func New(config *Config) (*Server, error) {
|
func New(config *Config) (*Server, error) {
|
||||||
containerServer, err := libkpod.New(config)
|
store, err := cstorage.GetStore(cstorage.StoreOptions{
|
||||||
|
RunRoot: config.RunRoot,
|
||||||
|
GraphRoot: config.Root,
|
||||||
|
GraphDriverName: config.Storage,
|
||||||
|
GraphDriverOptions: config.StorageOptions,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
storageRuntimeService := storage.GetRuntimeService(containerServer.StorageImageServer(), config.PauseImage)
|
imageService, err := storage.GetImageService(store, config.DefaultTransport, config.InsecureRegistries)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := oci.New(config.Runtime, config.RuntimeUntrustedWorkload, config.DefaultWorkloadTrust, config.Conmon, config.ConmonEnv, config.CgroupManager)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
storageRuntimeService := storage.GetRuntimeService(imageService, config.PauseImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -494,6 +510,8 @@ func New(config *Config) (*Server, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
containerServer := libkpod.New(r, store, imageService, config.SignaturePolicyPath)
|
||||||
|
|
||||||
sandboxes := make(map[string]*sandbox.Sandbox)
|
sandboxes := make(map[string]*sandbox.Sandbox)
|
||||||
netPlugin, err := ocicni.InitCNI(config.NetworkDir, config.PluginDir)
|
netPlugin, err := ocicni.InitCNI(config.NetworkDir, config.PluginDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue