Separate container state from sandbox state in server
Move container state data to libkpod, separate from the sandbox data in server. However, the move was structured such that sandbox data could easily be moved over into libkpod in the future Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
parent
0eb5cd527f
commit
bd540ac94c
4 changed files with 51 additions and 12 deletions
|
@ -1,6 +1,8 @@
|
|||
package libkpod
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/containers/image/types"
|
||||
cstorage "github.com/containers/storage"
|
||||
"github.com/docker/docker/pkg/registrar"
|
||||
|
@ -17,6 +19,8 @@ type ContainerServer struct {
|
|||
ctrNameIndex *registrar.Registrar
|
||||
ctrIDIndex *truncindex.TruncIndex
|
||||
imageContext *types.SystemContext
|
||||
stateLock sync.Locker
|
||||
state *containerServerState
|
||||
}
|
||||
|
||||
// Runtime returns the oci runtime for the ContainerServer
|
||||
|
@ -51,6 +55,7 @@ func (c *ContainerServer) ImageContext() *types.SystemContext {
|
|||
|
||||
// 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 {
|
||||
containers := oci.NewMemoryStore()
|
||||
return &ContainerServer{
|
||||
runtime: runtime,
|
||||
store: store,
|
||||
|
@ -58,5 +63,41 @@ func New(runtime *oci.Runtime, store cstorage.Store, storageImageServer storage.
|
|||
ctrNameIndex: ctrNameIndex,
|
||||
ctrIDIndex: ctrIDIndex,
|
||||
imageContext: imageContext,
|
||||
stateLock: new(sync.Mutex),
|
||||
state: &containerServerState{
|
||||
containers: containers,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type containerServerState struct {
|
||||
containers oci.ContainerStorer
|
||||
}
|
||||
|
||||
// AddContainer adds a container to the container state store
|
||||
func (c *ContainerServer) AddContainer(ctr *oci.Container) {
|
||||
c.stateLock.Lock()
|
||||
defer c.stateLock.Unlock()
|
||||
c.state.containers.Add(ctr.ID(), ctr)
|
||||
}
|
||||
|
||||
// GetContainer returns a container by its ID
|
||||
func (c *ContainerServer) GetContainer(id string) *oci.Container {
|
||||
c.stateLock.Lock()
|
||||
defer c.stateLock.Unlock()
|
||||
return c.state.containers.Get(id)
|
||||
}
|
||||
|
||||
// RemoveContainer removes a container from the container state store
|
||||
func (c *ContainerServer) RemoveContainer(ctr *oci.Container) {
|
||||
c.stateLock.Lock()
|
||||
defer c.stateLock.Unlock()
|
||||
c.state.containers.Delete(ctr.ID())
|
||||
}
|
||||
|
||||
// ListContainers returns a list of all containers stored by the server state
|
||||
func (c *ContainerServer) ListContainers() []*oci.Container {
|
||||
c.stateLock.Lock()
|
||||
defer c.stateLock.Unlock()
|
||||
return c.state.containers.List()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue