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

scheduler/volumebinding: migrate to use pkg/scheduler/framework/plugins/feature #103493

Merged
merged 1 commit into from
Sep 13, 2021

Conversation

cofyc
Copy link
Member

@cofyc cofyc commented Jul 5, 2021

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?

NONE

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


@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 5, 2021
@k8s-ci-robot
Copy link
Contributor

@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 triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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 needs-triage Indicates an issue or PR lacks a `triage/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. sig/storage Categorizes an issue or PR as relevant to SIG Storage. release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. 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 Jul 5, 2021
@cofyc
Copy link
Member Author

cofyc commented Jul 5, 2021

/assign @Huang-Wei
this is based on #100003, I'll rebase after #100003 is merged.

@Huang-Wei
Copy link
Member

this is based on #100003, I'll rebase after #100003 is merged.

Thanks, I just approved #100003.

@cofyc
Copy link
Member Author

cofyc commented Jul 6, 2021

/skip
/retest

@@ -660,7 +661,11 @@ func TestVolumeBinding(t *testing.T) {
}
}

pl, err := New(args, fh)
fts := feature.Features{
EnableVolumeCapacityPriority: utilfeature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority),
Copy link
Member

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.

Copy link
Member Author

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

@k8s-ci-robot k8s-ci-robot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Jul 8, 2021
@fejta-bot
Copy link

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.

@cofyc
Copy link
Member Author

cofyc commented Jul 8, 2021

/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"
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

@cofyc
Copy link
Member Author

cofyc commented Jul 9, 2021

/assign alculquicondor

@cofyc
Copy link
Member Author

cofyc commented Jul 9, 2021

/retest

1 similar comment
@cofyc
Copy link
Member Author

cofyc commented Jul 9, 2021

/retest

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 13, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 23, 2021
@@ -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 {
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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()).

Copy link
Member

@alculquicondor alculquicondor left a 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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 10, 2021
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 11, 2021
@Huang-Wei
Copy link
Member

/approve

@Huang-Wei
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 13, 2021
@k8s-ci-robot
Copy link
Contributor

[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 /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 Sep 13, 2021
@k8s-ci-robot k8s-ci-robot merged commit c6dfe73 into kubernetes:master Sep 13, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Sep 13, 2021
@cofyc cofyc deleted the fix103431 branch October 5, 2021 05:53
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/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. 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. sig/storage Categorizes an issue or PR as relevant to SIG Storage. 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.

scheduler/volumebinding: migrate to use pkg/scheduler/framework/plugins/feature
5 participants