Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #326 from jshachm/fix-pod-to-sandbox
Browse files Browse the repository at this point in the history
virtcontainers: fix codes misunderstanding in virtcontainers
  • Loading branch information
caoruidong authored May 21, 2018
2 parents 8347f4d + 7abb8fe commit 92ec15d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 69 deletions.
72 changes: 36 additions & 36 deletions virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ func DeleteSandbox(sandboxID string) (VCSandbox, error) {
defer unlockSandbox(lockFile)

// Fetch the sandbox from storage and create it.
p, err := fetchSandbox(sandboxID)
s, err := fetchSandbox(sandboxID)
if err != nil {
return nil, err
}

// Delete it.
if err := p.Delete(); err != nil {
if err := s.Delete(); err != nil {
return nil, err
}

return p, nil
return s, nil
}

// FetchSandbox is the virtcontainers sandbox fetching entry point.
Expand Down Expand Up @@ -129,27 +129,27 @@ func StartSandbox(sandboxID string) (VCSandbox, error) {
defer unlockSandbox(lockFile)

// Fetch the sandbox from storage and create it.
p, err := fetchSandbox(sandboxID)
s, err := fetchSandbox(sandboxID)
if err != nil {
return nil, err
}

return startSandbox(p)
return startSandbox(s)
}

func startSandbox(p *Sandbox) (*Sandbox, error) {
func startSandbox(s *Sandbox) (*Sandbox, error) {
// Start it
err := p.start()
err := s.start()
if err != nil {
return nil, err
}

// 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 p, nil
return s, nil
}

// StopSandbox is the virtcontainers sandbox stopping entry point.
Expand All @@ -166,45 +166,45 @@ func StopSandbox(sandboxID string) (VCSandbox, error) {
defer unlockSandbox(lockFile)

// Fetch the sandbox from storage and create it.
p, err := fetchSandbox(sandboxID)
s, err := fetchSandbox(sandboxID)
if err != nil {
return nil, err
}

// Stop it.
err = p.stop()
err = s.stop()
if err != nil {
return nil, err
}

// Remove the network.
if err := p.removeNetwork(); err != nil {
if err := s.removeNetwork(); err != nil {
return nil, err
}

// 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 p, nil
return s, nil
}

// RunSandbox is the virtcontainers sandbox running entry point.
// RunSandbox creates a sandbox and its containers and then it starts them.
func RunSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) {
p, err := createSandboxFromConfig(sandboxConfig)
s, err := createSandboxFromConfig(sandboxConfig)
if err != nil {
return nil, err
}

lockFile, err := rwLockSandbox(p.id)
lockFile, err := rwLockSandbox(s.id)
if err != nil {
return nil, err
}
defer unlockSandbox(lockFile)

return startSandbox(p)
return startSandbox(s)
}

// ListSandbox is the virtcontainers sandbox listing entry point.
Expand Down Expand Up @@ -250,7 +250,7 @@ func StatusSandbox(sandboxID string) (SandboxStatus, error) {
return SandboxStatus{}, err
}

sandbox, err := fetchSandbox(sandboxID)
s, err := fetchSandbox(sandboxID)
if err != nil {
unlockSandbox(lockFile)
return SandboxStatus{}, err
Expand All @@ -263,12 +263,12 @@ func StatusSandbox(sandboxID string) (SandboxStatus, error) {
// 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
// last operation executed by this function.
defer sandbox.wg.Wait()
defer s.wg.Wait()
defer unlockSandbox(lockFile)

var contStatusList []ContainerStatus
for _, container := range sandbox.containers {
contStatus, err := statusContainer(sandbox, container.id)
for _, container := range s.containers {
contStatus, err := statusContainer(s, container.id)
if err != nil {
return SandboxStatus{}, err
}
Expand All @@ -277,13 +277,13 @@ func StatusSandbox(sandboxID string) (SandboxStatus, error) {
}

sandboxStatus := SandboxStatus{
ID: sandbox.id,
State: sandbox.state,
Hypervisor: sandbox.config.HypervisorType,
HypervisorConfig: sandbox.config.HypervisorConfig,
Agent: sandbox.config.AgentType,
ID: s.id,
State: s.state,
Hypervisor: s.config.HypervisorType,
HypervisorConfig: s.config.HypervisorConfig,
Agent: s.config.AgentType,
ContainersStatus: contStatusList,
Annotations: sandbox.config.Annotations,
Annotations: s.config.Annotations,
}

return sandboxStatus, nil
Expand Down Expand Up @@ -388,13 +388,13 @@ func StopContainer(sandboxID, containerID string) (VCContainer, error) {
}
defer unlockSandbox(lockFile)

p, err := fetchSandbox(sandboxID)
s, err := fetchSandbox(sandboxID)
if err != nil {
return nil, err
}

// Fetch the container.
c, err := p.findContainer(containerID)
c, err := s.findContainer(containerID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -454,7 +454,7 @@ func StatusContainer(sandboxID, containerID string) (ContainerStatus, error) {
return ContainerStatus{}, err
}

sandbox, err := fetchSandbox(sandboxID)
s, err := fetchSandbox(sandboxID)
if err != nil {
unlockSandbox(lockFile)
return ContainerStatus{}, err
Expand All @@ -467,10 +467,10 @@ func StatusContainer(sandboxID, containerID string) (ContainerStatus, error) {
// 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
// last operation executed by this function.
defer sandbox.wg.Wait()
defer s.wg.Wait()
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
Expand Down Expand Up @@ -541,13 +541,13 @@ func KillContainer(sandboxID, containerID string, signal syscall.Signal, all boo
}
defer unlockSandbox(lockFile)

p, err := fetchSandbox(sandboxID)
s, err := fetchSandbox(sandboxID)
if err != nil {
return err
}

// Fetch the container.
c, err := p.findContainer(containerID)
c, err := s.findContainer(containerID)
if err != nil {
return err
}
Expand Down Expand Up @@ -590,13 +590,13 @@ func ProcessListContainer(sandboxID, containerID string, options ProcessListOpti
}
defer unlockSandbox(lockFile)

p, err := fetchSandbox(sandboxID)
s, err := fetchSandbox(sandboxID)
if err != nil {
return nil, err
}

// Fetch the container.
c, err := p.findContainer(containerID)
c, err := s.findContainer(containerID)
if err != nil {
return nil, err
}
Expand Down
58 changes: 29 additions & 29 deletions virtcontainers/pkg/vcmock/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,39 @@ import (
)

// ID implements the VCSandbox function of the same name.
func (p *Sandbox) ID() string {
return p.MockID
func (s *Sandbox) ID() string {
return s.MockID
}

// Annotations implements the VCSandbox function of the same name.
func (p *Sandbox) Annotations(key string) (string, error) {
return p.MockAnnotations[key], nil
func (s *Sandbox) Annotations(key string) (string, error) {
return s.MockAnnotations[key], nil
}

// 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
}

// GetAnnotations implements the VCSandbox function of the same name.
func (p *Sandbox) GetAnnotations() map[string]string {
return p.MockAnnotations
func (s *Sandbox) GetAnnotations() map[string]string {
return s.MockAnnotations
}

// GetAllContainers implements the VCSandbox function of the same name.
func (p *Sandbox) GetAllContainers() []vc.VCContainer {
var ifa = make([]vc.VCContainer, len(p.MockContainers))
func (s *Sandbox) GetAllContainers() []vc.VCContainer {
var ifa = make([]vc.VCContainer, len(s.MockContainers))

for i, v := range p.MockContainers {
for i, v := range s.MockContainers {
ifa[i] = v
}

return ifa
}

// GetContainer implements the VCSandbox function of the same name.
func (p *Sandbox) GetContainer(containerID string) vc.VCContainer {
for _, c := range p.MockContainers {
func (s *Sandbox) GetContainer(containerID string) vc.VCContainer {
for _, c := range s.MockContainers {
if c.MockID == containerID {
return c
}
Expand All @@ -55,86 +55,86 @@ func (p *Sandbox) GetContainer(containerID string) vc.VCContainer {
}

// Release implements the VCSandbox function of the same name.
func (p *Sandbox) Release() error {
func (s *Sandbox) Release() error {
return nil
}

// Pause implements the VCSandbox function of the same name.
func (p *Sandbox) Pause() error {
func (s *Sandbox) Pause() error {
return nil
}

// Resume implements the VCSandbox function of the same name.
func (p *Sandbox) Resume() error {
func (s *Sandbox) Resume() error {
return nil
}

// Delete implements the VCSandbox function of the same name.
func (p *Sandbox) Delete() error {
func (s *Sandbox) Delete() error {
return nil
}

// 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
}

// 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
}

// 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
}

// 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
}

// 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
}

// Status implements the VCSandbox function of the same name.
func (p *Sandbox) Status() vc.SandboxStatus {
func (s *Sandbox) Status() vc.SandboxStatus {
return vc.SandboxStatus{}
}

// 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
}

// 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
}

// 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
}

// 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
}

// 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
}

// 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
}

// 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
}
Loading

0 comments on commit 92ec15d

Please sign in to comment.