Skip to content

Commit

Permalink
add logging to ecs cluster provider
Browse files Browse the repository at this point in the history
  • Loading branch information
webern committed May 5, 2022
1 parent f0a5952 commit 871aa59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bottlerocket/agents/src/bin/ecs-resource-agent/ecs_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use aws_sdk_iam::output::GetInstanceProfileOutput;
use aws_types::sdk_config::SdkConfig;
use bottlerocket_agents::aws_resource_config;
use bottlerocket_types::agent_config::{EcsClusterConfig, AWS_CREDENTIALS_SECRET_NAME};
use log::{error, info};
use model::{Configuration, SecretName};
use resource_agent::clients::InfoClient;
use resource_agent::provider::{
Expand Down Expand Up @@ -74,6 +75,7 @@ impl Create for EcsCreator {
where
I: InfoClient,
{
info!("Creating ECS cluster");
let mut memo: Memo = client
.get_info()
.await
Expand All @@ -100,15 +102,18 @@ impl Create for EcsCreator {
let ecs_client = aws_sdk_ecs::Client::new(&config);
let iam_client = aws_sdk_iam::Client::new(&config);

info!("Creating cluster '{}'", spec.configuration.cluster_name);
ecs_client
.create_cluster()
.cluster_name(&spec.configuration.cluster_name)
.send()
.await
.context(Resources::Clear, "The cluster could not be created.")?;

info!("Creating instance profile");
let iam_arn = create_iam_instance_profile(&iam_client).await?;

info!("Getting cluster information");
let created_cluster = created_cluster(
&config,
&spec.configuration.cluster_name,
Expand Down Expand Up @@ -301,6 +306,7 @@ impl Destroy for EcsDestroyer {
where
I: InfoClient,
{
info!("Running destroy");
let mut memo: Memo = client
.get_info()
.await
Expand All @@ -316,6 +322,10 @@ impl Destroy for EcsDestroyer {
.await?;
let ecs_client = aws_sdk_ecs::Client::new(&config);

info!(
"Deleting cluster '{}'",
memo.cluster_name.as_deref().unwrap_or_default()
);
if let Some(cluster_name) = &memo.cluster_name {
ecs_client
.delete_cluster()
Expand All @@ -326,13 +336,14 @@ impl Destroy for EcsDestroyer {

memo.current_status = "Cluster deleted".into();
if let Err(e) = client.send_info(memo.clone()).await {
eprintln!(
error!(
"Cluster deleted but failed to send info message to k8s: {}",
e
)
}
}

info!("Done with cluster deletion");
Ok(())
}
}
Expand Down
2 changes: 2 additions & 0 deletions bottlerocket/agents/src/bin/ecs-resource-agent/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ Provides (or queries) an ECS cluster for use in Bottlerocket testing.
mod ecs_provider;

use crate::ecs_provider::{EcsCreator, EcsDestroyer};
use bottlerocket_agents::init_agent_logger;
use resource_agent::clients::{DefaultAgentClient, DefaultInfoClient};
use resource_agent::error::AgentResult;
use resource_agent::{Agent, BootstrapData, Types};
use std::marker::PhantomData;

#[tokio::main]
async fn main() {
init_agent_logger(env!("CARGO_CRATE_NAME"), None);
let data = match BootstrapData::from_env() {
Ok(ok) => ok,
Err(e) => {
Expand Down

0 comments on commit 871aa59

Please sign in to comment.