Remove containerd files
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
992fdbfd76
commit
e115b52ce2
74 changed files with 0 additions and 9757 deletions
|
@ -1,75 +0,0 @@
|
|||
// single app that will run containers in containerd and output
|
||||
// the total time in seconds that it took for the execution.
|
||||
// go run benchmark.go -count 1000 -bundle /containers/redis
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"net"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/containerd/api/grpc/types"
|
||||
netcontext "golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&bundle, "bundle", "/containers/redis", "the bundle path")
|
||||
flag.StringVar(&addr, "addr", "/run/containerd/containerd.sock", "address to the container d instance")
|
||||
flag.IntVar(&count, "count", 1000, "number of containers to run")
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
var (
|
||||
count int
|
||||
bundle, addr string
|
||||
group = sync.WaitGroup{}
|
||||
jobs = make(chan string, 20)
|
||||
)
|
||||
|
||||
func getClient() types.APIClient {
|
||||
dialOpts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
dialOpts = append(dialOpts,
|
||||
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
|
||||
return net.DialTimeout("unix", addr, timeout)
|
||||
},
|
||||
))
|
||||
conn, err := grpc.Dial(addr, dialOpts...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
return types.NewAPIClient(conn)
|
||||
}
|
||||
|
||||
func main() {
|
||||
client := getClient()
|
||||
for i := 0; i < 100; i++ {
|
||||
group.Add(1)
|
||||
go worker(client)
|
||||
}
|
||||
start := time.Now()
|
||||
for i := 0; i < count; i++ {
|
||||
id := strconv.Itoa(i)
|
||||
jobs <- id
|
||||
}
|
||||
close(jobs)
|
||||
group.Wait()
|
||||
end := time.Now()
|
||||
duration := end.Sub(start).Seconds()
|
||||
logrus.Info(duration)
|
||||
}
|
||||
|
||||
func worker(client types.APIClient) {
|
||||
defer group.Done()
|
||||
for id := range jobs {
|
||||
if _, err := client.CreateContainer(netcontext.Background(), &types.CreateContainerRequest{
|
||||
Id: id,
|
||||
BundlePath: bundle,
|
||||
}); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
140
hack/example/main.go
Normal file
140
hack/example/main.go
Normal file
|
@ -0,0 +1,140 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/containerkit"
|
||||
"github.com/docker/containerkit/osutils"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
|
||||
func reloadContainer() error {
|
||||
dockerContainer := &testConfig{}
|
||||
container, err := containerkit.LoadContainer(dockerContainer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// wait for it to exit and get the exit status
|
||||
logrus.Info("wait container")
|
||||
status, err := container.Wait()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// delete the container after it is done
|
||||
logrus.Info("delete container")
|
||||
if container.Delete(); err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("exit status %d", status)
|
||||
return nil
|
||||
}
|
||||
|
||||
func runContainer() error {
|
||||
// create a new runtime runtime that implements the ExecutionDriver interface
|
||||
dockerContainer := &testConfig{}
|
||||
|
||||
// create a new container
|
||||
container, err := containerkit.NewContainer(dockerContainer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// setup some stdio for our container
|
||||
container.Stdin = Stdin("")
|
||||
container.Stdout = Stdout("")
|
||||
container.Stderr = Stderr("")
|
||||
|
||||
// go ahead and set the container in the create state and have it ready to start
|
||||
logrus.Info("create container")
|
||||
if err := container.Create(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// start the user defined process in the container
|
||||
logrus.Info("start container")
|
||||
if err := container.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := 0; i < exec; i++ {
|
||||
process, err := container.NewProcess(&specs.Process{
|
||||
Args: []string{
|
||||
"sh", "-c",
|
||||
"echo " + fmt.Sprintf("sup from itteration %d", i),
|
||||
},
|
||||
Env: env,
|
||||
Terminal: false,
|
||||
Cwd: "/",
|
||||
NoNewPrivileges: true,
|
||||
Capabilities: caps,
|
||||
})
|
||||
|
||||
process.Stdin = Stdin(strconv.Itoa(i))
|
||||
stdout := Stdout(strconv.Itoa(i))
|
||||
|
||||
stderr := Stderr(strconv.Itoa(i))
|
||||
go io.Copy(os.Stdout, stdout)
|
||||
go io.Copy(os.Stdout, stderr)
|
||||
process.Stdout = stdout
|
||||
process.Stderr = stderr
|
||||
|
||||
if err := process.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
procStatus, err := process.Wait()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("process %d returned with %d", i, procStatus)
|
||||
}
|
||||
|
||||
if load {
|
||||
return nil
|
||||
}
|
||||
|
||||
// wait for it to exit and get the exit status
|
||||
logrus.Info("wait container")
|
||||
status, err := container.Wait()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// delete the container after it is done
|
||||
logrus.Info("delete container")
|
||||
if container.Delete(); err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("exit status %d", status)
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
exec int
|
||||
load bool
|
||||
reload bool
|
||||
)
|
||||
|
||||
// "Hooks do optional work. Drivers do mandatory work"
|
||||
func main() {
|
||||
flag.IntVar(&exec, "exec", 0, "run n number of execs")
|
||||
flag.BoolVar(&load, "load", false, "reload the container")
|
||||
flag.BoolVar(&reload, "reload", false, "reload the container live")
|
||||
flag.Parse()
|
||||
if err := osutils.SetSubreaper(1); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
if reload {
|
||||
if err := reloadContainer(); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err := runContainer(); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
232
hack/example/utils.go
Normal file
232
hack/example/utils.go
Normal file
|
@ -0,0 +1,232 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/docker/containerd/shim"
|
||||
"github.com/docker/containerkit"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
|
||||
var (
|
||||
RWM = "rwm"
|
||||
caps = []string{
|
||||
"CAP_AUDIT_WRITE",
|
||||
"CAP_KILL",
|
||||
"CAP_FOWNER",
|
||||
"CAP_CHOWN",
|
||||
"CAP_MKNOD",
|
||||
"CAP_FSETID",
|
||||
"CAP_DAC_OVERRIDE",
|
||||
"CAP_SETFCAP",
|
||||
"CAP_SETPCAP",
|
||||
"CAP_SETGID",
|
||||
"CAP_SETUID",
|
||||
"CAP_NET_BIND_SERVICE",
|
||||
}
|
||||
env = []string{
|
||||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||
}
|
||||
)
|
||||
|
||||
type testConfig struct {
|
||||
}
|
||||
|
||||
func (t *testConfig) ID() string {
|
||||
return "test"
|
||||
}
|
||||
|
||||
func (t *testConfig) Root() string {
|
||||
return "/var/lib/containerkit"
|
||||
}
|
||||
|
||||
func (t *testConfig) Runtime() (containerkit.Runtime, error) {
|
||||
return shim.New(shim.Opts{
|
||||
Root: "/run/cshim/test",
|
||||
Name: "containerd-shim",
|
||||
RuntimeName: "runc",
|
||||
RuntimeRoot: "/run/runc",
|
||||
Timeout: 5 * time.Second,
|
||||
})
|
||||
// TODO: support loading of runtime
|
||||
// create a new runtime runtime that implements the ExecutionDriver interface
|
||||
return shim.Load("/run/cshim/test")
|
||||
}
|
||||
|
||||
func (t *testConfig) Spec() (*specs.Spec, error) {
|
||||
var (
|
||||
cgpath = filepath.Join("/containerkit", t.ID())
|
||||
m = &containerkit.Mount{
|
||||
Target: "/",
|
||||
Type: "bind",
|
||||
Source: "/containers/redis/rootfs",
|
||||
Options: []string{
|
||||
"rbind",
|
||||
"rw",
|
||||
},
|
||||
}
|
||||
)
|
||||
return &specs.Spec{
|
||||
Version: specs.Version,
|
||||
Platform: specs.Platform{
|
||||
OS: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
},
|
||||
Root: specs.Root{
|
||||
Path: "rootfs",
|
||||
Readonly: false,
|
||||
},
|
||||
Process: specs.Process{
|
||||
Env: env,
|
||||
Args: []string{"sleep", "30"},
|
||||
Terminal: false,
|
||||
Cwd: "/",
|
||||
NoNewPrivileges: true,
|
||||
Capabilities: caps,
|
||||
},
|
||||
Hostname: "containerkit",
|
||||
Mounts: []specs.Mount{
|
||||
{
|
||||
Destination: m.Target,
|
||||
Type: m.Type,
|
||||
Source: m.Source,
|
||||
Options: m.Options,
|
||||
},
|
||||
{
|
||||
Destination: "/proc",
|
||||
Type: "proc",
|
||||
Source: "proc",
|
||||
},
|
||||
{
|
||||
Destination: "/dev",
|
||||
Type: "tmpfs",
|
||||
Source: "tmpfs",
|
||||
Options: []string{"nosuid", "strictatime", "mode=755", "size=65536k"},
|
||||
},
|
||||
{
|
||||
Destination: "/dev/pts",
|
||||
Type: "devpts",
|
||||
Source: "devpts",
|
||||
Options: []string{"nosuid", "noexec", "newinstance", "ptmxmode=0666", "mode=0620", "gid=5"},
|
||||
},
|
||||
{
|
||||
Destination: "/dev/shm",
|
||||
Type: "tmpfs",
|
||||
Source: "shm",
|
||||
Options: []string{"nosuid", "noexec", "nodev", "mode=1777", "size=65536k"},
|
||||
},
|
||||
{
|
||||
Destination: "/dev/mqueue",
|
||||
Type: "mqueue",
|
||||
Source: "mqueue",
|
||||
Options: []string{"nosuid", "noexec", "nodev"},
|
||||
},
|
||||
{
|
||||
Destination: "/sys",
|
||||
Type: "sysfs",
|
||||
Source: "sysfs",
|
||||
Options: []string{"nosuid", "noexec", "nodev"},
|
||||
},
|
||||
{
|
||||
Destination: "/run",
|
||||
Type: "tmpfs",
|
||||
Source: "tmpfs",
|
||||
Options: []string{"nosuid", "strictatime", "mode=755", "size=65536k"},
|
||||
},
|
||||
{
|
||||
Destination: "/etc/resolv.conf",
|
||||
Type: "bind",
|
||||
Source: "/etc/resolv.conf",
|
||||
Options: []string{"rbind", "ro"},
|
||||
},
|
||||
{
|
||||
Destination: "/etc/hosts",
|
||||
Type: "bind",
|
||||
Source: "/etc/hosts",
|
||||
Options: []string{"rbind", "ro"},
|
||||
},
|
||||
{
|
||||
Destination: "/etc/localtime",
|
||||
Type: "bind",
|
||||
Source: "/etc/localtime",
|
||||
Options: []string{"rbind", "ro"},
|
||||
},
|
||||
},
|
||||
Linux: &specs.Linux{
|
||||
CgroupsPath: &cgpath,
|
||||
Resources: &specs.LinuxResources{
|
||||
Devices: []specs.LinuxDeviceCgroup{
|
||||
{
|
||||
Allow: false,
|
||||
Access: &RWM,
|
||||
},
|
||||
},
|
||||
},
|
||||
Namespaces: []specs.LinuxNamespace{
|
||||
{
|
||||
Type: "pid",
|
||||
},
|
||||
{
|
||||
Type: "ipc",
|
||||
},
|
||||
{
|
||||
Type: "uts",
|
||||
},
|
||||
{
|
||||
Type: "mount",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func Stdin(n string) *os.File {
|
||||
abs, err := filepath.Abs("stdin" + n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := unix.Mkfifo(abs, 0755); err != nil && !os.IsExist(err) {
|
||||
panic(err)
|
||||
}
|
||||
f, err := os.OpenFile(abs, syscall.O_RDWR, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func Stdout(n string) *os.File {
|
||||
abs, err := filepath.Abs("stdout" + n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := unix.Mkfifo(abs, 0755); err != nil && !os.IsExist(err) {
|
||||
panic(err)
|
||||
}
|
||||
f, err := os.OpenFile(abs, syscall.O_RDWR, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func Stderr(n string) *os.File {
|
||||
abs, err := filepath.Abs("stderr" + n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := unix.Mkfifo(abs, 0755); err != nil && !os.IsExist(err) {
|
||||
panic(err)
|
||||
}
|
||||
f, err := os.OpenFile(abs, syscall.O_RDWR, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return f
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue