Skip to content

Commit 471a460

Browse files
authored
Merge pull request #99 from kurrent-io/brock/add-shared-clusters
add support for creating and deleting shared clusters
2 parents c6f4711 + 456de56 commit 471a460

File tree

8 files changed

+604
-12
lines changed

8 files changed

+604
-12
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
name: Build
99
strategy:
1010
matrix:
11-
os: [ubuntu-20.04, windows-2019, macos-11]
11+
os: [ubuntu-22.04, windows-2019, macos-13]
1212

1313
runs-on: ${{ matrix.os }}
1414

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Release
1111
strategy:
1212
matrix:
13-
os: [ubuntu-20.04, windows-2019, macos-11]
13+
os: [ubuntu-22.04, windows-2019, macos-13]
1414

1515
runs-on: ${{ matrix.os }}
1616

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ esc profiles set --profile my_profile --name fmt --value api
7070
```
7171

7272
## JSON commands output rendering
73+
7374
You can render any read command output in JSON by using the `--json` flag.
7475

7576
```
@@ -80,9 +81,9 @@ esc resources organizations list --json
8081

8182
You can generate shell completion script by using the `generate-{shell}-completion` command. Currently supported:
8283

83-
* Bash
84-
* Zsh
85-
* Powershell
84+
- Bash
85+
- Zsh
86+
- Powershell
8687

8788
Additional shells can be supported, please open a feature request.
8889

@@ -139,13 +140,17 @@ esc mesdb clusters create --help
139140
esc mesdb clusters stop --org-id <org-id> --project-id <project-id> --id <cluster-id>
140141
```
141142

142-
143143
### Start a cluster
144144

145145
```
146146
esc mesdb clusters start --org-id <org-id> --project-id <project-id> --id <cluster-id>
147147
```
148148

149+
### Create a shared cluster
150+
151+
```
152+
esc mesdb shared-clusters create --deployment-tier s0 --name <name> --projection-level <projection-level> --provider <provider> --region <region> --server-version <server-version> --topology <topology> --acl-id <acl-id>
153+
```
149154

150155
### Create a refresh token.
151156

@@ -167,7 +172,6 @@ esc access tokens display
167172
escp resources organizations update-mfa-status --enabled=true
168173
```
169174

170-
171175
### List members of an organization.
172176

