Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bolt): update datacenters from CLI #727

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions fern/definition/admin/clusters/datacenters/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ service:
request:
body: CreateRequest
response: CreateResponse
update:
path: /{datacenter_id}
path-parameters:
datacenter_id:
type: uuid
method: PATCH
request:
body: UpdateRequest
taint:
path: /{datacenter_id}/taint
path-parameters:
Expand All @@ -42,3 +50,10 @@ types:
CreateResponse:
properties:
datacenter_id: uuid
UpdateRequest:
properties:
pool_type: localCommons.PoolType
hardware: list<localCommons.Hardware>
desired_count: optional<integer>
max_count: optional<integer>
drain_timeout: optional<long>
10 changes: 5 additions & 5 deletions lib/api-helper/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ impl Endpoint {
struct EndpointFunction {
/// Path of the given Rust function.
path: syn::Path,
/// Request type of the endpoint. (GET, PUT, POST, etc)
/// Request type of the endpoint. (GET, POST, PUT, PATCH, etc)
req_type: String,
/// The request `body` type.
body: Option<syn::Expr>,
Expand All @@ -574,11 +574,11 @@ impl Parse for EndpointFunction {
let req_type = req_type_ident.to_string();

match req_type.as_str() {
"GET" | "POST" | "PUT" | "DELETE" => {}
"GET" | "POST" | "PUT" | "PATCH" | "DELETE" => {}
_ => {
return Err(syn::Error::new(
req_type_ident.span(),
"Invalid endpoint request type (try GET, POST, PUT, DELETE)",
"Invalid endpoint request type (try GET, POST, PUT, PATCH, DELETE)",
));
}
};
Expand Down Expand Up @@ -609,7 +609,7 @@ impl Parse for EndpointFunction {
.map(|arg| arg.value.expect_expr().cloned())
.transpose()?;

// Make sure body is set for post and put requests
// Make sure body is set for post, put, and patch requests
if body.is_none()
&& !args
.iter()
Expand All @@ -618,7 +618,7 @@ impl Parse for EndpointFunction {
if req_type != "GET" && req_type != "DELETE" {
return Err(syn::Error::new(
args_tt.span,
"POST and PUT endpoints must have a body argument",
"POST, PUT, and PATCH endpoints must have a body argument",
));
}
} else if req_type == "DELETE" || req_type == "GET" {
Expand Down
105 changes: 101 additions & 4 deletions lib/bolt/cli/src/commands/admin/cluster/datacenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ impl From<DatacenterBuildDeliveryMethod> for models::AdminBuildDeliveryMethod {
}
}

#[derive(ValueEnum, Clone)]
pub enum DatacenterPoolType {
Job,
Gg,
Ats,
}

impl From<DatacenterPoolType> for models::AdminPoolType {
fn from(pool_type: DatacenterPoolType) -> Self {
match pool_type {
DatacenterPoolType::Job => models::AdminPoolType::Job,
DatacenterPoolType::Gg => models::AdminPoolType::Gg,
DatacenterPoolType::Ats => models::AdminPoolType::Ats,
}
}
}

#[derive(Parser)]
pub enum SubCommand {
/// Creates a new datacenter
Expand Down Expand Up @@ -73,6 +90,30 @@ pub enum SubCommand {
#[clap(long, short = 'd')]
name_id: String,
},
/// Update a datacenter's pools
Update {
AngelOnFira marked this conversation as resolved.
Show resolved Hide resolved
/// The name id of the cluster
#[clap(long, short = 'c')]
cluster: String,
/// The name id of the datacenter
#[clap(index = 1)]
name_id: String,
/// The pool type
#[clap(index = 2)]
pool: DatacenterPoolType,
/// The hardware types
#[clap(long)]
hardware: Vec<String>,
/// The desired count
#[clap(long)]
desired_count: Option<i32>,
/// The max count
#[clap(long)]
max_count: Option<i32>,
/// The drain timeout
#[clap(long)]
drain_timeout: Option<i64>,
},
}

#[derive(Tabled)]
Expand All @@ -92,10 +133,10 @@ impl SubCommand {
provider_datacenter_id,
build_delivery_method,
} => {
ensure!(
ctx.ns().rivet.provisioning.is_some(),
"Provisioning is not enabled on this cluster"
);
// ensure!(
// ctx.ns().rivet.provisioning.is_some(),
// "Provisioning is not enabled on this cluster"
// );

let clusters =
admin_clusters_api::admin_clusters_list(&ctx.openapi_config_cloud().await?)
Expand Down Expand Up @@ -188,6 +229,62 @@ impl SubCommand {
)
.await?;
}
Self::Update {
cluster: cluster_name_id,
name_id,
pool,
hardware,
desired_count,
max_count,
drain_timeout,
} => {
let clusters =
admin_clusters_api::admin_clusters_list(&ctx.openapi_config_cloud().await?)
.await?
.clusters;

let cluster = clusters.iter().find(|c| c.name_id == cluster_name_id);

let cluster = match cluster {
Some(c) => c,
None => bail!("cluster with the name id {} not found", cluster_name_id),
};

let datacenters = admin_clusters_datacenters_api::admin_clusters_datacenters_list(
&ctx.openapi_config_cloud().await?,
&cluster.cluster_id.to_string(),
)
.await?
.datacenters;

let datacenter = datacenters.iter().find(|d| d.name_id == name_id);

let datacenter = match datacenter {
Some(d) => d,
None => bail!("datacenter with the name id {} not found", name_id),
};

admin_clusters_datacenters_api::admin_clusters_datacenters_update(
&ctx.openapi_config_cloud().await?,
&cluster.cluster_id.to_string(),
&datacenter.datacenter_id.to_string(),
models::AdminClustersDatacentersUpdateRequest {
desired_count,
drain_timeout,
hardware: hardware
.iter()
.map(|hardware| models::AdminHardware {
provider_hardware: hardware.clone(),
})
.collect(),
max_count,
pool_type: pool.into(),
},
)
.await?;

rivet_term::status::success("Datacenter updated", "");
}
}

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions lib/bolt/cli/src/commands/admin/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ impl SubCommand {
name_id,
owner_team_id,
} => {
ensure!(
ctx.ns().rivet.provisioning.is_some(),
"Provisioning is not enabled on this cluster"
);
// ensure!(
// ctx.ns().rivet.provisioning.is_some(),
// "Provisioning is not enabled on this cluster"
// );

admin_clusters_api::admin_clusters_create(
&ctx.openapi_config_cloud().await?,
Expand Down
76 changes: 76 additions & 0 deletions sdks/full/go/admin/clusters/datacenters/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions sdks/full/go/admin/clusters/datacenters/datacenters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading