60123a77ce
VM base container runtimes (e.g. Clear Containers) will run each pod in a VM and will create containers within that pod VM. Unfortunately those runtimes will get called by ocid with the same commands (create and start) for both the pause containers and subsequent containers to be added to the pod namespace. Unless they work around that by e.g. infering that a container which rootfs is under "/pause" would represent a pod, they have no way to decide if they need to create/start a VM or if they need to add a container to an already running VM pod. This patch tries to formalize this difference through pod annotations. When starting a container or a sandbox, we now add 2 annotations for the container type (Infrastructure or not) and the sandbox name. This will allow VM based container runtimes to handle 2 things: - Decide if they need to create a pod VM or not. - Keep track of which pod ID runs in a given VM, so that they know to which sandbox they have to add containers. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
36 lines
867 B
Go
36 lines
867 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/kubernetes-incubator/cri-o/oci"
|
|
)
|
|
|
|
const (
|
|
// containerTypeSandbox represents a pod sandbox container
|
|
containerTypeSandbox = "sandbox"
|
|
// containerTypeContainer represents a container running within a pod
|
|
containerTypeContainer = "container"
|
|
)
|
|
|
|
type containerRequest interface {
|
|
GetContainerId() string
|
|
}
|
|
|
|
func (s *Server) getContainerFromRequest(req containerRequest) (*oci.Container, error) {
|
|
ctrID := req.GetContainerId()
|
|
if ctrID == "" {
|
|
return nil, fmt.Errorf("container ID should not be empty")
|
|
}
|
|
|
|
containerID, err := s.ctrIDIndex.Get(ctrID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("container with ID starting with %s not found: %v", ctrID, err)
|
|
}
|
|
|
|
c := s.state.containers.Get(containerID)
|
|
if c == nil {
|
|
return nil, fmt.Errorf("specified container not found: %s", containerID)
|
|
}
|
|
return c, nil
|
|
}
|