fix(clusterapi): check RBAC before syncing infrastructure template cache #10619
All Vouch review confidence checks passed
Residual risk 0.35 = Change Risk (0.65) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.65 · 327 lines diff across 4 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.347
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.065
Real PR Conversation Timeline
1 comments
"Review active on #10619"
general
weight: 0.35
elmiko
What type of PR is this?
/kind bug
What this PR does / why we need it:
When
getInfrastructureResourcelooks up an infrastructure machine template (fromCanScaleFromZero->InstanceCapacityorTemplateNodeInfo->InstanceCapacity/InstanceSystemInfo), it creates and starts a dynamic informer viac.managementInformerFactory.ForResource(resource)and waits oncache.WaitForCacheSync(c.stopChannel, informer.Informer().HasSynced).If the Cluster Autoscaler ServiceAccount does not have RBAC permissions to
listandwatchthe infrastructure machine template resource (for example, when capacity is configured viacapacity.cluster-autoscaler.kubernetes.io/annotations on theMachineDeployment/MachineSet, or when scaling from non-zero replicas without scale-from-zero RBAC), the reflector'sListAndWatchfails with403 Forbidden,informer.Informer().HasSynced()never becomestrue, andcache.WaitForCacheSyncblocks indefinitely untilc.stopChannelis closed. Because this happens synchronously on the main autoscaler loop, all scale-up and scale-down operations stall across the cluster.This change follows the approach from #6498 by checking
listandwatchpermissions on the management cluster (in the namespace scope watched bymanagementInformerFactory) viaSelfSubjectAccessReviewwith a 30s request timeout before starting and syncing the infrastructure resource informer, caching allowed and denied decisions for 1 minute (infraAccessCacheTTL, matchingkindVersionCacheTTL) across wrapper rebuilds. When access is not allowed,getInfrastructureResourcereturnsnil, nil, allowingInstanceCapacity()to fall back tocapacity.cluster-autoscaler.kubernetes.io/annotations when present or return empty capacity without blocking the reconciliation loop.Which issue(s) this PR fixes:
Fixes #10416
Fixes #6490
Special notes for your reviewer:
Builds on #6498 by @jackfrancis, adding the
SelfSubjectAccessReviewreactor inNewTestMachineController(sincefakekube.NewSimpleClientset()returnsStatus.Allowed: falseby default forSelfSubjectAccessReviewobjects) along with unit tests covering deniedlist/watchaccess, namespace-scoped grants, and access-review caching.Does this PR introduce a user-facing change?
``
release-noteFix Cluster API provider hanging indefinitely in WaitForCacheSync when the autoscaler lacks RBAC permissions to list or watch infrastructure machine templates.
docs
``