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

Mitigate potential range panic #724

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mariusvniekerk
Copy link

What type of PR is this?

/kind bug

What this PR does / why we need it:

When a podgroup has a MinMember set to 0 and no pods exist, the reconciler can encounter a range exception.

I have observed this on v0.26.7. The underlying code is still the same so it is likely the same weakness exists in the currently.

The crash appears as follows

panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 227 [running]:
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
	/go/src/sigs.k8s.io/scheduler-plugins/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:119 +0x1fa
panic({0x16c9880, 0xc0001dc000})
	/usr/local/go/src/runtime/panic.go:884 +0x212
sigs.k8s.io/scheduler-plugins/pkg/controllers.(*PodGroupReconciler).Reconcile(0xc000477d60, {0x1a1fbb8, 0xc0003cf230}, {{{0xc000a08378?, 0x10?}, {0xc0005010c0?, 0x40da67?}}})
	/go/src/sigs.k8s.io/scheduler-plugins/pkg/controllers/podgroup_controller.go:112 +0x9c6
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x1a1fbb8?, {0x1a1fbb8?, 0xc0003cf230?}, {{{0xc000a08378?, 0x1567320?}, {0xc0005010c0?, 0x0?}}})
	/go/src/sigs.k8s.io/scheduler-plugins/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:122 +0xc8
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc000422a00, {0x1a1fb10, 0xc0008a0c80}, {0x1634dc0?, 0xc000460020?})
	/go/src/sigs.k8s.io/scheduler-plugins/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:323 +0x38f
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc000422a00, {0x1a1fb10, 0xc0008a0c80})
	/go/src/sigs.k8s.io/scheduler-plugins/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:274 +0x1d9
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
	/go/src/sigs.k8s.io/scheduler-plugins/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:235 +0x85
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2
	/go/src/sigs.k8s.io/scheduler-plugins/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:231 +0x333

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE


When a podgroup has a MinMember set to 0 and no pods exist, the reconciler can encounter a range exception.

I have observed this on v0.26.7.  The underlying code is still the same so it is likely the same weakness exists in the currently.
@k8s-ci-robot
Copy link
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.

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/test-infra 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. labels Apr 23, 2024
Copy link

linux-foundation-easycla bot commented Apr 23, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: mariusvniekerk / name: Marius van Niekerk (af11077)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Apr 23, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @mariusvniekerk!

It looks like this is your first PR to kubernetes-sigs/scheduler-plugins 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/scheduler-plugins has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@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 23, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @mariusvniekerk. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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. Regular contributors should join the org to skip this step.

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.

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/test-infra repository.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

The full list of commands accepted by this bot can be found 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

Copy link

netlify bot commented Apr 23, 2024

Deploy Preview for kubernetes-sigs-scheduler-plugins canceled.

Name Link
🔨 Latest commit af11077
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-scheduler-plugins/deploys/662781c3da52260008107046

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 23, 2024
@Huang-Wei
Copy link
Contributor

/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 23, 2024
@Huang-Wei
Copy link
Contributor

Huang-Wei commented Apr 24, 2024

When a podgroup has a MinMember set to 0

I think we should always ensure the PodGroup's .minMember is greater than 0:

diff --git a/apis/scheduling/v1alpha1/types.go b/apis/scheduling/v1alpha1/types.go
index 86901dd5..8aaf6aa5 100644
--- a/apis/scheduling/v1alpha1/types.go
+++ b/apis/scheduling/v1alpha1/types.go
@@ -137,6 +137,7 @@ type PodGroupSpec struct {
 	// MinMember defines the minimal number of members/tasks to run the pod group;
 	// if there's not enough resources to start all tasks, the scheduler
 	// will not start anyone.
+	// +kubebuilder:validation:Minimum=1
 	MinMember int32 `json:"minMember,omitempty"`
 
 	// MinResources defines the minimal resource of members/tasks to run the pod group;

After that, run hack/update-codegen.sh to generate a new CRD manifest. (and also update manifests/coscheduling/crd.yaml manually)

@mariusvniekerk
Copy link
Author

mariusvniekerk commented Apr 24, 2024

I think we should always ensure the PodGroup's .minMember is greater than 0:

I assumed that it could be validly be 0 if relying on .minResources instead.

@Huang-Wei
Copy link
Contributor

I assumed that it could be validly be 0 if relying on .minResources instead.

IMHO, I think the case (0 .minMember along with non-empty .minResources) is not legit. Are you have some real-world usecase using this semantics?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants