๐ fix: awsmachinetemplate: use cluster-scoped credentials for ec2 clients #6282
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.45) ร (1 โ Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 ยท Change Risk (XGBoost)
Score: 0.45 ยท 448 lines diff across 5 files
Model 2 ยท Review Depth (DistilBERT)
Depth Score: 0.02 ยท 1 substantive comment(s)
Model 3 ยท Review Timing & Attention
Session adequacy: 100% ยท Reviewer familiarity: 35%
Bedrock Claude 3 ยท Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 ยท Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.365
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #6282"
general
weight: 0.35
tthvo
<!-- Thanks for this PR! If this is your first PR please read the [contributing guide](../CONTRIBUTING.md) -->
<!-- If this PR is still work-in-progress and is being open for visibility please prefix the title with
WIP:-->What type of PR is this?
/kind bug
<!--
Add one of the following kinds:
/kind feature
/kind bug
/kind api-change
/kind cleanup
/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind flake
/kind regression
/kind support
-->
What this PR does / why we need it:
<!-- Enter a description of the change and why this change is needed -->
Replace the global controller AWS session with cluster-scoped credentials when querying EC2 for capacity and nodeInfo.
AWSCluster,ClusterScopeis usedAWSManagedControlPlane,ManagedControlPlaneScopeis used.This ensure EC2 API calls are scoped correctly to the cluster's account ID in multi-account setup. This is a follow-up for concerns in https://github.com/kubernetes-sigs/cluster-api-provider-aws/pull/6196#pullrequestreview-5366793598 and https://github.com/kubernetes-sigs/cluster-api-provider-aws/pull/6196#discussion_r4136216528.
Which issue(s) this PR fixes _(optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged)_:Fixes #6232
Special notes for your reviewer:
I couldn't find the reasons for using global-scoped credentials in the original commits, but the current
awsmachinetemplatecontroller code has a comment:As far as I understand, the
awsinstancestatecontroller manages an SQS queue in the management (controller) account; thus, the global scope is correct there.However, for
awsmachinetemplate, the machine resources (i.e. instance types, AMIs) "live" in the cluster account instead. Therefore, using cluster-scoped credentials should be the right approach, and the comment is "incorrect".AI Usage:
<!-- Declare if this PR has benefited from AI assistance in any way. Whether that's Cursor, Claude, Copilot, Codex, a local LLM, or another other AI assistant. If AI has been used please try to provide as much information as possible.
NOTE: basic autocompletion doesn't need to be declared.
If no AI assistance was used then used, write "None".
-->
I had help from Claude Code (model claude-opus-4-6) for code suggestions, and code reviews.
Checklist:
<!-- Put an "X" character inside the brackets of each completed task. Some may be optional depending on the PR in which case these can be deleted
Please add an icon to the title of this PR, the icon will be either โ ๏ธ (:warning:, major or breaking changes), โจ (:sparkles:, feature additions), ๐ (:bug:, patch and bugfixes), ๐ (:book:, documentation or proposals), or ๐ฑ (:seedling:, minor or other)
-->
Release note:
<!-- Write your release note:
1. Enter your extended release note in the below block. If the PR requires additional action from users switching to the new release, include the string "action required".
2. If no release note is required, just write "NONE".
-->
``
release-note
``fix: AWSMachineTemplate controller to construct EC2 client from cluster-scoped credentials instead of the global-scoped one.