-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlocalkube.go
61 lines (53 loc) · 1.4 KB
/
localkube.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
package localkube
import (
"errors"
"fmt"
"io"
)
// LocalKube provides a fully functional Kubernetes cluster running entirely through goroutines
type LocalKube struct {
Servers
}
func (lk *LocalKube) Add(server Server) {
lk.Servers = append(lk.Servers, server)
}
func (lk *LocalKube) Run(args []string, out io.Writer) error {
if len(args) < 2 {
return errors.New("you must choose start <name>, stop <name>, or status")
}
switch args[1] {
case "start":
// check if just start
if len(args) == 2 {
fmt.Fprintln(out, "Starting LocalKube...")
lk.StartAll()
return nil
} else if len(args) == 3 {
serverName := args[2]
fmt.Fprintf(out, "Starting `%s`...\n", serverName)
return lk.Start(serverName)
} else {
return errors.New("start: too many arguments")
}
case "stop":
// check if just stop
if len(args) == 2 {
fmt.Fprintln(out, "Stopping LocalKube...")
lk.StopAll()
return nil
} else if len(args) == 3 {
serverName := args[2]
fmt.Fprintf(out, "Stopping `%s`...\n", serverName)
return lk.Stop(serverName)
}
case "status":
fmt.Fprintln(out, "LocalKube Status")
fmt.Fprintln(out, "################\n")
fmt.Fprintln(out, "Order\tStatus\tName")
for num, server := range lk.Servers {
fmt.Fprintf(out, "%d\t%s\t%s\n", num, server.Status(), server.Name())
}
fmt.Fprintln(out)
}
return errors.New("you must choose start <name>, stop <name>, or status")
}