WIP create container
Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
parent
a36a83963c
commit
fb3f5b6b9a
2 changed files with 232 additions and 80 deletions
|
@ -20,6 +20,7 @@ var (
|
||||||
stores = make(map[storage.Store]struct{})
|
stores = make(map[storage.Store]struct{})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func getStore(c *libkpod.Config) (storage.Store, error) {
|
func getStore(c *libkpod.Config) (storage.Store, error) {
|
||||||
options := storage.DefaultStoreOptions
|
options := storage.DefaultStoreOptions
|
||||||
options.GraphRoot = c.Root
|
options.GraphRoot = c.Root
|
||||||
|
@ -134,13 +135,14 @@ func validateFlags(c *cli.Context, flags []cli.Flag) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Common flags shared between commands
|
// Common flags shared between commands
|
||||||
var createFlags = []cli.Flag{
|
var createFlags = []cli.Flag{
|
||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{ //
|
||||||
Name: "add-host",
|
Name: "add-host",
|
||||||
Usage: "Add a custom host-to-IP mapping (host:ip) (default [])",
|
Usage: "Add a custom host-to-IP mapping (host:ip) (default [])",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{ //
|
||||||
Name: "attach, a",
|
Name: "attach, a",
|
||||||
Usage: "Attach to STDIN, STDOUT or STDERR (default [])",
|
Usage: "Attach to STDIN, STDOUT or STDERR (default [])",
|
||||||
},
|
},
|
||||||
|
@ -168,7 +170,7 @@ var createFlags = []cli.Flag{
|
||||||
Name: "cpu-count",
|
Name: "cpu-count",
|
||||||
Usage: "Limit the number of CPUs available for execution by the container.",
|
Usage: "Limit the number of CPUs available for execution by the container.",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{ //
|
||||||
Name: "cid-file",
|
Name: "cid-file",
|
||||||
Usage: "Write the container ID to the file",
|
Usage: "Write the container ID to the file",
|
||||||
},
|
},
|
||||||
|
@ -208,7 +210,7 @@ var createFlags = []cli.Flag{
|
||||||
Name: "detach, d",
|
Name: "detach, d",
|
||||||
Usage: "Run container in background and print container ID",
|
Usage: "Run container in background and print container ID",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{ //
|
||||||
Name: "detach-keys",
|
Name: "detach-keys",
|
||||||
Usage: "Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`",
|
Usage: "Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`",
|
||||||
},
|
},
|
||||||
|
@ -253,7 +255,7 @@ var createFlags = []cli.Flag{
|
||||||
Usage: "Set environment variables in container",
|
Usage: "Set environment variables in container",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{
|
||||||
Name: "env-file",
|
Name: "env-file", //
|
||||||
Usage: "Read in a file of environment variables",
|
Usage: "Read in a file of environment variables",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{
|
||||||
|
@ -280,7 +282,7 @@ var createFlags = []cli.Flag{
|
||||||
Name: "ip6",
|
Name: "ip6",
|
||||||
Usage: "Container IPv6 address (e.g. 2001:db8::1b99)",
|
Usage: "Container IPv6 address (e.g. 2001:db8::1b99)",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{ //
|
||||||
Name: "ipc",
|
Name: "ipc",
|
||||||
Usage: "IPC Namespace to use",
|
Usage: "IPC Namespace to use",
|
||||||
},
|
},
|
||||||
|
@ -292,7 +294,7 @@ var createFlags = []cli.Flag{
|
||||||
Name: "label",
|
Name: "label",
|
||||||
Usage: "Set metadata on container (default [])",
|
Usage: "Set metadata on container (default [])",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{ //
|
||||||
Name: "label-file",
|
Name: "label-file",
|
||||||
Usage: "Read in a line delimited file of labels (default [])",
|
Usage: "Read in a line delimited file of labels (default [])",
|
||||||
},
|
},
|
||||||
|
@ -344,7 +346,7 @@ var createFlags = []cli.Flag{
|
||||||
Name: "network-alias",
|
Name: "network-alias",
|
||||||
Usage: "Add network-scoped alias for the container (default [])",
|
Usage: "Add network-scoped alias for the container (default [])",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{ //
|
||||||
Name: "oom-kill-disable",
|
Name: "oom-kill-disable",
|
||||||
Usage: "Disable OOM Killer",
|
Usage: "Disable OOM Killer",
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,94 +7,96 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type createResourceConfig struct {
|
type createResourceConfig struct {
|
||||||
blkioWeight int64
|
blkioWeight int64 // blkio-weight
|
||||||
blkioDevice []string
|
blkioDevice []string // blkio-weight
|
||||||
cpuShares int64
|
cpuShares int64 // cpu-shares
|
||||||
cpuCount int64
|
cpuCount int64 // cpu-count
|
||||||
cpuPeriod int64
|
cpuPeriod int64 // cpu-period
|
||||||
cpusetCpus string
|
cpusetCpus string
|
||||||
cpusetNames string
|
cpusetNames string
|
||||||
cpuFile string
|
cpuFile string
|
||||||
cpuMems string
|
cpuMems string // cpuset-mems
|
||||||
cpuQuota int64
|
cpuQuota int64 // cpu-quota
|
||||||
cpuRtPeriod int64
|
cpuRtPeriod int64 // cpu-rt-period
|
||||||
cpuRtRuntime int64
|
cpuRtRuntime int64 // cpu-rt-runtime
|
||||||
cpus int64
|
cpus int64 // cpus
|
||||||
deviceReadBps []string
|
deviceReadBps []string // device-read-bps
|
||||||
deviceReadIops []string
|
deviceReadIops []string // device-read-iops
|
||||||
deviceWriteBps []string
|
deviceWriteBps []string // device-write-bps
|
||||||
deviceWriteIops []string
|
deviceWriteIops []string // device-write-iops
|
||||||
memory string
|
memory string //memory
|
||||||
memoryReservation string
|
memoryReservation string // memory-reservation
|
||||||
memorySwap string
|
memorySwap string //memory-swap
|
||||||
memorySwapiness string
|
memorySwapiness string // memory-swappiness
|
||||||
kernelMemory string
|
kernelMemory string // kernel-memory
|
||||||
oomScoreAdj string
|
oomScoreAdj string //oom-score-adj
|
||||||
pidsLimit string
|
pidsLimit string // pids-limit
|
||||||
shmSize string
|
shmSize string
|
||||||
ulimit []string
|
ulimit []string //ulimit
|
||||||
}
|
}
|
||||||
|
|
||||||
type createConfig struct {
|
type createConfig struct {
|
||||||
additionalGroups []int64
|
additionalGroups []int64
|
||||||
args []string
|
args []string
|
||||||
capAdd []string
|
capAdd []string // cap-add
|
||||||
capDrop []string
|
capDrop []string // cap-drop
|
||||||
cgroupParent string
|
cgroupParent string // cgroup-parent
|
||||||
command string
|
command []string
|
||||||
detach bool
|
detach bool // detach
|
||||||
devices []*pb.Device
|
devices []*pb.Device // device
|
||||||
dnsOpt []string
|
dnsOpt []string //dns-opt
|
||||||
dnsSearch []string
|
dnsSearch []string //dns-search
|
||||||
dnsServers []string
|
dnsServers []string //dns
|
||||||
entrypoint string
|
entrypoint string //entrypoint
|
||||||
env map[string]string
|
env []string //env
|
||||||
expose []string
|
expose []string //expose
|
||||||
groupAdd []string
|
groupAdd []string // group-add
|
||||||
hostname string
|
hostname string //hostname
|
||||||
image string
|
image string
|
||||||
interactive bool
|
interactive bool //interactive
|
||||||
ip6Address string
|
ip6Address string //ipv6
|
||||||
ipAddress string
|
ipAddress string //ip
|
||||||
labels map[string]string
|
labels map[string]string //label
|
||||||
linkLocalIP []string
|
linkLocalIP []string // link-local-ip
|
||||||
logDriver string
|
logDriver string // log-driver
|
||||||
logDriverOpt []string
|
logDriverOpt []string // log-opt
|
||||||
macAddress string
|
macAddress string //mac-address
|
||||||
mounts []*pb.Mount
|
mounts []*pb.Mount
|
||||||
name string
|
name string //name
|
||||||
network string
|
network string //network
|
||||||
networkAlias []string
|
networkAlias []string //network-alias
|
||||||
nsIPC string
|
nsIPC string // ipc
|
||||||
nsNet string
|
nsNet string //net
|
||||||
nsPID string
|
nsPID string //pid
|
||||||
nsUser string
|
nsUser string
|
||||||
pod string
|
pod string //pod
|
||||||
ports []*pb.PortMapping
|
ports []*pb.PortMapping
|
||||||
privileged bool
|
privileged bool //privileged
|
||||||
publish []string
|
publish []string //publish
|
||||||
publishAll bool
|
publishAll bool //publish-all
|
||||||
readOnlyRootfs bool
|
readOnlyRootfs bool //read-only
|
||||||
resources createResourceConfig
|
resources createResourceConfig
|
||||||
rm bool
|
rm bool //rm
|
||||||
securityOpts []string
|
securityOpts []string //security-opt
|
||||||
shmSize string
|
shmSize string //shm-size
|
||||||
sigProxy bool
|
sigProxy bool //sig-proxy
|
||||||
stdin bool
|
stdin bool
|
||||||
stopSignal string
|
stopSignal string // stop-signal
|
||||||
stopTimeout int64
|
stopTimeout int64 // stop-timeout
|
||||||
storageOpts []string
|
storageOpts []string //storage-opt
|
||||||
sysctl string
|
sysctl map[string]string //sysctl
|
||||||
tmpfs []string
|
tmpfs []string // tmpfs
|
||||||
tty bool
|
tty bool //tty
|
||||||
user int64
|
user int64 //user
|
||||||
userns string
|
userns string //userns
|
||||||
volumes []string
|
volumes []string //volume
|
||||||
volumesFrom []string
|
volumesFrom []string //volumes-from
|
||||||
workDir string
|
workDir string //workdir
|
||||||
}
|
}
|
||||||
|
|
||||||
var createDescription = "Creates a new container from the given image or" +
|
var createDescription = "Creates a new container from the given image or" +
|
||||||
|
@ -112,6 +114,11 @@ var createCommand = cli.Command{
|
||||||
ArgsUsage: "IMAGE [COMMAND [ARG...]]",
|
ArgsUsage: "IMAGE [COMMAND [ARG...]]",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func verifyImage(image string) bool{
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func createCmd(c *cli.Context) error {
|
func createCmd(c *cli.Context) error {
|
||||||
// TODO should allow user to create based off a directory on the host not just image
|
// TODO should allow user to create based off a directory on the host not just image
|
||||||
// Need CLI support for this
|
// Need CLI support for this
|
||||||
|
@ -151,10 +158,153 @@ func createCmd(c *cli.Context) error {
|
||||||
// Parses CLI options related to container creation into a config which can be
|
// Parses CLI options related to container creation into a config which can be
|
||||||
// parsed into an OCI runtime spec
|
// parsed into an OCI runtime spec
|
||||||
func parseCreateOpts(c *cli.Context) (*createConfig, error) {
|
func parseCreateOpts(c *cli.Context) (*createConfig, error) {
|
||||||
return nil, errors.Errorf("NOT IMPLEMENTED")
|
//for _, i := range(c.FlagNames()) {
|
||||||
|
// fmt.Println(i)
|
||||||
|
//}
|
||||||
|
var command []string
|
||||||
|
var env []string
|
||||||
|
sysctl := make(map[string]string)
|
||||||
|
labels := make(map[string]string)
|
||||||
|
|
||||||
|
if len(c.Args()) < 1 {
|
||||||
|
return nil, errors.Errorf("you just provide an image name")
|
||||||
|
}
|
||||||
|
if len(c.Args()) > 1 {
|
||||||
|
command = c.Args()[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(c.StringSlice("env")) > 0 {
|
||||||
|
for _, inputEnv := range(c.StringSlice("env")) {
|
||||||
|
env = append(env, inputEnv)
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
env = append(env, "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "TERM=xterm")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(c.StringSlice("sysctl")) > 0 {
|
||||||
|
for _, inputSysctl := range(c.StringSlice("sysctl")) {
|
||||||
|
values := strings.Split(inputSysctl, "=")
|
||||||
|
sysctl[values[0]] = values[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO HERE
|
||||||
|
// insert labels - baude
|
||||||
|
|
||||||
|
image := c.Args()[0]
|
||||||
|
|
||||||
|
config := &createConfig{
|
||||||
|
capAdd: c.StringSlice("cap-add"),
|
||||||
|
capDrop: c.StringSlice("cap-drop"),
|
||||||
|
cgroupParent: c.String("cgroup-parent"),
|
||||||
|
command: command,
|
||||||
|
detach: c.Bool("detach"),
|
||||||
|
dnsOpt: c.StringSlice("dns-opt"),
|
||||||
|
dnsSearch: c.StringSlice("dns-search"),
|
||||||
|
dnsServers: c.StringSlice("dns"),
|
||||||
|
entrypoint: c.String("entrypoint"),
|
||||||
|
env: env,
|
||||||
|
expose: c.StringSlice("env"),
|
||||||
|
groupAdd:c.StringSlice("group-add"),
|
||||||
|
hostname: c.String("hostname"),
|
||||||
|
image: image,
|
||||||
|
interactive: c.Bool("interactive"),
|
||||||
|
ip6Address: c.String("ipv6"),
|
||||||
|
ipAddress: c.String("ip"),
|
||||||
|
labels: labels,
|
||||||
|
linkLocalIP: c.StringSlice("link-local-ip"),
|
||||||
|
logDriver: c.String("log-driver"),
|
||||||
|
logDriverOpt: c.StringSlice("log-opt"),
|
||||||
|
macAddress:c.String("mac-address"),
|
||||||
|
name: c.String("name"),
|
||||||
|
network: c.String("network"),
|
||||||
|
networkAlias: c.StringSlice("network-alias"),
|
||||||
|
nsIPC: c.String("ipc"),
|
||||||
|
nsNet: c.String("net"),
|
||||||
|
nsPID: c.String("pid"),
|
||||||
|
pod: c.String("pod"),
|
||||||
|
privileged: c.Bool("privileged"),
|
||||||
|
publish: c.StringSlice("publish"),
|
||||||
|
publishAll: c.Bool("publish-all"),
|
||||||
|
readOnlyRootfs: c.Bool("read-only"),
|
||||||
|
resources:createResourceConfig{
|
||||||
|
blkioWeight:c.Int64("blkio-weight"),
|
||||||
|
blkioDevice: c.StringSlice("blkio-device"),
|
||||||
|
cpuShares:c.Int64("cpu-shares"),
|
||||||
|
cpuCount: c.Int64("cpu-count"),
|
||||||
|
cpuPeriod:c.Int64("cpu-period"),
|
||||||
|
cpusetCpus:c.String("cpu-period"),
|
||||||
|
cpuMems:c.String("cpuset-mems"),
|
||||||
|
cpuQuota: c.Int64("cpu-quota"),
|
||||||
|
cpuRtPeriod: c.Int64("cpu-rt-period"),
|
||||||
|
cpuRtRuntime: c.Int64("cpu-rt-runtime"),
|
||||||
|
cpus: c.Int64("cpus"),
|
||||||
|
deviceReadBps: c.StringSlice("device-read-bps"),
|
||||||
|
deviceReadIops:c.StringSlice("device-read-iops"),
|
||||||
|
deviceWriteBps:c.StringSlice("device-write-bps"),
|
||||||
|
deviceWriteIops:c.StringSlice("device-write-iops"),
|
||||||
|
memory: c.String("memory"),
|
||||||
|
memoryReservation: c.String("memory-reservation"),
|
||||||
|
memorySwap: c.String("memory-swap"),
|
||||||
|
memorySwapiness:c.String("memory-swapiness"),
|
||||||
|
kernelMemory: c.String("kernel-memory"),
|
||||||
|
oomScoreAdj:c.String("oom-score-adj"),
|
||||||
|
pidsLimit: c.String("pids-limit"),
|
||||||
|
ulimit:c.StringSlice("ulimit"),
|
||||||
|
},
|
||||||
|
rm: c.Bool("rm"),
|
||||||
|
securityOpts:c.StringSlice("security-opt"),
|
||||||
|
shmSize: c.String("shm-size"),
|
||||||
|
sigProxy:c.Bool("sig-proxy"),
|
||||||
|
stopSignal:c.String("stop-signal"),
|
||||||
|
stopTimeout:c.Int64("stop-timeout"),
|
||||||
|
storageOpts:c.StringSlice("storage-opt"),
|
||||||
|
sysctl: sysctl,
|
||||||
|
tmpfs: c.StringSlice("tmpfs"),
|
||||||
|
tty: c.Bool("tty"), //
|
||||||
|
user: c.Int64("user"),
|
||||||
|
userns: c.String("userns"),
|
||||||
|
volumes:c.StringSlice("volume"),
|
||||||
|
volumesFrom:c.StringSlice("volumes-from"),
|
||||||
|
workDir:c.String("workdir"),
|
||||||
|
}
|
||||||
|
|
||||||
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses information needed to create a container into an OCI runtime spec
|
// Parses information needed to create a container into an OCI runtime spec
|
||||||
func createConfigToOCISpec(config *createConfig) (*spec.Spec, error) {
|
func createConfigToOCISpec(config *createConfig) (*spec.Spec, error) {
|
||||||
return nil, errors.Errorf("NOT IMPLEMENTED")
|
spec := &spec.Spec{
|
||||||
|
Version: "1.0.0.0", // where do I get this?
|
||||||
|
Process: &spec.Process{
|
||||||
|
Terminal: config.tty,
|
||||||
|
User: spec.User{
|
||||||
|
},
|
||||||
|
Args: config.command,
|
||||||
|
Env: config.env,
|
||||||
|
Capabilities: &spec.LinuxCapabilities{
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Root: &spec.Root{
|
||||||
|
Readonly: config.readOnlyRootfs,
|
||||||
|
},
|
||||||
|
// Hostname
|
||||||
|
// Mounts
|
||||||
|
Hooks: &spec.Hooks{},
|
||||||
|
//Annotations
|
||||||
|
Linux: &spec.Linux{
|
||||||
|
// UIDMappings
|
||||||
|
// GIDMappings
|
||||||
|
Sysctl: config.sysctl,
|
||||||
|
Resources: &spec.LinuxResources{
|
||||||
|
Devices: spec.LinuxDeviceCgroup,
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return spec, errors.Errorf("NOT IMPLEMENTED")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue