-
Notifications
You must be signed in to change notification settings - Fork 92
/
setup.go
257 lines (242 loc) · 8.7 KB
/
setup.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
// MIT License
//
// Copyright (c) 2023 Haoyuan Ma and vHive team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package main
import (
"flag"
"fmt"
"os"
cloudlab "github.com/vhive-serverless/vHive/scripts/cloudlab"
cluster "github.com/vhive-serverless/vHive/scripts/cluster"
configs "github.com/vhive-serverless/vHive/scripts/configs"
gpu "github.com/vhive-serverless/vHive/scripts/gpu"
setup "github.com/vhive-serverless/vHive/scripts/setup"
utils "github.com/vhive-serverless/vHive/scripts/utils"
)
func main() {
var err error
// Detect and prepare for the environment
if err = utils.PrepareEnvironment(); err != nil {
os.Exit(1)
}
defer utils.CleanEnvironment()
// Set up arguments
var help bool
setupFlagsName := os.Args[0]
setupFlags := flag.NewFlagSet(setupFlagsName, flag.ExitOnError)
setupFlags.StringVar(&configs.VHive.VHiveSetupConfigPath, "setup-configs-dir", configs.VHive.VHiveSetupConfigPath, "Config directory for setting up vHive (left blank to use default configs in vHive repo)")
setupFlags.StringVar(&configs.VHive.VHiveRepoPath, "vhive-repo-dir", configs.VHive.VHiveRepoPath, "vHive repo path (left blank to use online repo automatically)")
setupFlags.StringVar(&configs.VHive.VHiveRepoBranch, "vhive-repo-branch", configs.VHive.VHiveRepoBranch, "vHive repo branch (valid only when using online repo)")
setupFlags.StringVar(&configs.VHive.VHiveRepoUrl, "vhive-repo-url", configs.VHive.VHiveRepoUrl, "vHive repo url (valid only when using online repo)")
setupFlags.BoolVar(&configs.VHive.ForceRemote, "force-remote", configs.VHive.ForceRemote, "Force scripts to use the online repo")
setupFlags.BoolVar(&help, "help", false, "Show help")
setupFlags.BoolVar(&help, "h", false, "Show help")
// Parse arguments
setupFlags.Parse(os.Args[1:])
// Show help
if help {
setupFlags.Usage()
return
}
if setupFlags.NArg() < 1 {
utils.FatalPrintf("Missing subcommand! Script terminated!\n")
return
}
// Create logs
if err = utils.CreateLogs(configs.System.CurrentDir, setupFlags.Args()[0]); err != nil {
utils.CleanEnvironment()
os.Exit(1)
}
// Current available commands
subCmd := setupFlags.Args()[0]
availableCmds := []string{
"create_multinode_cluster",
"create_one_node_cluster",
"prepare_one_node_cluster",
"setup_master_node",
"setup_worker_kubelet",
"setup_node",
"start_onenode_vhive_cluster",
"setup_nvidia_gpu",
"setup_zipkin",
"setup_system",
"setup_gvisor_containerd",
"setup_firecracker_containerd",
"install_stock",
"install_pmutools",
"create_docker_image",
"create_devmapper",
"clean_fcctr",
}
// Check vHive repo
// In-repo setup (default, use the current git repo as vHive repo)
if configs.VHive.VHiveRepoPath == "." {
repoRoot, err := utils.ExecShellCmd("git rev-parse --show-toplevel")
if err != nil {
// Invalid git repo, set vHive repo path to empty
configs.VHive.VHiveRepoPath = ""
} else {
configs.VHive.VHiveRepoPath = repoRoot
}
}
utils.CheckVHiveRepo()
utils.InfoPrintf("vHive repo Path: %s\n", configs.VHive.VHiveRepoPath)
// Check config directory
if len(configs.VHive.VHiveSetupConfigPath) == 0 {
configs.VHive.VHiveSetupConfigPath, err = utils.GetVHiveFilePath("configs/setup")
if err != nil {
utils.CleanEnvironment()
os.Exit(1)
}
}
// load config file
utils.WaitPrintf("Loading config files from %s", configs.VHive.VHiveSetupConfigPath)
if err = configs.VHive.LoadConfig(); !utils.CheckErrorWithMsg(err, "Failed to load config files!\n") {
utils.CleanEnvironment()
os.Exit(1)
}
if err = configs.System.LoadConfig(); !utils.CheckErrorWithMsg(err, "Failed to load config files!\n") {
utils.CleanEnvironment()
os.Exit(1)
}
if err = configs.Kube.LoadConfig(); !utils.CheckErrorWithMsg(err, "Failed to load config files!\n") {
utils.CleanEnvironment()
os.Exit(1)
}
if err = configs.Knative.LoadConfig(); !utils.CheckErrorWithMsg(err, "Failed to load config files!\n") {
utils.CleanEnvironment()
os.Exit(1)
}
utils.SuccessPrintf("\n")
// Execute corresponding scripts
switch subCmd {
// Original scripts from `scripts/cluster` directory
case "create_multinode_cluster":
if setupFlags.NArg() < 2 {
utils.FatalPrintf("Missing parameters: %s <stock-containerd>\n", subCmd)
utils.CleanEnvironment()
os.Exit(1)
}
utils.InfoPrintf("Create multinode cluster\n")
err = cluster.CreateMultinodeCluster(setupFlags.Args()[1])
case "create_one_node_cluster":
if setupFlags.NArg() < 2 {
utils.FatalPrintf("Missing parameters: %s <stock-containerd>\n", subCmd)
utils.CleanEnvironment()
os.Exit(1)
}
utils.InfoPrintf("Create one-node Cluster\n")
err = cluster.CreateOneNodeCluster(setupFlags.Args()[1])
if err == nil {
utils.InfoPrintf("Set up master node\n")
err = cluster.SetupMasterNode(setupFlags.Args()[1])
}
case "prepare_one_node_cluster":
if setupFlags.NArg() < 2 {
utils.FatalPrintf("Missing parameters: %s <stock-containerd>\n", subCmd)
utils.CleanEnvironment()
os.Exit(1)
}
utils.InfoPrintf("Create one-node Cluster\n")
err = cluster.CreateOneNodeCluster(setupFlags.Args()[1])
case "setup_master_node":
if setupFlags.NArg() < 2 {
utils.FatalPrintf("Missing parameters: %s <stock-containerd>\n", subCmd)
utils.CleanEnvironment()
os.Exit(1)
}
utils.InfoPrintf("Set up master node\n")
err = cluster.SetupMasterNode(setupFlags.Args()[1])
case "setup_worker_kubelet":
if setupFlags.NArg() < 2 {
utils.FatalPrintf("Missing parameters: %s <stock-containerd>\n", subCmd)
utils.CleanEnvironment()
os.Exit(1)
}
utils.InfoPrintf("Set up worker kubelet\n")
err = cluster.SetupWorkerKubelet(setupFlags.Args()[1])
// Original scripts from `scripts/cloudlab` directory
case "setup_node":
if setupFlags.NArg() < 2 {
utils.FatalPrintf("Missing parameters: %s <sandbox> [use-stargz]\n", subCmd)
utils.CleanEnvironment()
os.Exit(1)
}
utils.InfoPrintf("Set up node\n")
if setupFlags.NArg() >= 3 {
err = cloudlab.SetupNode(setupFlags.Args()[1], setupFlags.Args()[2])
} else {
err = cloudlab.SetupNode(setupFlags.Args()[1], "")
}
case "start_onenode_vhive_cluster":
if setupFlags.NArg() < 2 {
utils.FatalPrintf("Missing parameters: %s <sandbox>\n", subCmd)
utils.CleanEnvironment()
os.Exit(1)
}
utils.InfoPrintf("Start one-node vHive cluster\n")
err = cloudlab.StartOnenodeVhiveCluster(setupFlags.Args()[1])
// Original scripts from `scripts/cloudlab` directory
case "setup_nvidia_gpu":
utils.InfoPrintf("Set up Nvidia gpu\n")
err = gpu.SetupNvidiaGpu()
// Original scripts from `scripts` directory
case "setup_zipkin":
utils.InfoPrintf("Setup zipkin\n")
err = setup.SetupZipkin()
case "setup_system":
utils.InfoPrintf("Set up system\n")
err = setup.SetupSystem()
case "setup_gvisor_containerd":
utils.InfoPrintf("Set up gvisor_containerd\n")
err = setup.SetupGvisorContainerd()
case "setup_firecracker_containerd":
utils.InfoPrintf("Set up firecracker_containerd\n")
err = setup.SetupFirecrackerContainerd()
case "install_stock":
utils.InfoPrintf("Install stock\n")
err = setup.InstallStock()
case "install_pmutools":
utils.InfoPrintf("Install pmutools\n")
err = setup.InstallPmuTools()
case "create_docker_image":
utils.InfoPrintf("Create docker image\n")
err = setup.CreateDockerImage()
case "create_devmapper":
utils.InfoPrintf("Create devmapper\n")
err = setup.CreateDevmapper()
case "clean_fcctr":
utils.InfoPrintf("Clean fcctr\n")
err = setup.CleanFcctr()
default:
utils.FatalPrintf("Invalid subcommand --> %s! Available subcommands list: \n", subCmd)
for _, subCmd := range availableCmds {
fmt.Printf("%s\n", subCmd)
}
utils.CleanEnvironment()
os.Exit(1)
}
if err != nil {
utils.FatalPrintf("Failed subcommand: %s!\n", subCmd)
utils.CleanEnvironment()
os.Exit(1)
}
}