Skip to content

Commit

Permalink
switch deployed version
Browse files Browse the repository at this point in the history
  • Loading branch information
sebt3 committed Apr 8, 2024
1 parent 1555ad3 commit ec2beff
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 131 deletions.
192 changes: 108 additions & 84 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ tokio = { version = "1.23.0", features = ["macros", "rt-multi-thread"] }
chrono = "0.4.24"

[dependencies.kube]
default-features = false
features = ["runtime", "client", "derive", "openssl-tls"]
features = ["runtime", "client", "derive"]
version = "0.90.0"

[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion agent/src/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub async fn clone(target: &PathBuf, client: kube::Client, dist: &client::Distri
DistribComponent::new(
get_commit_id(&comp_dir.clone()).or_else(|e: Error| bail!("{e}"))?,
yaml.metadata.description,
yaml.options,
yaml.options.into_iter().collect(),
yaml.dependencies,
yaml.providers,
),
Expand Down
16 changes: 10 additions & 6 deletions agent/src/destroy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ pub struct Parameters {
}

pub async fn destroy(src: &PathBuf, script: &mut script::Script, client: kube::Client, inst: &client::Install) -> Result<()> {
inst.update_status_start_destroy(client.clone(), AGENT).await.map_err(|e| anyhow!("{e}"))?;
match inst.update_status_start_destroy(client.clone(), AGENT).await {Ok(_) => {}, Err(e) =>
{log::warn!("While updating instance status event we got {:?}", e)}
};
// run pre-plan stage from rhai script if any
let stage = "destroy".to_string();
script.run_pre_stage(&stage).or_else(|e: Error| {bail!("{e}")})?;
Expand All @@ -40,12 +42,14 @@ pub async fn destroy(src: &PathBuf, script: &mut script::Script, client: kube::C
terraform::run_destroy(src).or_else(|e: Error| {bail!("{e}")})?;
// run post-plan stage from rhai script if any
script.run_post_stage(&stage).or_else(|e: Error| {bail!("{e}")}).or_else(|e: Error| {bail!("{e}")})?;
inst.update_status_end_destroy(client.clone(), AGENT).await.map_err(|e| anyhow!("{e}"))?;
match inst.update_status_end_destroy(client.clone(), AGENT).await {Ok(_) => {}, Err(e) =>
{log::warn!("While updating instance status event we got {:?}", e)}
};
match events::report(AGENT, client,events::from(
format!("Deleting {}",inst.name()),
format!("Terraform destroy for `{}`",inst.name()),
Some(format!("Terraform destroy for `{}` successfully completed",inst.name()
))), inst.object_ref(&())).await {Ok(_) => {}, Err(e) =>
format!("Deleting"),
format!("Terraform destroy for '{}.{}'",inst.namespace(),inst.name()),
Some(format!("Terraform destroy for '{}.{}' successfully completed",inst.namespace(),inst.name()))
), inst.object_ref(&())).await {Ok(_) => {}, Err(e) =>
{log::warn!("While sending event we got {:?}", e)}
};
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions agent/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ pub async fn install(src: &PathBuf, script: &mut script::Script, client: kube::C
let new_state = match serde_json::from_str(&content) {Ok(d) => d, Err(e) => bail!("Error {} while reading: {}", e, path.display())};
inst.update_status_apply(client.clone(), AGENT, new_state, std::env::var("COMMIT_ID").unwrap_or_else(|_| String::new())).await.map_err(|e| anyhow!("{e}"))?;
events::report(AGENT, client,events::from(
format!("Installing {}",inst.name()),
format!("Terraform apply for `{}`",inst.name()),
Some(format!("Terraform apply for `{}` successfully completed",inst.name()
))), inst.object_ref(&())).await.unwrap();
format!("Installing"),
format!("Terraform apply for '{}.{}'",inst.namespace(),inst.name()),
Some(format!("Terraform apply for '{}.{}' successfully completed",inst.namespace(),inst.name()))
), inst.object_ref(&())).await.unwrap();
Ok(())
}

Expand Down
8 changes: 4 additions & 4 deletions agent/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ pub async fn plan (src: &PathBuf, script: &mut script::Script, client: kube::Cli
// Upload the plan to the status->plan of the k8s Install Object
inst.update_status_plan(client.clone(), AGENT, plan).await.map_err(|e| anyhow!("{e}"))?;
events::report(AGENT, client,events::from(
format!("Preparing {}",inst.name()),
format!("Terraform plan for `{}`",inst.name()),
Some(format!("Terraform plan for `{}` successfully completed",inst.name()
))), inst.object_ref(&())).await.unwrap();
format!("Planning"),
format!("Terraform plan for '{}.{}'",inst.namespace(),inst.name()),
Some(format!("Terraform plan for '{}.{}' successfully completed",inst.namespace(),inst.name()))
), inst.object_ref(&())).await.unwrap();
Ok(())
}

Expand Down
16 changes: 10 additions & 6 deletions agent/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ pub async fn template(src: PathBuf, dest: PathBuf, client: kube::Client,
config:&serde_json::Map<String, serde_json::Value>,
script: &mut script::Script) -> Result<()> {
let providers = yaml.providers.clone();
inst.update_status_start_template(client.clone(), AGENT).await.map_err(|e| anyhow!("{e}"))?;
match inst.update_status_start_template(client.clone(), AGENT).await {Ok(_) => {}, Err(e) =>
{log::warn!("While updating install status we got {:?}", e)}
};
let reg = Handlebars::new();
// run pre-template stage from rhai script if any
let stage = "template".to_string();
Expand Down Expand Up @@ -69,12 +71,14 @@ pub async fn template(src: PathBuf, dest: PathBuf, client: kube::Client,
terraform::gen_tfvars(&dest, config).or_else(|e: Error| {bail!("{e}")})?;
// run post-template stage from rhai script if any
script.run_post_stage(&stage).or_else(|e: Error| {bail!("{e}")})?;
inst.update_status_end_template(client.clone(), AGENT).await.map_err(|e| anyhow!("{e}"))?;
match inst.update_status_end_template(client.clone(), AGENT).await {Ok(_) => {}, Err(e) =>
{log::warn!("While updating install status we got {:?}", e)}
};
match events::report(AGENT, client,events::from(
format!("Installing {}",inst.name()),
format!("Generating templates for `{}`",inst.name()),
Some(format!("Generating templates for `{}` successfully completed",inst.name()
))), inst.object_ref(&())).await {Ok(_) => {}, Err(e) =>
format!("Templating"),
format!("Generating templates for '{}.{}'",inst.namespace(),inst.name()),
Some(format!("Generating templates for '{}.{}' successfully completed",inst.namespace(),inst.name()))
), inst.object_ref(&())).await {Ok(_) => {}, Err(e) =>
{log::warn!("While sending event we got {:?}",e)}
};
Ok(())
Expand Down
Loading

0 comments on commit ec2beff

Please sign in to comment.