-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
scheduler/volumebinding: migrate to use pkg/scheduler/framework/plugins/feature #103493
Conversation
@cofyc: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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. |
/assign @Huang-Wei |
/skip |
@@ -660,7 +661,11 @@ func TestVolumeBinding(t *testing.T) { | |||
} | |||
} | |||
|
|||
pl, err := New(args, fh) | |||
fts := feature.Features{ | |||
EnableVolumeCapacityPriority: utilfeature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority), |
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.
instead, change the test cases to have a feature.Features struct. If we are decoupling, there is no reason for the unit tests to depend on the feature gates.
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.
fixed in 1a012fc
because the validation code depends on feature gates, I need to add a new function which we can pass feature.Features
struct
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
/retest |
@@ -29,6 +29,7 @@ import ( | |||
"k8s.io/component-helpers/scheduling/corev1/nodeaffinity" | |||
"k8s.io/kubernetes/pkg/features" | |||
"k8s.io/kubernetes/pkg/scheduler/apis/config" | |||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/feature" |
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.
This is a big no.
A better solution is to have this file define VolumeBindingArgsValidationOptions
. Somewhat similar to this https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api_changes.md#new-enum-value-in-existing-field
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.
updated
/assign alculquicondor |
/retest |
1 similar comment
/retest |
@@ -311,15 +311,27 @@ func ValidateNodeAffinityArgs(path *field.Path, args *config.NodeAffinityArgs) e | |||
return errors.Flatten(errors.NewAggregate(errs)) | |||
} | |||
|
|||
// VolumeBindingArgsValidationOptions contains the different settings for validation. | |||
type VolumeBindingArgsValidationOptions struct { |
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.
What's the motivation for introducing this? If it's to eliminate the dependency on utilfeature
, L322 still depends on it; if not, the old logic that directly checks the feature gate seems more straightforward.
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.
This was inspired by my initial recommendation. There are 2 options:
- Keep the Options but populate it outside of this package.
- Leave the old logic (we probably don't care enough about the dependency). Just don't import
k8s.io/kubernetes/pkg/scheduler/framework/plugins/feature
here.
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.
The 2nd option sounds neat to me.
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.
hi, @Huang-Wei
I'd prefer keeping this option struct. It's required if we want to cut the dependency on the feature gates (typically the global utilfeature.DefaultFeatureGate
). Without this option struct, we need to pass fts.Features
to utilfeature.DefaultFeatureGate
, because we need to call validation function in volumebinding
plugin if the validation function check the features in utilfeature.DefaultFeatureGate
. This will be weird.
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.
The above comment is not for pkg/scheduler/framework/plugins/volumebinding/volume_binding.go - that refactoring is absolutely fine.
My point is it doesn't seem necessary to introduce the option in validation logic. There are no differences in terms of dependency as both depend on utilfeature, isn't it?
So I'd prefer to revert the changes in this file.
diff --git a/pkg/scheduler/apis/config/validation/validation_pluginargs.go b/pkg/scheduler/apis/config/validation/validation_pluginargs.go
index 70fdabe20b1..3202841c579 100644
--- a/pkg/scheduler/apis/config/validation/validation_pluginargs.go
+++ b/pkg/scheduler/apis/config/validation/validation_pluginargs.go
@@ -311,27 +311,15 @@ func ValidateNodeAffinityArgs(path *field.Path, args *config.NodeAffinityArgs) e
return errors.Flatten(errors.NewAggregate(errs))
}
-// VolumeBindingArgsValidationOptions contains the different settings for validation.
-type VolumeBindingArgsValidationOptions struct {
- AllowVolumeCapacityPriority bool
-}
-
// ValidateVolumeBindingArgs validates that VolumeBindingArgs are set correctly.
func ValidateVolumeBindingArgs(path *field.Path, args *config.VolumeBindingArgs) error {
- return ValidateVolumeBindingArgsWithOptions(path, args, VolumeBindingArgsValidationOptions{
- AllowVolumeCapacityPriority: utilfeature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority),
- })
-}
-
-// ValidateVolumeBindingArgs validates that VolumeBindingArgs with scheduler features.
-func ValidateVolumeBindingArgsWithOptions(path *field.Path, args *config.VolumeBindingArgs, opts VolumeBindingArgsValidationOptions) error {
var allErrs field.ErrorList
if args.BindTimeoutSeconds < 0 {
allErrs = append(allErrs, field.Invalid(path.Child("bindTimeoutSeconds"), args.BindTimeoutSeconds, "invalid BindTimeoutSeconds, should not be a negative value"))
}
- if opts.AllowVolumeCapacityPriority {
+ if utilfeature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority) {
allErrs = append(allErrs, validateFunctionShape(args.Shape, path.Child("shape"))...)
} else if args.Shape != nil {
// When the feature is off, return an error if the config is not nil.
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.
The new option struct is introduced because we need to pass the fts.Features
to the validation function. Especially in unit testing, if we don't the test will fail.
However, the fts.Features
is populated from the global utilfeature.DefaultFeatureGate
in kube-scheduler
. This is the place why I think it will be weird.
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.
I think the struct is fine. We could try to get rid of the original ValidateVolumeBindingArgs
as well, but we would need to pass the options to ValidateKubeSchedulerConfiguration
or something like that.
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.
The new option struct is introduced because we need to pass the fts.Features to the validation function. Especially in unit testing, if we don't the test will fail.
That's fair.
We could try to get rid of the original
ValidateVolumeBindingArgs
as well
That sounds great so we don't need to build another options struct - just use plugins/../feature.go#Features
. Also, we would change the validation function signature to func(path, args, options)
and then parse the signature properly. Let's pursue it in a follow-up.
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.
Let's pursue it in a follow-up.
Hmm... it seems we cannot achieve it as the fts
can only be obtained from New(), which happens after validation (Config()).
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
I'll leave the approval to @Huang-Wei
/approve |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cofyc, 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:
fixes #103431
/sig scheduling
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.: