Skip to content
This repository has been archived by the owner on Feb 8, 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, at the same time, do not
export those functions and variables which will
not used out this module.

Fixes: kata-containers#572

Signed-off-by: fupan <[email protected]>
  • Loading branch information
lifupan committed Aug 14, 2018
1 parent 8fdf25e commit c637940
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 118 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
24 changes: 11 additions & 13 deletions containerd-shim/kata/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,34 @@ import (
"github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/errdefs"
taskAPI "github.com/containerd/containerd/runtime/v2/task"
vc "github.com/kata-containers/runtime/virtcontainers"
"sync"
"time"
)

type Container struct {
type container struct {
s *service
ttyio *ttyIO
pid uint32
exit uint32
id string
stdin string
stdout string
stderr string
ttyio *TtyIO
terminal bool

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
time time.Time

mu sync.Mutex
}

func newContainer(s *service, r *taskAPI.CreateTaskRequest, pid uint32, container vc.VCContainer) *Container {
c := &Container{
func newContainer(s *service, r *taskAPI.CreateTaskRequest, pid uint32) *container {
c := &container{
s: s,
pid: pid,
id: r.ID,
Expand All @@ -47,7 +45,7 @@ func newContainer(s *service, r *taskAPI.CreateTaskRequest, pid uint32, containe
stdout: r.Stdout,
stderr: r.Stderr,
terminal: r.Terminal,
execs: make(map[string]*Exec),
execs: make(map[string]*exec),
status: task.StatusCreated,
exitIOch: make(chan struct{}),
exitch: make(chan uint32, 1),
Expand All @@ -56,7 +54,7 @@ func newContainer(s *service, r *taskAPI.CreateTaskRequest, pid uint32, containe
return c
}

func (c *Container) getExec(id string) (*Exec, error) {
func (c *container) getExec(id string) (*exec, error) {
exec := c.execs[id]

if exec == nil {
Expand Down
2 changes: 1 addition & 1 deletion containerd-shim/kata/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"path"
)

func deleteContainer(s *service, c *Container) error {
func deleteContainer(s *service, c *container) error {

status, err := s.sandbox.StatusContainer(c.id)
if err != nil {
Expand Down
24 changes: 13 additions & 11 deletions containerd-shim/kata/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@ import (
"time"
)

type Exec struct {
type exec struct {
container *container
cmds *vc.Cmd
tty *tty
ttyio *ttyIO
id string
pid uint32
container *Container
cmds *vc.Cmd
exitCode int32
tty *Tty
ttyio *TtyIO
status task.Status

exitCode int32

status task.Status

exitIOch chan struct{}
exitch chan uint32

exitTime time.Time
}

type Tty struct {
type tty struct {
stdin string
stdout string
stderr string
Expand Down Expand Up @@ -60,7 +62,7 @@ func getEnvs(envs []string) []vc.EnvVar {
return vcEnvs
}

func newExec(c *Container, stdin, stdout, stderr string, terminal bool, jspec *googleProtobuf.Any) (*Exec, error) {
func newExec(c *container, stdin, stdout, stderr string, terminal bool, jspec *googleProtobuf.Any) (*exec, error) {
var height uint32
var width uint32

Expand All @@ -75,7 +77,7 @@ func newExec(c *Container, stdin, stdout, stderr string, terminal bool, jspec *g
width = uint32(spec.ConsoleSize.Width)
}

tty := &Tty{
tty := &tty{
stdin: stdin,
stdout: stdout,
stderr: stderr,
Expand All @@ -95,7 +97,7 @@ func newExec(c *Container, stdin, stdout, stderr string, terminal bool, jspec *g
NoNewPrivileges: spec.NoNewPrivileges,
}

exec := &Exec{
exec := &exec{
container: c,
cmds: cmds,
tty: tty,
Expand Down
1 change: 1 addition & 0 deletions containerd-shim/kata/metrics.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
Loading

0 comments on commit c637940

Please sign in to comment.