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

fix: verify metadata is non-nil in resource allocation #77845

Merged

Conversation

draveness
Copy link
Contributor

@draveness draveness commented May 14, 2019

/kind bug

What this PR does / why we need it:

Fix a bug when metadata is nil in resource allocation.

It crashes when meta is of type *priorityMetadata but equals to nil

Related to #77498 (review)

Does this PR introduce a user-facing change?:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 14, 2019
@draveness
Copy link
Contributor Author

/assign @k82cn @Huang-Wei
/kind bug
/priority important-soon

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 14, 2019
@draveness draveness force-pushed the bugfix/resource-allocation-priority branch from b4c4772 to b05beec Compare May 14, 2019 06:08
@draveness
Copy link
Contributor Author

/retest

}
}
list, err := priorityFunction(BalancedResourceAllocationMap, nil, nil)(test.pod, nodeNameToInfo, test.nodes)
Copy link
Member

Choose a reason for hiding this comment

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

we are passing nil already in the test, was the test crashing all the time?

Copy link
Member

Choose a reason for hiding this comment

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

Let me try to explain here: "non-typed" nil and "typed" nil (i.e. "var foo *meta") behave differently in the type assertion.

Current testcase and code base are always using "non-typed" nil, so it works fine all the time. In this PR, @draveness introduced a potential "typed" nil (when hasMeta=false), so it can pass type assertion. It's a Golang gotcha which IMO should be aware of, but shouldn't practice as a pattern in code.

@draveness my suggestion is:

  1. avoid introducing "typed" nil as it can confuse people
  2. eliminate the && meta != nil check in this PR as well as feat: cache pod limits as part of metadata in priority functions #77498

Thoughts?

BTW: a write-up on typed nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SGTM, updated as your suggestion.

Copy link
Member

Choose a reason for hiding this comment

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

sure, but in the new code, if you pass a typed nil, wouldn't that cause a crash? shouldn't we make sure that does not happen?

@draveness draveness force-pushed the bugfix/resource-allocation-priority branch 2 times, most recently from 9d3c1fd to 0ad4624 Compare May 18, 2019 01:55
@draveness draveness force-pushed the bugfix/resource-allocation-priority branch from 0ad4624 to 7336725 Compare May 18, 2019 02:05
@draveness
Copy link
Contributor Author

/retest

1 similar comment
@Huang-Wei
Copy link
Member

/retest

Copy link
Member

@Huang-Wei Huang-Wei 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 k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 19, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: draveness, Huang-Wei

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 May 19, 2019
@k8s-ci-robot k8s-ci-robot merged commit 8903155 into kubernetes:master May 19, 2019
@draveness draveness deleted the bugfix/resource-allocation-priority branch May 19, 2019 06:27
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants