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:
parent
49ed4ab710
commit
4fe17ee16d
2 changed files with 40 additions and 31 deletions
|
@ -3,7 +3,9 @@ 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"
|
||||||
|
@ -11,8 +13,10 @@ import (
|
||||||
"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"
|
"github.com/moby/moby/pkg/ioutils"
|
||||||
|
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerServer implements the ImageServer
|
// ContainerServer implements the ImageServer
|
||||||
|
@ -23,6 +27,7 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -57,21 +62,45 @@ func (c *ContainerServer) ImageContext() *types.SystemContext {
|
||||||
return c.imageContext
|
return c.imageContext
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new ContainerServer
|
// New creates a new ContainerServer with options provided
|
||||||
func New(runtime *oci.Runtime, store cstorage.Store, storageImageServer storage.ImageServer, ctrNameIndex *registrar.Registrar, ctrIDIndex *truncindex.TruncIndex, imageContext *types.SystemContext) *ContainerServer {
|
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()
|
containers := oci.NewMemoryStore()
|
||||||
return &ContainerServer{
|
c := &ContainerServer{
|
||||||
runtime: runtime,
|
runtime: r,
|
||||||
store: store,
|
store: store,
|
||||||
storageImageServer: storageImageServer,
|
storageImageServer: imageService,
|
||||||
ctrNameIndex: ctrNameIndex,
|
ctrNameIndex: registrar.NewRegistrar(),
|
||||||
ctrIDIndex: ctrIDIndex,
|
ctrIDIndex: truncindex.NewTruncIndex([]string{}),
|
||||||
imageContext: imageContext,
|
imageContext: &types.SystemContext{SignaturePolicyPath: config.ImageConfig.SignaturePolicyPath},
|
||||||
stateLock: new(sync.Mutex),
|
stateLock: new(sync.Mutex),
|
||||||
state: &containerServerState{
|
state: &containerServerState{
|
||||||
containers: containers,
|
containers: containers,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -11,8 +11,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"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/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"
|
||||||
|
@ -477,28 +475,17 @@ func (s *Server) Shutdown() error {
|
||||||
// notice this won't trigger just on system halt but also on normal
|
// notice this won't trigger just on system halt but also on normal
|
||||||
// crio.service restart!!!
|
// crio.service restart!!!
|
||||||
s.cleanupSandboxesOnShutdown()
|
s.cleanupSandboxesOnShutdown()
|
||||||
_, err := s.Store().Shutdown(false)
|
return s.ContainerServer.Shutdown()
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
store, err := cstorage.GetStore(cstorage.StoreOptions{
|
containerServer, err := libkpod.New(config)
|
||||||
RunRoot: config.RunRoot,
|
|
||||||
GraphRoot: config.Root,
|
|
||||||
GraphDriverName: config.Storage,
|
|
||||||
GraphDriverOptions: config.StorageOptions,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
imageService, err := storage.GetImageService(store, config.DefaultTransport, config.InsecureRegistries)
|
storageRuntimeService := storage.GetRuntimeService(containerServer.StorageImageServer(), config.PauseImage)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
storageRuntimeService := storage.GetRuntimeService(imageService, config.PauseImage)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -507,11 +494,6 @@ func New(config *Config) (*Server, error) {
|
||||||
return nil, err
|
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)
|
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 {
|
||||||
|
@ -521,7 +503,6 @@ func New(config *Config) (*Server, error) {
|
||||||
iptInterface.EnsureChain(utiliptables.TableNAT, iptablesproxy.KubeMarkMasqChain)
|
iptInterface.EnsureChain(utiliptables.TableNAT, iptablesproxy.KubeMarkMasqChain)
|
||||||
hostportManager := hostport.NewHostportManager()
|
hostportManager := hostport.NewHostportManager()
|
||||||
|
|
||||||
containerServer := libkpod.New(r, store, imageService, registrar.NewRegistrar(), truncindex.NewTruncIndex([]string{}), &types.SystemContext{SignaturePolicyPath: config.ImageConfig.SignaturePolicyPath})
|
|
||||||
s := &Server{
|
s := &Server{
|
||||||
ContainerServer: *containerServer,
|
ContainerServer: *containerServer,
|
||||||
storageRuntimeServer: storageRuntimeService,
|
storageRuntimeServer: storageRuntimeService,
|
||||||
|
@ -588,7 +569,6 @@ func New(config *Config) (*Server, error) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
logrus.Debugf("sandboxes: %v", s.state.sandboxes)
|
logrus.Debugf("sandboxes: %v", s.state.sandboxes)
|
||||||
logrus.Debugf("containers: %v", s.ContainerServer.ListContainers())
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue