Update libkpod New()

update libkpod's New() function to use a config struct, and update
server.New() to call into libkpod.New()

Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
Ryan Cole 2017-07-20 15:43:01 -04:00
parent 49ed4ab710
commit 4fe17ee16d
2 changed files with 40 additions and 31 deletions

View file

@ -3,7 +3,9 @@ package libkpod
import (
"encoding/json"
"fmt"
"os"
"sync"
"time"
"github.com/Sirupsen/logrus"
"github.com/containers/image/types"
@ -11,8 +13,10 @@ import (
"github.com/docker/docker/pkg/registrar"
"github.com/docker/docker/pkg/truncindex"
"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/moby/moby/pkg/ioutils"
rspec "github.com/opencontainers/runtime-spec/specs-go"
)
// ContainerServer implements the ImageServer
@ -23,6 +27,7 @@ type ContainerServer struct {
ctrNameIndex *registrar.Registrar
ctrIDIndex *truncindex.TruncIndex
imageContext *types.SystemContext
updateLock *sync.RWMutex
stateLock sync.Locker
state *containerServerState
}
@ -57,21 +62,45 @@ func (c *ContainerServer) ImageContext() *types.SystemContext {
return c.imageContext
}
// New creates a new ContainerServer
func New(runtime *oci.Runtime, store cstorage.Store, storageImageServer storage.ImageServer, ctrNameIndex *registrar.Registrar, ctrIDIndex *truncindex.TruncIndex, imageContext *types.SystemContext) *ContainerServer {
// New creates a new ContainerServer with options provided
func New(config *server.Config) (*ContainerServer, error) {
store, err := cstorage.GetStore(cstorage.StoreOptions{
RunRoot: config.RunRoot,
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()
return &ContainerServer{
runtime: runtime,
c := &ContainerServer{
runtime: r,
store: store,
storageImageServer: storageImageServer,
ctrNameIndex: ctrNameIndex,
ctrIDIndex: ctrIDIndex,
imageContext: imageContext,
storageImageServer: imageService,
ctrNameIndex: registrar.NewRegistrar(),
ctrIDIndex: truncindex.NewTruncIndex([]string{}),
imageContext: &types.SystemContext{SignaturePolicyPath: config.ImageConfig.SignaturePolicyPath},
stateLock: new(sync.Mutex),
state: &containerServerState{
containers: containers,
},
}
logrus.Debugf("containers: %v", c.ListContainers())
return c, nil
}
// ContainerStateFromDisk retrieves information on the state of a running container

View file

@ -11,8 +11,6 @@ import (
"time"
"github.com/Sirupsen/logrus"
"github.com/containers/image/types"
cstorage "github.com/containers/storage"
"github.com/docker/docker/pkg/registrar"
"github.com/docker/docker/pkg/truncindex"
"github.com/kubernetes-incubator/cri-o/libkpod"
@ -477,28 +475,17 @@ func (s *Server) Shutdown() error {
// notice this won't trigger just on system halt but also on normal
// crio.service restart!!!
s.cleanupSandboxesOnShutdown()
_, err := s.Store().Shutdown(false)
return err
return s.ContainerServer.Shutdown()
}
// New creates a new Server with options provided
func New(config *Config) (*Server, error) {
store, err := cstorage.GetStore(cstorage.StoreOptions{
RunRoot: config.RunRoot,
GraphRoot: config.Root,
GraphDriverName: config.Storage,
GraphDriverOptions: config.StorageOptions,
})
containerServer, err := libkpod.New(config)
if err != nil {
return nil, err
}
imageService, err := storage.GetImageService(store, config.DefaultTransport, config.InsecureRegistries)
if err != nil {
return nil, err
}
storageRuntimeService := storage.GetRuntimeService(imageService, config.PauseImage)
storageRuntimeService := storage.GetRuntimeService(containerServer.StorageImageServer(), config.PauseImage)
if err != nil {
return nil, err
}
@ -507,11 +494,6 @@ func New(config *Config) (*Server, error) {
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
}
sandboxes := make(map[string]*sandbox.Sandbox)
netPlugin, err := ocicni.InitCNI(config.NetworkDir, config.PluginDir)
if err != nil {
@ -521,7 +503,6 @@ func New(config *Config) (*Server, error) {
iptInterface.EnsureChain(utiliptables.TableNAT, iptablesproxy.KubeMarkMasqChain)
hostportManager := hostport.NewHostportManager()
containerServer := libkpod.New(r, store, imageService, registrar.NewRegistrar(), truncindex.NewTruncIndex([]string{}), &types.SystemContext{SignaturePolicyPath: config.ImageConfig.SignaturePolicyPath})
s := &Server{
ContainerServer: *containerServer,
storageRuntimeServer: storageRuntimeService,
@ -588,7 +569,6 @@ func New(config *Config) (*Server, error) {
}()
logrus.Debugf("sandboxes: %v", s.state.sandboxes)
logrus.Debugf("containers: %v", s.ContainerServer.ListContainers())
return s, nil
}