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

fix(deployer): check correct config field(s) in resource cache #1675

Merged
merged 4 commits into from
Mar 12, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/src/backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ClaimExt for Claim {
.len();
}

Ok(self.limits.rds_quota > (rds_count as u32))
Ok(self.limits.rds_quota > (rds_count as u32) || self.is_admin())
}

#[instrument(skip_all)]
Expand Down
24 changes: 13 additions & 11 deletions deployer/src/deployment/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use shuttle_common::{
DEPLOYER_END_MSG_COMPLETED, DEPLOYER_END_MSG_CRASHED, DEPLOYER_END_MSG_STARTUP_ERR,
DEPLOYER_END_MSG_STOPPED, DEPLOYER_RUNTIME_START_FAILED, DEPLOYER_RUNTIME_START_RESPONSE,
},
resource::{self, ProvisionResourceRequest, ResourceInput},
resource::{self, ResourceInput, Type},
DatabaseResource, DbInput, SecretStore,
};
use shuttle_proto::{
Expand Down Expand Up @@ -414,27 +414,26 @@ async fn load(
}
}

fn log(ty: resource::Type, msg: &str) {
fn log(ty: &resource::Type, msg: &str) {
info!("[Resource][{}] {}", ty, msg);
}

/// If an old resource with matching type + config and valid data exists, return it
fn get_cached_output<T: DeserializeOwned>(
shuttle_resource: &ProvisionResourceRequest,
shuttle_resource_type: &Type,
config: &serde_json::Value,
prev_resources: &[resource::Response],
) -> Option<T> {
prev_resources
.iter()
.find(|resource| {
resource.r#type == shuttle_resource.r#type && resource.config == shuttle_resource.config
})
.find(|resource| resource.r#type == *shuttle_resource_type && resource.config == *config)
.and_then(|resource| {
let cached_output = resource.data.clone();
log(shuttle_resource.r#type, "Found cached output");
log(shuttle_resource_type, "Found cached output");
match serde_json::from_value::<T>(cached_output) {
Ok(output) => Some(output),
Err(_) => {
log(shuttle_resource.r#type, "Failed to validate cached output");
log(shuttle_resource_type, "Failed to validate cached output");
None
}
}
Expand Down Expand Up @@ -501,12 +500,15 @@ async fn provision(
// no config fields are used yet, but verify the format anyways
let config: DbInput = serde_json::from_value(shuttle_resource.config.clone())
.context("deserializing resource config")?;

let output = get_cached_output(&shuttle_resource, prev_resources.as_slice());
// We pass a Null config right now because this is relevant only for updating the resources
// through the provisioner, which is something we don't support currently. If there will be
// config fields that are relevant for provisioner updates on top of resources, they should
// be cached.
let output = get_cached_output(&shuttle_resource.r#type, &serde_json::Value::Null, prev_resources.as_slice());
let output = match output {
Some(o) => o,
None => {
log(shuttle_resource.r#type, "Provisioning...");
log(&shuttle_resource.r#type, "Provisioning...");
// ###
let mut req = Request::new(DatabaseRequest {
project_name: project_name.to_string(),
Expand Down