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

vpa-recommender: Prevent nil pointer dereference #7161

Merged
merged 2 commits into from
Aug 15, 2024

Conversation

ialidzhikov
Copy link
Contributor

@ialidzhikov ialidzhikov commented Aug 14, 2024

What type of PR is this?

/kind regression

What this PR does / why we need it:

With 628fc39 I introduced the following nil pointer dereference to VPA 1.2.0:

I0814 11:04:28.216725       1 cluster_feeder.go:265] Loading VPA kube-system/kube-proxy-cpu-8-64-v1.29 checkpoint for conntrack-fix
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x161e6d5]

goroutine 102 [running]:
k8s.io/autoscaler/vertical-pod-autoscaler/pkg/recommender/input.(*clusterStateFeeder).setVpaCheckpoint(0xc00bc06450?, 0xc010efa1e0)
	/gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder.go:236 +0x1d5
k8s.io/autoscaler/vertical-pod-autoscaler/pkg/recommender/input.(*clusterStateFeeder).InitFromCheckpoints(0xc001fc8160)
	/gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder.go:266 +0x6bc
main.run(0xc0004ff890)
	/gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/recommender/main.go:269 +0xf38
main.main.func1({0xc000003c80?, 0x0?})
	/gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/recommender/main.go:169 +0x17
created by k8s.io/client-go/tools/leaderelection.(*LeaderElector).Run in goroutine 1
	/gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go:213 +0xe6

In

vpaID := model.VpaID{Namespace: checkpoint.Namespace, VpaName: checkpoint.Spec.VPAObjectName}
vpa, exists := feeder.clusterState.Vpas[vpaID]
if !exists {
return fmt.Errorf("cannot load checkpoint to missing VPA object %s/%s", vpa.ID.Namespace, vpa.ID.VpaName)
}

for returning the err we have to use the vpaID var as the vpa var will be always nil when entry with the given key does not exist in the map.

Which issue(s) this PR fixes:

N/A
but see the panic above

Special notes for your reviewer:

The issue occurs when there is a VPACheckpoint and the corresponding VPA does not exists:

% ks get verticalpodautoscalercheckpoints.autoscaling.k8s.io kube-proxy-cpu-8-64-v1.29-conntrack-fix -o jsonpath='{.spec.vpaObjectName}'
kube-proxy-cpu-8-64-v1.29

% ks get vpa kube-proxy-cpu-8-64-v1.29
Error from server (NotFound): verticalpodautoscalers.autoscaling.k8s.io "kube-proxy-cpu-8-64-v1.29" not found

Does this PR introduce a user-facing change?

A `nil pointer dereference` regression introduced in vpa-recommender v1.2.0 is now fixed.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/regression Categorizes issue or PR as related to a regression from a prior release. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. area/vertical-pod-autoscaler labels Aug 14, 2024
@ialidzhikov
Copy link
Contributor Author

@raywainman
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 14, 2024
@adrianmoisey
Copy link
Member

/lgtm

@k8s-ci-robot
Copy link
Contributor

@adrianmoisey: changing LGTM is restricted to collaborators

In response to this:

/lgtm

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.

@raywainman
Copy link
Contributor

Sounds like we'll probably want to cherrypick this into 1.2.0, right?

@ialidzhikov

@ialidzhikov
Copy link
Contributor Author

Sounds like we'll probably want to cherrypick this into 1.2.0, right?

Yes, it is a very subtle bug. I am sorry again.

@ialidzhikov
Copy link
Contributor Author

/cherry-pick vpa-release-1.2

@k8s-infra-cherrypick-robot

@ialidzhikov: once the present PR merges, I will cherry-pick it on top of vpa-release-1.2 in a new PR and assign it to you.

In response to this:

/cherry-pick vpa-release-1.2

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.

@raywainman
Copy link
Contributor

Sounds like we'll probably want to cherrypick this into 1.2.0, right?

Yes, it is a very subtle bug. I am sorry again.

No worries :) A bunch of missed this in review as well. We can cut a new release with this patched in.

Copy link
Member

@kwiesmueller kwiesmueller left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ialidzhikov, kwiesmueller

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

The pull request process is described here

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 15, 2024
@k8s-ci-robot k8s-ci-robot merged commit 3097495 into kubernetes:master Aug 15, 2024
7 checks passed
@k8s-infra-cherrypick-robot

@ialidzhikov: new pull request created: #7169

In response to this:

/cherry-pick vpa-release-1.2

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.

@raywainman
Copy link
Contributor

Tracking release in #7170.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/vertical-pod-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/regression Categorizes issue or PR as related to a regression from a prior release. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

6 participants