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

eks-resource: process paginated results from list-stacks #873

Merged
merged 1 commit into from
Sep 28, 2023
Merged
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
60 changes: 40 additions & 20 deletions bottlerocket/agents/src/bin/eks-resource-agent/eks_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,33 +458,53 @@ async fn nodegroup_iam_role(
cluster_name: &str,
cfn_client: &aws_sdk_cloudformation::Client,
) -> ProviderResult<String> {
let stack_name = cfn_client
let mut list_stack_output = cfn_client
.list_stacks()
.stack_status_filter(StackStatus::CreateComplete)
.stack_status_filter(StackStatus::UpdateComplete)
.send()
.await
.context(Resources::Remaining, "Unable to list CloudFormation stacks")?
.stack_summaries()
.context(
Resources::Remaining,
"Missing CloudFormation stack summaries",
)?
.iter()
.filter_map(|stack| stack.stack_name())
.find(|name|
// For eksctl created clusters
name.starts_with(&format!("eksctl-{cluster_name}-nodegroup"))
// For non-eksctl created clusters
|| name.starts_with(&format!("{cluster_name}-node-group")))
.context(
Resources::Remaining,
"Could not find nodegroup cloudformation stack for cluster",
)?
.to_string();
.context(Resources::Remaining, "Unable to list CloudFormation stacks")?;

let stack_name;
loop {
if let Some(name) = list_stack_output
.stack_summaries()
.context(
Resources::Remaining,
"Missing CloudFormation stack summaries",
)?
.iter()
.filter_map(|stack| stack.stack_name())
.find(|name|
// For eksctl created clusters
name.starts_with(&format!("eksctl-{cluster_name}-nodegroup"))
// For non-eksctl created clusters
|| name.starts_with(&format!("{cluster_name}-node-group")))
{
stack_name = name;
break;
} else if let Some(token) = list_stack_output.next_token() {
list_stack_output = cfn_client
.list_stacks()
.next_token(token)
.stack_status_filter(StackStatus::CreateComplete)
.stack_status_filter(StackStatus::UpdateComplete)
.send()
.await
.context(Resources::Remaining, "Unable to list CloudFormation stacks")?;
continue;
} else {
return Err(ProviderError::new_with_context(
Resources::Remaining,
"Could not find nodegroup cloudformation stack for cluster",
));
Comment on lines +498 to +501
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Err(ProviderError::new_with_context(
Resources::Remaining,
"Could not find nodegroup cloudformation stack for cluster",
));
return Err(ProviderError::new_with_context(
Resources::Remaining,
format!("Could not find nodegroup cloudformation stack '{}'
for cluster '{}'", stack.name(), cluster_name),
));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this in a follow up after I'm back

}
}

cfn_client
.describe_stack_resource()
.stack_name(&stack_name)
.stack_name(stack_name)
.logical_resource_id("NodeInstanceRole")
.send()
.await
Expand Down