173177
```

cli/src/main.rs

Lines changed: 168 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod v1;
1414

1515
use cidr::Cidr;
1616
use esc_api::resources::MfaStatus;
17+
1718
use esc_api::{GroupId, MemberId, OrgId};
1819
use output::OutputFormat;
1920
use serde::Serialize;
@@ -1013,6 +1014,7 @@ struct Mesdb {
10131014
enum MesdbCommand {
10141015
Clusters(Clusters),
10151016
Backups(Backups),
1017+
SharedClusters(SharedClusters),
10161018
}
10171019

10181020
#[derive(Debug, StructOpt)]
@@ -1074,7 +1076,7 @@ struct CreateCluster {
10741076

10751077
#[structopt(
10761078
long,
1077-
help = "Type of disk. For example, if you are using AWS as a provider, it could be GP2"
1079+
help = "Type of disk. For example, if you are using AWS as a provider, it could be GP2"
10781080
)]
10791081
disk_type: String,
10801082

@@ -1102,6 +1104,12 @@ struct CreateCluster {
11021104

11031105
#[structopt(long, help = "The protected flag prevents from accidental deletion")]
11041106
protected: Option<bool>,
1107+
1108+
#[structopt(long, help = "The provider of the cluster")]
1109+
provider: Option<String>,
1110+
1111+
#[structopt(long, help = "The region of the cluster")]
1112+
region: Option<String>,
11051113
}
11061114

11071115
#[derive(Debug, StructOpt)]
@@ -1248,6 +1256,97 @@ struct UpgradeCluster {
12481256
target_tag: String,
12491257
}
12501258

1259+
#[derive(Debug, StructOpt)]
1260+
#[structopt(about = "Gathers shared cluster management commands")]
1261+
struct SharedClusters {
1262+
#[structopt(subcommand)]
1263+
shared_clusters_command: SharedClustersCommand,
1264+
}
1265+
1266+
#[derive(Debug, StructOpt)]
1267+
enum SharedClustersCommand {
1268+
Create(CreateSharedCluster),
1269+
List(ListSharedClusters),
1270+
Delete(DeleteSharedCluster),
1271+
Get(GetSharedCluster),
1272+
}
1273+
1274+
#[derive(Debug, StructOpt)]
1275+
struct CreateSharedCluster {
1276+
#[structopt(long, parse(try_from_str = parse_org_id), default_value = "", help = "The organization id the cluster relates to")]
1277+
org_id: OrgId,
1278+
1279+
#[structopt(long, parse(try_from_str = parse_project_id), default_value = "", help = "The project id the cluster relates to")]
1280+
project_id: esc_api::resources::ProjectId,
1281+
1282+
#[structopt(long, parse(try_from_str = parse_acl_id), help = "The acl id the cluster relates to")]
1283+
acl_id: esc_api::infra::AclId,
1284+
1285+
#[structopt(long, help = "The name of the cluster")]
1286+
name: String,
1287+
1288+
#[structopt(long, help = "The provider of the cluster")]
1289+
provider: String,
1290+
1291+
#[structopt(long, help = "The region of the cluster")]
1292+
region: String,
1293+
1294+
#[structopt(long, help = "The deployment tier of the cluster")]
1295+
deployment_tier: String,
1296+
1297+
#[structopt(long, help = "Whether mutual TLS is enabled for the cluster")]
1298+
mutual_tls_enabled: bool,
1299+
1300+
#[structopt(
1301+
long,
1302+
parse(try_from_str = parse_projection_level),
1303+
help = "The projection level of your database. Can be off, system or user "
1304+
)]
1305+
projection_level: esc_api::mesdb::ProjectionLevel,
1306+
1307+
#[structopt(long, help = "The server version of the cluster")]
1308+
server_version: String,
1309+
1310+
#[structopt(long, parse(try_from_str = parse_topology), help = "Either single-node or three-node-multi-zone")]
1311+
topology: esc_api::mesdb::Topology,
1312+
}
1313+
1314+
#[derive(Debug, StructOpt)]
1315+
#[structopt(about = "List all shared clusters of an organization, given a project id")]
1316+
struct ListSharedClusters {
1317+
#[structopt(long, parse(try_from_str = parse_org_id), default_value = "", help = "The organization id the cluster relates to")]
1318+
org_id: OrgId,
1319+
1320+
#[structopt(long, parse(try_from_str = parse_project_id), default_value = "", help = "The project id the cluster relates to")]
1321+
project_id: esc_api::resources::ProjectId,
1322+
}
1323+
1324+
#[derive(Debug, StructOpt)]
1325+
#[structopt(about = "Delete a shared cluster")]
1326+
struct DeleteSharedCluster {
1327+
#[structopt(long, parse(try_from_str = parse_org_id), default_value = "", help = "The organization id the cluster relates to")]
1328+
org_id: OrgId,
1329+
1330+
#[structopt(long, parse(try_from_str = parse_project_id), default_value = "", help = "The project id the cluster relates to")]
1331+
project_id: esc_api::resources::ProjectId,
1332+
1333+
#[structopt(long, short, parse(try_from_str = parse_cluster_id), help = "Id of the cluster you want to delete")]
1334+
id: esc_api::ClusterId,
1335+
}
1336+
1337+
#[derive(Debug, StructOpt)]
1338+
#[structopt(about = "Get a shared cluster")]
1339+
struct GetSharedCluster {
1340+
#[structopt(long, parse(try_from_str = parse_org_id), default_value = "", help = "The organization id the cluster relates to")]
1341+
org_id: OrgId,
1342+
1343+
#[structopt(long, parse(try_from_str = parse_project_id), default_value = "", help = "The project id the cluster relates to")]
1344+
project_id: esc_api::resources::ProjectId,
1345+
1346+
#[structopt(long, short, parse(try_from_str = parse_cluster_id), help = "Id of the cluster you want to get")]
1347+
id: esc_api::ClusterId,
1348+
}
1349+
12511350
#[derive(Debug, StructOpt)]
12521351
#[structopt(about = "Gathers backup management commands")]
12531352
struct Backups {
@@ -2717,6 +2816,72 @@ async fn call_api<'a, 'b>(
27172816

27182817
Command::Mesdb(mesdb) => {
27192818
match mesdb.mesdb_command {
2819+
MesdbCommand::SharedClusters(shared_clusters) => {
2820+
match shared_clusters.shared_clusters_command {
2821+
SharedClustersCommand::Create(params) => {
2822+
let client = client_builder.create().await?;
2823+
let resp = esc_api::mesdb::create_shared_cluster(
2824+
&client,
2825+
params.org_id,
2826+
params.project_id,
2827+
esc_api::mesdb::CreateSharedClusterDeploymentRequest {
2828+
cluster: esc_api::mesdb::CreateSharedClusterRequest {
2829+
name: params.name,
2830+
provider: params.provider,
2831+
region: params.region,
2832+
deployment_tier: params.deployment_tier,
2833+
mutual_tls_enabled: params.mutual_tls_enabled,
2834+
projection_level: params.projection_level,
2835+
server_version: params.server_version,
2836+
topology: params.topology,
2837+
},
2838+
acl: esc_api::mesdb::Acl::ResourceIdentifier(
2839+
esc_api::mesdb::ResourceIdentifier {
2840+
id: params.acl_id.0,
2841+
},
2842+
),
2843+
},
2844+
)
2845+
.await?;
2846+
printer.print(resp)?;
2847+
}
2848+
2849+
SharedClustersCommand::List(params) => {
2850+
let client = client_builder.create().await?;
2851+
let resp = esc_api::mesdb::list_shared_clusters(
2852+
&client,
2853+
params.org_id,
2854+
params.project_id,
2855+
)
2856+
.await?;
2857+
printer.print(resp)?;
2858+
}
2859+
2860+
SharedClustersCommand::Delete(params) => {
2861+
let client = client_builder.create().await?;
2862+
esc_api::mesdb::delete_shared_cluster(
2863+
&client,
2864+
params.org_id,
2865+
params.project_id,
2866+
params.id,
2867+
)
2868+
.await?;
2869+
}
2870+
2871+
SharedClustersCommand::Get(params) => {
2872+
let client = client_builder.create().await?;
2873+
let resp = esc_api::mesdb::get_shared_cluster(
2874+
&client,
2875+
params.org_id,
2876+
params.project_id,
2877+
params.id,
2878+
)
2879+
.await?;
2880+
printer.print(resp)?;
2881+
}
2882+
}
2883+
}
2884+
27202885
MesdbCommand::Clusters(clusters) => match clusters.clusters_command {
27212886
ClustersCommand::Create(params) => {
27222887
let client = client_builder.create().await?;
@@ -2741,6 +2906,8 @@ async fn call_api<'a, 'b>(
27412906
topology: params.topology,
27422907
protected: params.protected,
27432908
public_access: params.public_access,
2909+
provider: params.provider,
2910+
region: params.region,
27442911
},
27452912
)
27462913
.await?;

cli/src/v1/mesdb.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,74 @@ impl ToV1 for esc_api::mesdb::ListBackupsResponse {
170170
List(l)
171171
}
172172
}
173+
174+
#[derive(Debug, Serialize, Deserialize)]
175+
#[serde(rename_all = "camelCase")]
176+
pub struct SharedCluster {
177+
pub id: esc_api::mesdb::ClusterId,
178+
pub org_id: OrgId,
179+
pub project_id: esc_api::resources::ProjectId,
180+
pub name: String,
181+
pub provider: Provider,
182+
pub region: String,
183+
pub topology: esc_api::mesdb::Topology,
184+
pub deployment_tier: String,
185+
pub mutual_tls_enabled: bool,
186+
pub per_node_cores: String,
187+
pub per_node_memory: usize,
188+
pub per_node_volume_size: usize,
189+
pub status: String,
190+
pub created: String,
191+
pub acl_id: String,
192+
pub projection_level: esc_api::mesdb::ProjectionLevel,
193+
pub server_version: String,
194+
pub server_version_tag: String,
195+
}
196+
197+
impl ToV1 for esc_api::mesdb::SharedCluster {
198+
type V1Type = SharedCluster;
199+
fn to_v1(self) -> Self::V1Type {
200+
SharedCluster {
201+
created: self.created.to_rfc3339(),
202+
id: self.id,
203+
name: self.name,
204+
org_id: self.organization_id.to_v1(),
205+
project_id: self.project_id,
206+
provider: Provider::from_string(&self.provider),
207+
region: self.region,
208+
topology: self.topology,
209+
deployment_tier: self.deployment_tier,
210+
mutual_tls_enabled: self.mutual_tls_enabled,
211+
per_node_cores: self.per_node_cores,
212+
per_node_memory: self.per_node_memory as usize,
213+
per_node_volume_size: self.per_node_volume_size as usize,
214+
status: self.status.to_string(),
215+
acl_id: self.acl_id,
216+
projection_level: self.projection_level,
217+
server_version: self.server_version,
218+
server_version_tag: self.server_version_tag,
219+
}
220+
}
221+
}
222+
223+
impl ToV1 for esc_api::mesdb::CreateSharedClusterResponse {
224+
type V1Type = esc_api::mesdb::ClusterId;
225+
fn to_v1(self) -> Self::V1Type {
226+
self.id
227+
}
228+
}
229+
230+
impl ToV1 for esc_api::mesdb::GetSharedClusterResponse {
231+
type V1Type = SharedCluster;
232+
fn to_v1(self) -> Self::V1Type {
233+
self.cluster.to_v1()
234+
}
235+
}
236+
237+
impl ToV1 for esc_api::mesdb::ListSharedClustersResponse {
238+
type V1Type = List<SharedCluster>;
239+
fn to_v1(self) -> Self::V1Type {
240+
let l = self.clusters.into_iter().map(|c| c.to_v1()).collect();
241+
List(l)
242+
}
243+
}

0 commit comments

Comments
 (0)