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

Commit

Permalink
containerd-shim-kata-v2: retune the code style
Browse files Browse the repository at this point in the history
Removed some unused variables and retuned some
if/else code style.

Fixes: #572

Signed-off-by: fupan <[email protected]>
  • Loading branch information
lifupan committed Aug 10, 2018
1 parent 8fdf25e commit 3e86062
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 53 deletions.
9 changes: 4 additions & 5 deletions cli/containerd-shim-kata-v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
package main

import (
"fmt"
"os"
"fmt"
"os"

"github.com/kata-containers/runtime/containerd-shim/kata"
"github.com/containerd/containerd/runtime/v2/shim"
"github.com/containerd/containerd/runtime/v2/shim"
"github.com/kata-containers/runtime/containerd-shim/kata"
)

func main() {
Expand All @@ -19,4 +19,3 @@ func main() {
os.Exit(1)
}
}

3 changes: 0 additions & 3 deletions containerd-shim/kata/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,20 @@ import (
)

var defaultHypervisorPath = "/usr/bin/qemu-lite-system-x86_64"
var defaultImagePath = "/usr/share/kata-containers/kata-containers.img"
var defaultKernelPath = "/usr/share/kata-containers/vmlinuz.container"
var defaultInitrdPath = "/usr/share/kata-containers/kata-containers-initrd.img"
var defaultFirmwarePath = ""
var defaultMachineAccelerators = ""

const defaultKernelParams = ""
const defaultMachineType = "pc"
const defaultRootDirectory = "/var/run/kata-containers"
const systemdUnitName = "kata-containers.target"

const defaultVCPUCount uint32 = 1
const defaultMaxVCPUCount uint32 = 0
const defaultMemSize uint32 = 2048 // MiB
const defaultBridgesCount uint32 = 1
const defaultInterNetworkingModel = "macvtap"
const defaultDisableBlockDeviceUse bool = false
const defaultBlockDeviceDriver = "virtio-scsi"
const defaultEnableIOThreads bool = false
const defaultEnableMemPrealloc bool = false
Expand Down
11 changes: 5 additions & 6 deletions containerd-shim/kata/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ type Container struct {
exitIOch chan struct{}
exitch chan uint32

bundle string
execs map[string]*Exec
container vc.VCContainer
status task.Status
exit uint32
time time.Time
bundle string
execs map[string]*Exec
status task.Status
exit uint32
time time.Time

mu sync.Mutex
}
Expand Down
81 changes: 42 additions & 39 deletions containerd-shim/kata/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (s *service) pid() uint32 {
if !ok {
break
} else {
pidCount += 1
pidCount++
//if it overflows, recount from 5
if pidCount < 5 {
pidCount = 5
Expand Down Expand Up @@ -378,16 +378,16 @@ func (s *service) Start(ctx context.Context, r *taskAPI.StartRequest) (*taskAPI.
return &taskAPI.StartResponse{
Pid: c.pid,
}, nil
} else { //start an exec
execs, err := startExec(ctx, s, r.ID, r.ExecID)
if err != nil {
return nil, errdefs.ToGRPC(err)
}

return &taskAPI.StartResponse{
Pid: execs.pid,
}, nil
}
//start an exec
execs, err := startExec(ctx, s, r.ID, r.ExecID)
if err != nil {
return nil, errdefs.ToGRPC(err)
}

return &taskAPI.StartResponse{
Pid: execs.pid,
}, nil
}

// Delete the initial process and container
Expand All @@ -411,21 +411,21 @@ func (s *service) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (*taskAP
ExitedAt: c.time,
Pid: c.pid,
}, nil
} else {
execs, err := c.getExec(r.ExecID)
if err != nil {
return nil, err
}
}
//deal with the exec case
execs, err := c.getExec(r.ExecID)
if err != nil {
return nil, err
}

delete(s.processes, execs.pid)
delete(c.execs, r.ExecID)
delete(s.processes, execs.pid)
delete(c.execs, r.ExecID)

return &taskAPI.DeleteResponse{
ExitStatus: uint32(execs.exitCode),
ExitedAt: execs.exitTime,
Pid: execs.pid,
}, nil
}
return &taskAPI.DeleteResponse{
ExitStatus: uint32(execs.exitCode),
ExitedAt: execs.exitTime,
Pid: execs.pid,
}, nil
}

// Exec an additional process inside the container
Expand Down Expand Up @@ -504,23 +504,26 @@ func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI.
Terminal: c.terminal,
ExitStatus: c.exit,
}, nil
} else {
execs, err := c.getExec(r.ExecID)
if err != nil {
return nil, err
}
return &taskAPI.StateResponse{
ID: execs.id,
Bundle: c.bundle,
Pid: execs.pid,
Status: execs.status,
Stdin: execs.tty.stdin,
Stdout: execs.tty.stdout,
Stderr: execs.tty.stderr,
Terminal: execs.tty.terminal,
ExitStatus: uint32(execs.exitCode),
}, nil
}

//deal with exec case
execs, err := c.getExec(r.ExecID)
if err != nil {
return nil, err
}

return &taskAPI.StateResponse{
ID: execs.id,
Bundle: c.bundle,
Pid: execs.pid,
Status: execs.status,
Stdin: execs.tty.stdin,
Stdout: execs.tty.stdout,
Stderr: execs.tty.stderr,
Terminal: execs.tty.terminal,
ExitStatus: uint32(execs.exitCode),
}, nil

}

// Pause the container
Expand Down
6 changes: 6 additions & 0 deletions containerd-shim/kata/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func startContainer(ctx context.Context, s *service, c *Container) error {
return err
}
tty, err := newTtyIO(ctx, c.stdin, c.stdout, c.stderr, c.terminal)
if err != nil {
return err
}
c.ttyio = tty

go ioCopy(c.exitIOch, tty, stdin, stdout, stderr)
Expand Down Expand Up @@ -88,6 +91,9 @@ func startExec(ctx context.Context, s *service, containerID, execID string) (*Ex
return nil, err
}
tty, err := newTtyIO(ctx, execs.tty.stdin, execs.tty.stdout, execs.tty.stderr, execs.tty.terminal)
if err != nil {
return nil, err
}
execs.ttyio = tty

go ioCopy(execs.exitIOch, tty, stdin, stdout, stderr)
Expand Down
1 change: 1 addition & 0 deletions containerd-shim/kata/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0
//

package kata

import (
Expand Down

0 comments on commit 3e86062

Please sign in to comment.