-
Notifications
You must be signed in to change notification settings - Fork 20
/
createPodCommand.go
71 lines (59 loc) · 1.65 KB
/
createPodCommand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"os"
"github.com/ernoaapa/eliot/cmd"
pods "github.com/ernoaapa/eliot/pkg/api/services/pods/v1"
"github.com/ernoaapa/eliot/pkg/printers"
"github.com/ernoaapa/eliot/pkg/progress"
"github.com/ernoaapa/eliot/pkg/resolve"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
var createPodCommand = cli.Command{
Name: "pod",
HelpName: "pod",
Usage: "Create new pod",
Description: "With create pod command, you can create new pod into the node",
UsageText: `eli create pod [options] <NAME>
# Create new pod 'my-pod' and create single container
eli create pod --image alpine my-pod
`,
Flags: []cli.Flag{
cli.StringSliceFlag{
Name: "image",
Usage: "The container image to run. You can pass as many images you want",
},
},
Action: func(clicontext *cli.Context) error {
var (
images = clicontext.StringSlice("image")
name = clicontext.Args().First()
)
if name == "" {
return errors.New("You need to give name for the pod")
}
var pod *pods.Pod
if len(images) > 0 {
pod = resolve.BuildPod(name, images)
} else {
return errors.New("You need to give at least one --image flag")
}
config := cmd.GetConfigProvider(clicontext)
client := cmd.GetClient(config)
progressc := make(chan []*progress.ImageFetch)
go cmd.ShowDownloadProgress(progressc)
err := client.CreatePod(progressc, pod)
close(progressc)
if err != nil {
return err
}
result, err := client.StartPod(pod.Metadata.Name)
if err != nil {
return err
}
writer := printers.GetNewTabWriter(os.Stdout)
defer writer.Flush()
printer := cmd.GetPrinter(clicontext)
return printer.PrintPod(result, writer)
},
}