server: Add infra container store to track them separately
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
b4f9fc8c2c
commit
49c1fd27ac
2 changed files with 39 additions and 4 deletions
|
@ -143,8 +143,9 @@ func New(config *Config) (*ContainerServer, error) {
|
||||||
imageContext: &types.SystemContext{SignaturePolicyPath: config.SignaturePolicyPath},
|
imageContext: &types.SystemContext{SignaturePolicyPath: config.SignaturePolicyPath},
|
||||||
stateLock: lock,
|
stateLock: lock,
|
||||||
state: &containerServerState{
|
state: &containerServerState{
|
||||||
containers: oci.NewMemoryStore(),
|
containers: oci.NewMemoryStore(),
|
||||||
sandboxes: make(map[string]*sandbox.Sandbox),
|
infraContainers: oci.NewMemoryStore(),
|
||||||
|
sandboxes: make(map[string]*sandbox.Sandbox),
|
||||||
},
|
},
|
||||||
config: config,
|
config: config,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -579,8 +580,9 @@ func (c *ContainerServer) Shutdown() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type containerServerState struct {
|
type containerServerState struct {
|
||||||
containers oci.ContainerStorer
|
containers oci.ContainerStorer
|
||||||
sandboxes map[string]*sandbox.Sandbox
|
infraContainers oci.ContainerStorer
|
||||||
|
sandboxes map[string]*sandbox.Sandbox
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddContainer adds a container to the container state store
|
// AddContainer adds a container to the container state store
|
||||||
|
@ -592,6 +594,13 @@ func (c *ContainerServer) AddContainer(ctr *oci.Container) {
|
||||||
c.state.containers.Add(ctr.ID(), ctr)
|
c.state.containers.Add(ctr.ID(), ctr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddInfraContainer adds a container to the container state store
|
||||||
|
func (c *ContainerServer) AddInfraContainer(ctr *oci.Container) {
|
||||||
|
c.stateLock.Lock()
|
||||||
|
defer c.stateLock.Unlock()
|
||||||
|
c.state.infraContainers.Add(ctr.ID(), ctr)
|
||||||
|
}
|
||||||
|
|
||||||
// GetContainer returns a container by its ID
|
// GetContainer returns a container by its ID
|
||||||
func (c *ContainerServer) GetContainer(id string) *oci.Container {
|
func (c *ContainerServer) GetContainer(id string) *oci.Container {
|
||||||
c.stateLock.Lock()
|
c.stateLock.Lock()
|
||||||
|
@ -599,6 +608,13 @@ func (c *ContainerServer) GetContainer(id string) *oci.Container {
|
||||||
return c.state.containers.Get(id)
|
return c.state.containers.Get(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetInfraContainer returns a container by its ID
|
||||||
|
func (c *ContainerServer) GetInfraContainer(id string) *oci.Container {
|
||||||
|
c.stateLock.Lock()
|
||||||
|
defer c.stateLock.Unlock()
|
||||||
|
return c.state.infraContainers.Get(id)
|
||||||
|
}
|
||||||
|
|
||||||
// HasContainer checks if a container exists in the state
|
// HasContainer checks if a container exists in the state
|
||||||
func (c *ContainerServer) HasContainer(id string) bool {
|
func (c *ContainerServer) HasContainer(id string) bool {
|
||||||
c.stateLock.Lock()
|
c.stateLock.Lock()
|
||||||
|
@ -617,6 +633,13 @@ func (c *ContainerServer) RemoveContainer(ctr *oci.Container) {
|
||||||
c.state.containers.Delete(ctr.ID())
|
c.state.containers.Delete(ctr.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveInfraContainer removes a container from the container state store
|
||||||
|
func (c *ContainerServer) RemoveInfraContainer(ctr *oci.Container) {
|
||||||
|
c.stateLock.Lock()
|
||||||
|
defer c.stateLock.Unlock()
|
||||||
|
c.state.infraContainers.Delete(ctr.ID())
|
||||||
|
}
|
||||||
|
|
||||||
// listContainers returns a list of all containers stored by the server state
|
// listContainers returns a list of all containers stored by the server state
|
||||||
func (c *ContainerServer) listContainers() []*oci.Container {
|
func (c *ContainerServer) listContainers() []*oci.Container {
|
||||||
c.stateLock.Lock()
|
c.stateLock.Lock()
|
||||||
|
|
|
@ -277,10 +277,18 @@ func (s *Server) addContainer(c *oci.Container) {
|
||||||
s.ContainerServer.AddContainer(c)
|
s.ContainerServer.AddContainer(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) addInfraContainer(c *oci.Container) {
|
||||||
|
s.ContainerServer.AddInfraContainer(c)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) getContainer(id string) *oci.Container {
|
func (s *Server) getContainer(id string) *oci.Container {
|
||||||
return s.ContainerServer.GetContainer(id)
|
return s.ContainerServer.GetContainer(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) getInfraContainer(id string) *oci.Container {
|
||||||
|
return s.ContainerServer.GetInfraContainer(id)
|
||||||
|
}
|
||||||
|
|
||||||
// GetSandboxContainer returns the infra container for a given sandbox
|
// GetSandboxContainer returns the infra container for a given sandbox
|
||||||
func (s *Server) GetSandboxContainer(id string) *oci.Container {
|
func (s *Server) GetSandboxContainer(id string) *oci.Container {
|
||||||
return s.ContainerServer.GetSandboxContainer(id)
|
return s.ContainerServer.GetSandboxContainer(id)
|
||||||
|
@ -295,6 +303,10 @@ func (s *Server) removeContainer(c *oci.Container) {
|
||||||
s.ContainerServer.RemoveContainer(c)
|
s.ContainerServer.RemoveContainer(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) removeInfraContainer(c *oci.Container) {
|
||||||
|
s.ContainerServer.RemoveInfraContainer(c)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) getPodSandboxFromRequest(podSandboxID string) (*sandbox.Sandbox, error) {
|
func (s *Server) getPodSandboxFromRequest(podSandboxID string) (*sandbox.Sandbox, error) {
|
||||||
if podSandboxID == "" {
|
if podSandboxID == "" {
|
||||||
return nil, sandbox.ErrIDEmpty
|
return nil, sandbox.ErrIDEmpty
|
||||||
|
|
Loading…
Reference in a new issue