mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 00:37:24 +00:00
Merge pull request #326 from jshachm/fix-pod-to-sandbox
virtcontainers: fix codes misunderstanding in virtcontainers
This commit is contained in:
commit
92ec15d774
@ -82,17 +82,17 @@ func DeleteSandbox(sandboxID string) (VCSandbox, error) {
|
|||||||
defer unlockSandbox(lockFile)
|
defer unlockSandbox(lockFile)
|
||||||
|
|
||||||
// Fetch the sandbox from storage and create it.
|
// Fetch the sandbox from storage and create it.
|
||||||
p, err := fetchSandbox(sandboxID)
|
s, err := fetchSandbox(sandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete it.
|
// Delete it.
|
||||||
if err := p.Delete(); err != nil {
|
if err := s.Delete(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return p, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchSandbox is the virtcontainers sandbox fetching entry point.
|
// FetchSandbox is the virtcontainers sandbox fetching entry point.
|
||||||
@ -129,27 +129,27 @@ func StartSandbox(sandboxID string) (VCSandbox, error) {
|
|||||||
defer unlockSandbox(lockFile)
|
defer unlockSandbox(lockFile)
|
||||||
|
|
||||||
// Fetch the sandbox from storage and create it.
|
// Fetch the sandbox from storage and create it.
|
||||||
p, err := fetchSandbox(sandboxID)
|
s, err := fetchSandbox(sandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return startSandbox(p)
|
return startSandbox(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func startSandbox(p *Sandbox) (*Sandbox, error) {
|
func startSandbox(s *Sandbox) (*Sandbox, error) {
|
||||||
// Start it
|
// Start it
|
||||||
err := p.start()
|
err := s.start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute poststart hooks.
|
// Execute poststart hooks.
|
||||||
if err := p.config.Hooks.postStartHooks(p); err != nil {
|
if err := s.config.Hooks.postStartHooks(s); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return p, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopSandbox is the virtcontainers sandbox stopping entry point.
|
// StopSandbox is the virtcontainers sandbox stopping entry point.
|
||||||
@ -166,45 +166,45 @@ func StopSandbox(sandboxID string) (VCSandbox, error) {
|
|||||||
defer unlockSandbox(lockFile)
|
defer unlockSandbox(lockFile)
|
||||||
|
|
||||||
// Fetch the sandbox from storage and create it.
|
// Fetch the sandbox from storage and create it.
|
||||||
p, err := fetchSandbox(sandboxID)
|
s, err := fetchSandbox(sandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop it.
|
// Stop it.
|
||||||
err = p.stop()
|
err = s.stop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the network.
|
// Remove the network.
|
||||||
if err := p.removeNetwork(); err != nil {
|
if err := s.removeNetwork(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute poststop hooks.
|
// Execute poststop hooks.
|
||||||
if err := p.config.Hooks.postStopHooks(p); err != nil {
|
if err := s.config.Hooks.postStopHooks(s); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return p, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunSandbox is the virtcontainers sandbox running entry point.
|
// RunSandbox is the virtcontainers sandbox running entry point.
|
||||||
// RunSandbox creates a sandbox and its containers and then it starts them.
|
// RunSandbox creates a sandbox and its containers and then it starts them.
|
||||||
func RunSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) {
|
func RunSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) {
|
||||||
p, err := createSandboxFromConfig(sandboxConfig)
|
s, err := createSandboxFromConfig(sandboxConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
lockFile, err := rwLockSandbox(p.id)
|
lockFile, err := rwLockSandbox(s.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer unlockSandbox(lockFile)
|
defer unlockSandbox(lockFile)
|
||||||
|
|
||||||
return startSandbox(p)
|
return startSandbox(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListSandbox is the virtcontainers sandbox listing entry point.
|
// ListSandbox is the virtcontainers sandbox listing entry point.
|
||||||
@ -250,7 +250,7 @@ func StatusSandbox(sandboxID string) (SandboxStatus, error) {
|
|||||||
return SandboxStatus{}, err
|
return SandboxStatus{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sandbox, err := fetchSandbox(sandboxID)
|
s, err := fetchSandbox(sandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
unlockSandbox(lockFile)
|
unlockSandbox(lockFile)
|
||||||
return SandboxStatus{}, err
|
return SandboxStatus{}, err
|
||||||
@ -263,12 +263,12 @@ func StatusSandbox(sandboxID string) (SandboxStatus, error) {
|
|||||||
// will need to lock an exclusive lock, meaning that all other locks have
|
// will need to lock an exclusive lock, meaning that all other locks have
|
||||||
// to be released to let this happen. This call ensures this will be the
|
// to be released to let this happen. This call ensures this will be the
|
||||||
// last operation executed by this function.
|
// last operation executed by this function.
|
||||||
defer sandbox.wg.Wait()
|
defer s.wg.Wait()
|
||||||
defer unlockSandbox(lockFile)
|
defer unlockSandbox(lockFile)
|
||||||
|
|
||||||
var contStatusList []ContainerStatus
|
var contStatusList []ContainerStatus
|
||||||
for _, container := range sandbox.containers {
|
for _, container := range s.containers {
|
||||||
contStatus, err := statusContainer(sandbox, container.id)
|
contStatus, err := statusContainer(s, container.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SandboxStatus{}, err
|
return SandboxStatus{}, err
|
||||||
}
|
}
|
||||||
@ -277,13 +277,13 @@ func StatusSandbox(sandboxID string) (SandboxStatus, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sandboxStatus := SandboxStatus{
|
sandboxStatus := SandboxStatus{
|
||||||
ID: sandbox.id,
|
ID: s.id,
|
||||||
State: sandbox.state,
|
State: s.state,
|
||||||
Hypervisor: sandbox.config.HypervisorType,
|
Hypervisor: s.config.HypervisorType,
|
||||||
HypervisorConfig: sandbox.config.HypervisorConfig,
|
HypervisorConfig: s.config.HypervisorConfig,
|
||||||
Agent: sandbox.config.AgentType,
|
Agent: s.config.AgentType,
|
||||||
ContainersStatus: contStatusList,
|
ContainersStatus: contStatusList,
|
||||||
Annotations: sandbox.config.Annotations,
|
Annotations: s.config.Annotations,
|
||||||
}
|
}
|
||||||
|
|
||||||
return sandboxStatus, nil
|
return sandboxStatus, nil
|
||||||
@ -388,13 +388,13 @@ func StopContainer(sandboxID, containerID string) (VCContainer, error) {
|
|||||||
}
|
}
|
||||||
defer unlockSandbox(lockFile)
|
defer unlockSandbox(lockFile)
|
||||||
|
|
||||||
p, err := fetchSandbox(sandboxID)
|
s, err := fetchSandbox(sandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the container.
|
// Fetch the container.
|
||||||
c, err := p.findContainer(containerID)
|
c, err := s.findContainer(containerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -454,7 +454,7 @@ func StatusContainer(sandboxID, containerID string) (ContainerStatus, error) {
|
|||||||
return ContainerStatus{}, err
|
return ContainerStatus{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sandbox, err := fetchSandbox(sandboxID)
|
s, err := fetchSandbox(sandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
unlockSandbox(lockFile)
|
unlockSandbox(lockFile)
|
||||||
return ContainerStatus{}, err
|
return ContainerStatus{}, err
|
||||||
@ -467,10 +467,10 @@ func StatusContainer(sandboxID, containerID string) (ContainerStatus, error) {
|
|||||||
// will need to lock an exclusive lock, meaning that all other locks have
|
// will need to lock an exclusive lock, meaning that all other locks have
|
||||||
// to be released to let this happen. This call ensures this will be the
|
// to be released to let this happen. This call ensures this will be the
|
||||||
// last operation executed by this function.
|
// last operation executed by this function.
|
||||||
defer sandbox.wg.Wait()
|
defer s.wg.Wait()
|
||||||
defer unlockSandbox(lockFile)
|
defer unlockSandbox(lockFile)
|
||||||
|
|
||||||
return statusContainer(sandbox, containerID)
|
return statusContainer(s, containerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is going to spawn a goroutine and it needs to be waited for
|
// This function is going to spawn a goroutine and it needs to be waited for
|
||||||
@ -541,13 +541,13 @@ func KillContainer(sandboxID, containerID string, signal syscall.Signal, all boo
|
|||||||
}
|
}
|
||||||
defer unlockSandbox(lockFile)
|
defer unlockSandbox(lockFile)
|
||||||
|
|
||||||
p, err := fetchSandbox(sandboxID)
|
s, err := fetchSandbox(sandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the container.
|
// Fetch the container.
|
||||||
c, err := p.findContainer(containerID)
|
c, err := s.findContainer(containerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -590,13 +590,13 @@ func ProcessListContainer(sandboxID, containerID string, options ProcessListOpti
|
|||||||
}
|
}
|
||||||
defer unlockSandbox(lockFile)
|
defer unlockSandbox(lockFile)
|
||||||
|
|
||||||
p, err := fetchSandbox(sandboxID)
|
s, err := fetchSandbox(sandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the container.
|
// Fetch the container.
|
||||||
c, err := p.findContainer(containerID)
|
c, err := s.findContainer(containerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -14,30 +14,30 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ID implements the VCSandbox function of the same name.
|
// ID implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) ID() string {
|
func (s *Sandbox) ID() string {
|
||||||
return p.MockID
|
return s.MockID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annotations implements the VCSandbox function of the same name.
|
// Annotations implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) Annotations(key string) (string, error) {
|
func (s *Sandbox) Annotations(key string) (string, error) {
|
||||||
return p.MockAnnotations[key], nil
|
return s.MockAnnotations[key], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAnnotations implements the VCSandbox function of the same name.
|
// SetAnnotations implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) SetAnnotations(annotations map[string]string) error {
|
func (s *Sandbox) SetAnnotations(annotations map[string]string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAnnotations implements the VCSandbox function of the same name.
|
// GetAnnotations implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) GetAnnotations() map[string]string {
|
func (s *Sandbox) GetAnnotations() map[string]string {
|
||||||
return p.MockAnnotations
|
return s.MockAnnotations
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllContainers implements the VCSandbox function of the same name.
|
// GetAllContainers implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) GetAllContainers() []vc.VCContainer {
|
func (s *Sandbox) GetAllContainers() []vc.VCContainer {
|
||||||
var ifa = make([]vc.VCContainer, len(p.MockContainers))
|
var ifa = make([]vc.VCContainer, len(s.MockContainers))
|
||||||
|
|
||||||
for i, v := range p.MockContainers {
|
for i, v := range s.MockContainers {
|
||||||
ifa[i] = v
|
ifa[i] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +45,8 @@ func (p *Sandbox) GetAllContainers() []vc.VCContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetContainer implements the VCSandbox function of the same name.
|
// GetContainer implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) GetContainer(containerID string) vc.VCContainer {
|
func (s *Sandbox) GetContainer(containerID string) vc.VCContainer {
|
||||||
for _, c := range p.MockContainers {
|
for _, c := range s.MockContainers {
|
||||||
if c.MockID == containerID {
|
if c.MockID == containerID {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
@ -55,86 +55,86 @@ func (p *Sandbox) GetContainer(containerID string) vc.VCContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Release implements the VCSandbox function of the same name.
|
// Release implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) Release() error {
|
func (s *Sandbox) Release() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause implements the VCSandbox function of the same name.
|
// Pause implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) Pause() error {
|
func (s *Sandbox) Pause() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resume implements the VCSandbox function of the same name.
|
// Resume implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) Resume() error {
|
func (s *Sandbox) Resume() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete implements the VCSandbox function of the same name.
|
// Delete implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) Delete() error {
|
func (s *Sandbox) Delete() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateContainer implements the VCSandbox function of the same name.
|
// CreateContainer implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) CreateContainer(conf vc.ContainerConfig) (vc.VCContainer, error) {
|
func (s *Sandbox) CreateContainer(conf vc.ContainerConfig) (vc.VCContainer, error) {
|
||||||
return &Container{}, nil
|
return &Container{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteContainer implements the VCSandbox function of the same name.
|
// DeleteContainer implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) DeleteContainer(contID string) (vc.VCContainer, error) {
|
func (s *Sandbox) DeleteContainer(contID string) (vc.VCContainer, error) {
|
||||||
return &Container{}, nil
|
return &Container{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartContainer implements the VCSandbox function of the same name.
|
// StartContainer implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) StartContainer(contID string) (vc.VCContainer, error) {
|
func (s *Sandbox) StartContainer(contID string) (vc.VCContainer, error) {
|
||||||
return &Container{}, nil
|
return &Container{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusContainer implements the VCSandbox function of the same name.
|
// StatusContainer implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) StatusContainer(contID string) (vc.ContainerStatus, error) {
|
func (s *Sandbox) StatusContainer(contID string) (vc.ContainerStatus, error) {
|
||||||
return vc.ContainerStatus{}, nil
|
return vc.ContainerStatus{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatsContainer implements the VCSandbox function of the same name.
|
// StatsContainer implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) StatsContainer(contID string) (vc.ContainerStats, error) {
|
func (s *Sandbox) StatsContainer(contID string) (vc.ContainerStats, error) {
|
||||||
return vc.ContainerStats{}, nil
|
return vc.ContainerStats{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status implements the VCSandbox function of the same name.
|
// Status implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) Status() vc.SandboxStatus {
|
func (s *Sandbox) Status() vc.SandboxStatus {
|
||||||
return vc.SandboxStatus{}
|
return vc.SandboxStatus{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnterContainer implements the VCSandbox function of the same name.
|
// EnterContainer implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) EnterContainer(containerID string, cmd vc.Cmd) (vc.VCContainer, *vc.Process, error) {
|
func (s *Sandbox) EnterContainer(containerID string, cmd vc.Cmd) (vc.VCContainer, *vc.Process, error) {
|
||||||
return &Container{}, &vc.Process{}, nil
|
return &Container{}, &vc.Process{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Monitor implements the VCSandbox function of the same name.
|
// Monitor implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) Monitor() (chan error, error) {
|
func (s *Sandbox) Monitor() (chan error, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateContainer implements the VCSandbox function of the same name.
|
// UpdateContainer implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) UpdateContainer(containerID string, resources specs.LinuxResources) error {
|
func (s *Sandbox) UpdateContainer(containerID string, resources specs.LinuxResources) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitProcess implements the VCSandbox function of the same name.
|
// WaitProcess implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) WaitProcess(containerID, processID string) (int32, error) {
|
func (s *Sandbox) WaitProcess(containerID, processID string) (int32, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignalProcess implements the VCSandbox function of the same name.
|
// SignalProcess implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) SignalProcess(containerID, processID string, signal syscall.Signal, all bool) error {
|
func (s *Sandbox) SignalProcess(containerID, processID string, signal syscall.Signal, all bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WinsizeProcess implements the VCSandbox function of the same name.
|
// WinsizeProcess implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) WinsizeProcess(containerID, processID string, height, width uint32) error {
|
func (s *Sandbox) WinsizeProcess(containerID, processID string, height, width uint32) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IOStream implements the VCSandbox function of the same name.
|
// IOStream implements the VCSandbox function of the same name.
|
||||||
func (p *Sandbox) IOStream(containerID, processID string) (io.WriteCloser, io.Reader, io.Reader, error) {
|
func (s *Sandbox) IOStream(containerID, processID string) (io.WriteCloser, io.Reader, io.Reader, error) {
|
||||||
return nil, nil, nil, nil
|
return nil, nil, nil, nil
|
||||||
}
|
}
|
||||||
|
@ -1326,22 +1326,22 @@ func togglePauseSandbox(sandboxID string, pause bool) (*Sandbox, error) {
|
|||||||
defer unlockSandbox(lockFile)
|
defer unlockSandbox(lockFile)
|
||||||
|
|
||||||
// Fetch the sandbox from storage and create it.
|
// Fetch the sandbox from storage and create it.
|
||||||
p, err := fetchSandbox(sandboxID)
|
s, err := fetchSandbox(sandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if pause {
|
if pause {
|
||||||
err = p.Pause()
|
err = s.Pause()
|
||||||
} else {
|
} else {
|
||||||
err = p.Resume()
|
err = s.Resume()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return p, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HotplugAddDevice is used for add a device to sandbox
|
// HotplugAddDevice is used for add a device to sandbox
|
||||||
|
Loading…
Reference in New Issue
Block a user