Skip to content

Commit 8fa2318

Browse files
tas50claude
andcommitted
🐛 Fix insights N+1, addonVersion cache collision, and nil pointer in EKS
- Eagerly populate insight fields from ListInsights summary to avoid N+1 DescribeInsight calls (name, category, insightStatus are @defaults) - Include region in addonVersion __id to prevent cache collisions across regions - Add nil check on DescribeInsight response to prevent nil pointer panic Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 94f0005 commit 8fa2318

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

providers/aws/resources/aws.lr.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

providers/aws/resources/aws_eks.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,8 +1636,21 @@ func (a *mqlAwsEksCluster) insights() ([]any, error) {
16361636
if err != nil {
16371637
return nil, err
16381638
}
1639-
mqlInsight.(*mqlAwsEksInsight).clusterName = a.Name.Data
1640-
mqlInsight.(*mqlAwsEksInsight).region = regionVal
1639+
cast := mqlInsight.(*mqlAwsEksInsight)
1640+
cast.clusterName = a.Name.Data
1641+
cast.region = regionVal
1642+
1643+
// Eagerly populate fields available from the list summary to avoid
1644+
// N+1 DescribeInsight calls (especially for @defaults fields).
1645+
cast.Name = plugin.TValue[string]{Data: convert.ToValue(summary.Name), State: plugin.StateIsSet}
1646+
cast.Category = plugin.TValue[string]{Data: string(summary.Category), State: plugin.StateIsSet}
1647+
statusDict, _ := convert.JsonToDict(summary.InsightStatus)
1648+
cast.InsightStatus = plugin.TValue[any]{Data: statusDict, State: plugin.StateIsSet}
1649+
cast.KubernetesVersion = plugin.TValue[string]{Data: convert.ToValue(summary.KubernetesVersion), State: plugin.StateIsSet}
1650+
cast.Description = plugin.TValue[string]{Data: convert.ToValue(summary.Description), State: plugin.StateIsSet}
1651+
cast.LastRefreshTime = plugin.TValue[*time.Time]{Data: summary.LastRefreshTime, State: plugin.StateIsSet}
1652+
cast.LastTransitionTime = plugin.TValue[*time.Time]{Data: summary.LastTransitionTime, State: plugin.StateIsSet}
1653+
16411654
res = append(res, mqlInsight)
16421655
}
16431656
}
@@ -1678,6 +1691,11 @@ func (a *mqlAwsEksInsight) fetchDetails() (*ekstypes.Insight, error) {
16781691
a.fetched = true
16791692
return nil, err
16801693
}
1694+
if desc.Insight == nil {
1695+
a.fetchErr = errors.New("DescribeInsight returned nil insight for " + a.Id.Data)
1696+
a.fetched = true
1697+
return nil, a.fetchErr
1698+
}
16811699
a.details = desc.Insight
16821700
a.fetched = true
16831701
return desc.Insight, nil
@@ -1814,7 +1832,7 @@ func (a *mqlAwsEksCluster) availableAddonVersions() ([]any, error) {
18141832

18151833
mqlAddonVersion, err := CreateResource(a.MqlRuntime, "aws.eks.addonVersion",
18161834
map[string]*llx.RawData{
1817-
"__id": llx.StringData(fmt.Sprintf("aws.eks.addonVersion/%s/%s", addonName, version)),
1835+
"__id": llx.StringData(fmt.Sprintf("aws.eks.addonVersion/%s/%s/%s", regionVal, addonName, version)),
18181836
"addonName": llx.StringData(addonName),
18191837
"addonVersion": llx.StringData(version),
18201838
"architectures": llx.ArrayData(archs, "\x02"),
@@ -1827,6 +1845,7 @@ func (a *mqlAwsEksCluster) availableAddonVersions() ([]any, error) {
18271845
}
18281846
// Set compatibilities eagerly since we already have the data
18291847
cast := mqlAddonVersion.(*mqlAwsEksAddonVersion)
1848+
cast.region = regionVal
18301849
cast.Compatibilities = plugin.TValue[[]any]{Data: compats, State: plugin.StateIsSet}
18311850
res = append(res, mqlAddonVersion)
18321851
}
@@ -1835,8 +1854,12 @@ func (a *mqlAwsEksCluster) availableAddonVersions() ([]any, error) {
18351854
return res, nil
18361855
}
18371856

1857+
type mqlAwsEksAddonVersionInternal struct {
1858+
region string
1859+
}
1860+
18381861
func (a *mqlAwsEksAddonVersion) id() (string, error) {
1839-
return fmt.Sprintf("aws.eks.addonVersion/%s/%s", a.AddonName.Data, a.AddonVersion.Data), nil
1862+
return fmt.Sprintf("aws.eks.addonVersion/%s/%s/%s", a.region, a.AddonName.Data, a.AddonVersion.Data), nil
18401863
}
18411864

18421865
func (a *mqlAwsEksAddonVersion) compatibilities() ([]any, error) {

0 commit comments

Comments
 (0)