-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Refactor NewXXXPlugin in framework_test to avoid package variables #81460
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/assign @Huang-Wei
/priority important-soon
Thanks @hex108
@@ -637,20 +650,21 @@ func TestNormalizeScorePlugin(t *testing.T) { | |||
t.Errorf("Expected the pod to be scheduled. error: %v", err) | |||
} | |||
|
|||
if scoreWithNormalizePlguin.numScoreCalled == 0 { | |||
if scoreWithNormalizePlugin.numScoreCalled == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hex108 for a very good catch on the flake test!
func NewScorePlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { | ||
return scPlugin, nil | ||
// NewScorePlugin returns a factory for score plugin with specified ScorePlugin. | ||
func NewScorePlugin(scorePlugin *ScorePlugin) framework.PluginFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need to export those New* functions? should be enough if we do newScorePlugin etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree :) Addressed it.
@@ -563,6 +564,12 @@ func TestPrefilterPlugin(t *testing.T) { | |||
|
|||
// TestScorePlugin tests invocation of score plugins. | |||
func TestScorePlugin(t *testing.T) { | |||
// Create a plugin registry for testing. Register only a score plugin. | |||
scPlugin := &ScorePlugin{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not your fault, but I dislike those short plugin names "scPlugin" etc. not descriptive and confusing, perhaps a followup cleanup PR to rename all of them properly, like s/scPlugin/scorePlugin, s/perPlugin/permitPlugin etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also addressed in this PR. PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, could you please squash the commits
func NewScorePlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { | ||
return scPlugin, nil | ||
// newScorePlugin returns a factory for score plugin with specified ScorePlugin. | ||
func newScorePlugin(scorePlugin *ScorePlugin) framework.PluginFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simply compose a generic newPlugin
:
func newPlugin(plugin framework.Plugin) framework.PluginFactory {
return func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) {
return plugin, nil
}
}
And remove all newXYZPlugin()
b/c all callers can just pass in specific plugin struct as a plugin interface obj.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed. If we need a more specific newXXXPlugin, we could add it later.
Thanks @hex108. Please squash the commits and then it'd good to /approve. |
… do some other refactor
@Huang-Wei Addressed :) The failed test is not related. |
/lgtm Thanks, @hex108 ! |
@Huang-Wei Thanks! It seems there is something wrong with the /approve |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahg-g, hex108, 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 |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Refactor NewXXXPlugin to avoid package variables to avoid race conditions. It is a follow-up for #81328.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
/sig scheduling