Skip to content

Fix nil pointer dereference in atomicScaleDownNode#9453

Open
bpineau wants to merge 1 commit intokubernetes:masterfrom
DataDog:fix/nil-nodegroup-atomic-scaledown
Open

Fix nil pointer dereference in atomicScaleDownNode#9453
bpineau wants to merge 1 commit intokubernetes:masterfrom
DataDog:fix/nil-nodegroup-atomic-scaledown

Conversation

@bpineau
Copy link
Copy Markdown
Contributor

@bpineau bpineau commented Apr 3, 2026

NodeGroupForNode can return (nil, nil) when a node's instance is no longer part of any registered node group. This can happen when the GCE MIG instance cache is regenerated (by the background hourly goroutine or during a concurrent fillMigInstances call) between the pre-filtering step and the atomicScaleDownNode call: the node passes the pre-filter with stale cache data, but by the time atomicScaleDownNode queries NodeGroupForNode again, the refreshed cache no longer maps the instance to a MIG.

In any cases, the CloudProvider interface spec allows providers to return nil:

	// NodeGroupForNode returns the node group for the given node, nil if the node
	// should not be processed by cluster autoscaler, or non-nil error if such
	// occurred. Must be implemented.
	NodeGroupForNode(*apiv1.Node) (NodeGroup, error)

The crash manifests as:

  panic: runtime error: invalid memory address or nil pointer dereference
  goroutine 11809 [running]:
  ...scaledown/planner.(*Planner).atomicScaleDownNode(0xc00183c000, 0xc0f066c5c0)
    planner.go:322 +0x8b

Add a nil check for the returned nodeGroup, consistent with all other call sites of NodeGroupForNode in the codebase (pre_filtering_processor, eligibility checker).

What type of PR is this?

/kind bug

NodeGroupForNode can return (nil, nil) when a node's instance is no
longer part of any registered node group. This can happen when the
GCE MIG instance cache is regenerated (by the background hourly
goroutine or during a concurrent fillMigInstances call) between the
pre-filtering step and the atomicScaleDownNode call: the node passes
the pre-filter with stale cache data, but by the time
atomicScaleDownNode queries NodeGroupForNode again, the refreshed
cache no longer maps the instance to a MIG.

In any cases, the CloudProvider interface spec allows providers to return nil:

```go
	// NodeGroupForNode returns the node group for the given node, nil if the node
	// should not be processed by cluster autoscaler, or non-nil error if such
	// occurred. Must be implemented.
	NodeGroupForNode(*apiv1.Node) (NodeGroup, error)
```

The crash manifests as:

```
  panic: runtime error: invalid memory address or nil pointer dereference
  goroutine 11809 [running]:
  ...scaledown/planner.(*Planner).atomicScaleDownNode(0xc00183c000, 0xc0f066c5c0)
    planner.go:322 +0x8b
```

Add a nil check for the returned nodeGroup, consistent with all other
call sites of NodeGroupForNode in the codebase (pre_filtering_processor,
eligibility checker).
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/cluster-autoscaler do-not-merge/needs-area labels Apr 3, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: bpineau
Once this PR has been reviewed and has the lgtm label, please assign x13n for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 3, 2026
@k8s-ci-robot k8s-ci-robot requested a review from vadasambar April 3, 2026 09:58
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @bpineau. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 3, 2026
@Choraden
Copy link
Copy Markdown
Contributor

Choraden commented Apr 3, 2026

Makes sense. Thanks @bpineau!

/lgtm
/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 3, 2026
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 3, 2026
@bpineau
Copy link
Copy Markdown
Contributor Author

bpineau commented Apr 3, 2026

/retest

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@bpineau: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-autoscaling-e2e-gci-gce-ca-test 05a7f70 link false /test pull-autoscaling-e2e-gci-gce-ca-test

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@bpineau
Copy link
Copy Markdown
Contributor Author

bpineau commented Apr 9, 2026

Thanks @Choraden , the failing test seems to be an unrelated known issue?
#9251
https://prow.k8s.io/job-history/gs/kubernetes-ci-logs/pr-logs/directory/pull-autoscaling-e2e-gci-gce-ca-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cluster-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants