forked from k3d-io/k3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
177 lines (171 loc) · 4.09 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package main
import (
"log"
"os"
run "github.com/rancher/k3d/cli"
"github.com/rancher/k3d/version"
"github.com/urfave/cli"
)
// main represents the CLI application
func main() {
// App Details
app := cli.NewApp()
app.Name = "k3d"
app.Usage = "Run k3s in Docker!"
app.Version = version.GetVersion()
app.Authors = []cli.Author{
cli.Author{
Name: "Thorsten Klein",
Email: "[email protected]",
},
cli.Author{
Name: "Rishabh Gupta",
Email: "[email protected]",
},
cli.Author{
Name: "Darren Shepherd",
},
}
// commands that you can execute
app.Commands = []cli.Command{
{
// check-tools verifies that docker is up and running
Name: "check-tools",
Aliases: []string{"ct"},
Usage: "Check if docker is running",
Action: run.CheckTools,
},
{
// create creates a new k3s cluster in a container
Name: "create",
Aliases: []string{"c"},
Usage: "Create a single node k3s cluster in a container",
Flags: []cli.Flag{
cli.StringFlag{
Name: "name, n",
Value: "k3s_default",
Usage: "Set a name for the cluster",
},
cli.StringFlag{
Name: "volume, v",
Usage: "Mount a volume into the cluster node (Docker notation: `source:destination`)",
},
cli.StringFlag{
Name: "version",
Value: "v0.3.0",
Usage: "Choose the k3s image version",
},
cli.IntFlag{
Name: "port, p",
Value: 6443,
Usage: "Set a port on which the ApiServer will listen",
},
cli.IntFlag{
Name: "timeout, t",
Value: 0,
Usage: "Set the timeout value when --wait flag is set",
},
cli.BoolFlag{
Name: "wait, w",
Usage: "Wait for the cluster to come up",
},
cli.StringSliceFlag{
Name: "server-arg, x",
Usage: "Pass an additional argument to k3s server (new flag per argument)",
},
cli.StringSliceFlag{
Name: "env, e",
Usage: "Pass an additional environment variable (new flag per variable)",
},
},
Action: run.CreateCluster,
},
{
// delete deletes an existing k3s cluster (remove container and cluster directory)
Name: "delete",
Aliases: []string{"d", "del"},
Usage: "Delete cluster",
Flags: []cli.Flag{
cli.StringFlag{
Name: "name, n",
Value: "k3s_default",
Usage: "name of the cluster",
},
cli.BoolFlag{
Name: "all, a",
Usage: "delete all existing clusters (this ignores the --name/-n flag)",
},
},
Action: run.DeleteCluster,
},
{
// stop stopy a running cluster (its container) so it's restartable
Name: "stop",
Usage: "Stop cluster",
Flags: []cli.Flag{
cli.StringFlag{
Name: "name, n",
Value: "k3s_default",
Usage: "name of the cluster",
},
cli.BoolFlag{
Name: "all, a",
Usage: "stop all running clusters (this ignores the --name/-n flag)",
},
},
Action: run.StopCluster,
},
{
// start restarts a stopped cluster container
Name: "start",
Usage: "Start a stopped cluster",
Flags: []cli.Flag{
cli.StringFlag{
Name: "name, n",
Value: "k3s_default",
Usage: "name of the cluster",
},
cli.BoolFlag{
Name: "all, a",
Usage: "start all stopped clusters (this ignores the --name/-n flag)",
},
},
Action: run.StartCluster,
},
{
// list prints a list of created clusters
Name: "list",
Aliases: []string{"ls", "l"},
Usage: "List all clusters",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "all, a",
Usage: "also show non-running clusters",
},
},
Action: run.ListClusters,
},
{
// get-kubeconfig grabs the kubeconfig from the cluster and prints the path to it
Name: "get-kubeconfig",
Usage: "Get kubeconfig location for cluster",
Flags: []cli.Flag{
cli.StringFlag{
Name: "name, n",
Value: "k3s_default",
Usage: "name of the cluster",
},
cli.BoolFlag{
Name: "all, a",
Usage: "get kubeconfig for all clusters (this ignores the --name/-n flag)",
},
},
Action: run.GetKubeConfig,
},
}
// run the whole thing
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}