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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "mks")]
pub(crate) struct CliOptions {
#[structopt(short, long)]
/// Activate debug mode
pub(crate) debug: bool,
#[structopt(short, long)]
/// Activate verbose mode
pub(crate) verbose: bool,
#[structopt(long, env = "MKS_TOKEN", hide_env_values = true)]
/// MKS project-scoped token
pub(crate) mks_token: String,
#[structopt(long, env = "MKS_ENDPOINT", hide_env_values = true)]
/// MKS endpoint
pub(crate) mks_endpoint: String,
#[structopt(subcommand)]
pub(crate) resource: Resource,
}
#[derive(Debug, StructOpt)]
pub(crate) enum Resource {
/// Cluster commands
Cluster(Cluster),
/// Kubeversion commands
Kubeversion(Kubeversion),
/// Node commands
Node(Node),
/// Nodegroup commands
Nodegroup(Nodegroup),
/// Task commands
Task(Task),
}
#[derive(Debug, StructOpt)]
pub(crate) struct Cluster {
#[structopt(subcommand)]
pub(crate) command: ClusterCommand,
}
#[derive(Debug, StructOpt)]
pub(crate) enum ClusterCommand {
/// Get cluster
Get {
#[structopt(default_value = "table", short, long)]
/// Output format, can be either of table or json
output: String,
/// Cluster identifier
#[structopt(name = "cluster-id")]
cluster_id: String,
},
/// List all clusters
List {
#[structopt(default_value = "table", short, long)]
/// Output format, can be either of table or json
output: String,
},
/// Create a new cluster
Create {
#[structopt(default_value = "table", short, long)]
/// Output format, can be either of table or json
output: String,
/// Cluster name
#[structopt(long)]
name: String,
/// Kubernetes version
#[structopt(long)]
kube_version: String,
/// Cluster region
#[structopt(long)]
region: String,
/// Reference to a pre-created network
#[structopt(long)]
network_id: Option<String>,
/// Reference to a pre-created subnet
#[structopt(long)]
subnet_id: Option<String>,
/// UTC time in "hh:mm:ss" format of when the cluster will start its maintenance tasks
#[structopt(long)]
maintenance_window_start: Option<String>,
/// Flag that indicates if worker nodes are allowed to be reinstalled automatically
/// in case of their unavailability or unhealthiness
#[structopt(long)]
enable_autorepair: Option<bool>,
/// Flag that indicates if Kubernetes patch version of the cluster is allowed to be upgraded
/// automatically
#[structopt(long)]
enable_patch_version_auto_upgrade: Option<bool>,
/// Flag that indicates that cluster has only a single master and that
/// control-plane is not in highly available mode
#[structopt(long)]
zonal: Option<bool>,
},
/// Delete cluster
Delete {
/// Cluster identifier
#[structopt(name = "cluster-id")]
cluster_id: String,
},
}
#[derive(Debug, StructOpt)]
pub(crate) struct Kubeversion {
#[structopt(subcommand)]
pub(crate) command: KubeversionCommand,
}
#[derive(Debug, StructOpt)]
pub(crate) enum KubeversionCommand {
/// List all available Kubernetes versions
List {
#[structopt(default_value = "table", short, long)]
/// Output format, can be either of table or json
output: String,
},
}
#[derive(Debug, StructOpt)]
pub(crate) struct Node {
#[structopt(subcommand)]
pub(crate) command: NodeCommand,
}
#[derive(Debug, StructOpt)]
pub(crate) enum NodeCommand {
/// Get a cluster node in a nodegroup
Get {
#[structopt(default_value = "table", short, long)]
/// Output format, can be either of table or json
output: String,
/// Cluster identifier
#[structopt(long)]
cluster_id: String,
/// Nodegroup identifier
#[structopt(long)]
nodegroup_id: String,
/// Node identifier
#[structopt(name = "node-id")]
node_id: String,
},
/// Reinstall a single cluster node in a nodegroup
Reinstall {
/// Cluster identifier
#[structopt(long)]
cluster_id: String,
/// Nodegroup identifier
#[structopt(long)]
nodegroup_id: String,
/// Node identifier
#[structopt(name = "node-id")]
node_id: String,
},
}
#[derive(Debug, StructOpt)]
pub(crate) struct Nodegroup {
#[structopt(subcommand)]
pub(crate) command: NodegroupCommand,
}
#[derive(Debug, StructOpt)]
pub(crate) enum NodegroupCommand {
/// List cluster nodegroups
List {
#[structopt(default_value = "table", short, long)]
/// Output format, can be either of table or json
output: String,
/// Cluster identifier
#[structopt(long)]
cluster_id: String,
},
/// Get cluster nodegroup
Get {
#[structopt(default_value = "table", short, long)]
/// Output format, can be either of table or json
output: String,
/// Cluster identifier
#[structopt(long)]
cluster_id: String,
/// Nodegroup identifier
#[structopt(name = "nodegroup-id")]
nodegroup_id: String,
},
/// Create a new nodegroup
Create {
/// Cluster identifier
#[structopt(long)]
cluster_id: String,
/// Count of nodes
#[structopt(long)]
nodes_count: u32,
/// Availability zone for all nodes in this nodegroup
#[structopt(long)]
availability_zone: String,
/// Use local volume for each node
#[structopt(long)]
local_volume: bool,
/// Reference to a pre-created flavor, it can be omitted in most cases
#[structopt(long)]
flavor_id: Option<String>,
/// CPU count for each node, it can be omitted only in cases when
/// flavor-id is provided
#[structopt(long)]
cpus: Option<u32>,
/// RAM value in MB for each node, it can be omitted only in cases when
/// flavor-id is provided
#[structopt(long)]
ram_mb: Option<u32>,
/// Volume size in GB for each node, it can be omitted only in cases when
/// flavor-id is provided and volume is local
#[structopt(long)]
volume_gb: Option<u32>,
/// BlockStorage volume type for each node, it can be omitted only in cases when
/// flavor-id is set and volume is local
#[structopt(long)]
volume_type: Option<String>,
/// Name of the SSH key that will be added to all nodes
#[structopt(long)]
keypair_name: Option<String>,
/// Optional parameter to tune nodes affinity
#[structopt(long)]
affinity_policy: Option<String>,
},
/// Set nodegroup parameters
Set {
/// Cluster identifier
#[structopt(long)]
cluster_id: String,
/// Nodegroup identifier
#[structopt(name = "nodegroup-id")]
nodegroup_id: String,
/// Count of nodes
#[structopt(long)]
nodes_count: Option<u32>,
},
/// Delete nodegroup
Delete {
/// Cluster identifier
#[structopt(long)]
cluster_id: String,
/// Nodegroup identifier
#[structopt(name = "nodegroup-id")]
nodegroup_id: String,
},
}
#[derive(Debug, StructOpt)]
pub(crate) struct Task {
#[structopt(subcommand)]
pub(crate) command: TaskCommand,
}
#[derive(Debug, StructOpt)]
pub(crate) enum TaskCommand {
/// List cluster tasks
List {
#[structopt(default_value = "table", short, long)]
/// Output format, can be either of table or json
output: String,
/// Cluster identifier
#[structopt(long)]
cluster_id: String,
},
/// Get cluster task
Get {
#[structopt(default_value = "table", short, long)]
/// Output format, can be either of table or json
output: String,
/// Cluster identifier
#[structopt(long)]
cluster_id: String,
/// Task identifier
#[structopt(name = "task-id")]
task_id: String,
},
}