Merge 45808ca998
into 825f7f290b
This commit is contained in:
commit
26b08502de
3 changed files with 233 additions and 0 deletions
|
@ -133,3 +133,119 @@ func validateFlags(c *cli.Context, flags []cli.Flag) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Common flags shared between commands
|
||||||
|
var createFlags = []cli.Flag{
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "cap-add",
|
||||||
|
Usage: "Add capabilities to the container",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "cap-drop",
|
||||||
|
Usage: "Drop capabilities from the container",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "cgroup-parent",
|
||||||
|
Usage: "Set CGroup parent",
|
||||||
|
Value: defaultCgroupParent,
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "detach, d",
|
||||||
|
Usage: "Start container detached",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "device",
|
||||||
|
Usage: "Mount devices into the container",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "dns",
|
||||||
|
Usage: "Set custom DNS servers",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "dns-opt",
|
||||||
|
Usage: "Set custom DNS options",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "dns-search",
|
||||||
|
Usage: "Set custom DNS search domains",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "env, e",
|
||||||
|
Usage: "Set environment variables in container",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "expose",
|
||||||
|
Usage: "Expose a port",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "group-add",
|
||||||
|
Usage: "Specify additional groups to run as",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "hostname, h",
|
||||||
|
Usage: "Set hostname",
|
||||||
|
Value: defaultHostname,
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "interactive, i",
|
||||||
|
Usage: "Keep STDIN open even if deatched",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "ipc",
|
||||||
|
Usage: "Use `host` IPC namespace",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "label",
|
||||||
|
Usage: "Set label metadata on container",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "name",
|
||||||
|
Usage: "Assign a name to the container",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "network",
|
||||||
|
Usage: "Use `host` network namespace",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "pid",
|
||||||
|
Usage: "Use `host` PID namespace",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "pod",
|
||||||
|
Usage: "Run container in an existing pod",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "privileged",
|
||||||
|
Usage: "Run a privileged container",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "read-only",
|
||||||
|
Usage: "Make root filesystem read-only",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "rm",
|
||||||
|
Usage: "Remove container (and pod if created) after exit",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "sysctl",
|
||||||
|
Usage: "Set namespaced SYSCTLs",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "tty, t",
|
||||||
|
Usage: "Allocate a TTY for container",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "user, u",
|
||||||
|
Usage: "Specify user to run as",
|
||||||
|
},
|
||||||
|
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "volume, v",
|
||||||
|
Usage: "Mount volumes into the container",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "workdir, w",
|
||||||
|
Usage: "Set working `directory` of container",
|
||||||
|
Value: "/",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
116
cmd/kpod/create.go
Normal file
116
cmd/kpod/create.go
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: Missing flags from docker-create - particularly --security-opt or equiv and resource limit flags
|
||||||
|
// TODO stop using Kubernetes API structs here - replace with our own versions (remove pb import entirely)
|
||||||
|
// TODO Add missing flags from docker-create
|
||||||
|
// TODO parse flags into a createConfig, and parse createConfig into an OCI runtime spec
|
||||||
|
|
||||||
|
// TODO These temporary values should be replaced with sane defaults
|
||||||
|
const (
|
||||||
|
defaultHostname = "kpod-launch"
|
||||||
|
defaultCgroupParent = "/kpod-launch"
|
||||||
|
)
|
||||||
|
|
||||||
|
type createConfig struct {
|
||||||
|
image string
|
||||||
|
command string
|
||||||
|
args []string
|
||||||
|
pod string
|
||||||
|
privileged bool
|
||||||
|
rm bool
|
||||||
|
hostNet bool
|
||||||
|
hostPID bool
|
||||||
|
hostIPC bool
|
||||||
|
name string
|
||||||
|
labels map[string]string
|
||||||
|
workDir string
|
||||||
|
env map[string]string
|
||||||
|
detach bool
|
||||||
|
stdin bool
|
||||||
|
tty bool
|
||||||
|
devices []*pb.Device
|
||||||
|
mounts []*pb.Mount
|
||||||
|
capAdd []string
|
||||||
|
capDrop []string
|
||||||
|
dnsServers []string
|
||||||
|
dnsSearch []string
|
||||||
|
dnsOpt []string
|
||||||
|
ports []*pb.PortMapping
|
||||||
|
hostname string
|
||||||
|
cgroupParent string
|
||||||
|
sysctl string
|
||||||
|
user int64
|
||||||
|
additionalGroups []int64
|
||||||
|
readOnlyRootfs bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var createDescription = "Creates a new container from the given image or" +
|
||||||
|
" storage and prepares it for running the specified command. The" +
|
||||||
|
" container ID is then printed to stdout. You can then start it at" +
|
||||||
|
" any time with the kpod start <container_id> command. The container" +
|
||||||
|
" will be created with the initial state 'created'."
|
||||||
|
|
||||||
|
var createCommand = cli.Command{
|
||||||
|
Name: "create",
|
||||||
|
Usage: "create but do not start a container",
|
||||||
|
Description: createDescription,
|
||||||
|
Flags: createFlags,
|
||||||
|
Action: createCmd,
|
||||||
|
ArgsUsage: "IMAGE [COMMAND [ARG...]]",
|
||||||
|
}
|
||||||
|
|
||||||
|
func createCmd(c *cli.Context) error {
|
||||||
|
// TODO should allow user to create based off a directory on the host not just image
|
||||||
|
// Need CLI support for this
|
||||||
|
if len(c.Args()) != 1 {
|
||||||
|
return errors.Errorf("must specify name of image to create from")
|
||||||
|
}
|
||||||
|
if err := validateFlags(c, createFlags); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
runtime, err := getRuntime(c)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "error creating libpod runtime")
|
||||||
|
}
|
||||||
|
|
||||||
|
createConfig, err := parseCreateOpts(c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
runtimeSpec, err := createConfigToOCISpec(createConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctr, err := runtime.NewContainer(runtimeSpec)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should we also call ctr.Create() to make the container in runc?
|
||||||
|
|
||||||
|
fmt.Printf("%s\n", ctr.ID())
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parses CLI options related to container creation into a config which can be
|
||||||
|
// parsed into an OCI runtime spec
|
||||||
|
func parseCreateOpts(c *cli.Context) (*createConfig, error) {
|
||||||
|
return nil, errors.Errorf("NOT IMPLEMENTED")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parses information needed to create a container into an OCI runtime spec
|
||||||
|
func createConfigToOCISpec(config *createConfig) (*spec.Spec, error) {
|
||||||
|
return nil, errors.Errorf("NOT IMPLEMENTED")
|
||||||
|
}
|
|
@ -31,6 +31,7 @@ func main() {
|
||||||
app.Version = v
|
app.Version = v
|
||||||
|
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
|
createCommand,
|
||||||
diffCommand,
|
diffCommand,
|
||||||
exportCommand,
|
exportCommand,
|
||||||
historyCommand,
|
historyCommand,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue