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

pkg/admission/storageclass: pick one storageclass conditionally if >1 present #110559

Merged

Conversation

danishprakash
Copy link
Contributor

@danishprakash danishprakash commented Jun 14, 2022

What this PR does / why we need it:

If there are two StorageClasses, currently we don't pick either of them as the default as part of admission control. This change picks one StorageClass at random.

Which issue(s) this PR fixes:

Fixes #110514

Signed-off-by: danishprakash grafitykoncept@gmail.com

Does this PR introduce a user-facing change?

Admission control plugin "DefaultStorageClass": If more than one StorageClass is designated as default (via the "storageclass.kubernetes.io/is-default-class" annotation), choose the newest one instead of throwing an error.

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 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-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 14, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @danishprakash. Thanks for your PR.

I'm waiting for a kubernetes 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 k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 14, 2022
Comment on lines 146 to 147
rand.Seed(time.Now().UnixNano())
return defaultClasses[rand.Intn(len(defaultClasses))], 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.

@thockin I've used rand here for starters, but is there a heuristic we have in mind that we can employ here. I'm open to suggestions, thanks.

Copy link
Member

@aojea aojea Jun 19, 2022

Choose a reason for hiding this comment

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

Tim should we not have to be consistent in a multimaster deployment?
If we have 2 or more apiservers, I think that all of them should pick the same default

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 that sorting it alphabetically and returning the first one will make it

Copy link
Member

Choose a reason for hiding this comment

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

Why not sort by CreationTimestamp and choose the newest one (on the assumption that this situation USUALLY means someone is adding a new one and removing an old one)?

@danishprakash danishprakash changed the title pkg/admission/storageclass: pick random storageclass if >1 present [wip] pkg/admission/storageclass: pick random storageclass if >1 present Jun 14, 2022
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 14, 2022
@danishprakash danishprakash marked this pull request as draft June 14, 2022 05:27
@danishprakash danishprakash changed the title [wip] pkg/admission/storageclass: pick random storageclass if >1 present pkg/admission/storageclass: pick random storageclass if >1 present Jun 14, 2022
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 19, 2022
@danishprakash danishprakash marked this pull request as ready for review June 19, 2022 14:24
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 19, 2022
@@ -170,7 +170,7 @@ func TestAdmission(t *testing.T) {
"two defaults, error with PVC with class=nil",
[]*storagev1.StorageClass{defaultClass1, defaultClass2, classWithFalseDefault, classWithNoDefault, classWithEmptyDefault},
claimWithNoClass,
true,
false,
Copy link
Member

Choose a reason for hiding this comment

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

How about a testcase for multiple defaults?

@thockin
Copy link
Member

thockin commented Jul 12, 2022

The IngressClass PR was approved

@danishprakash
Copy link
Contributor Author

I'll update this today, thanks for the heads up.

@thockin thockin added the sig/storage Categorizes an issue or PR as relevant to SIG Storage. label Jul 15, 2022
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jul 15, 2022
@thockin thockin added the kind/feature Categorizes issue or PR as related to a new feature. label Jul 15, 2022
@k8s-ci-robot k8s-ci-robot added the sig/apps Categorizes an issue or PR as relevant to SIG Apps. label Aug 4, 2022
@jsafrane
Copy link
Member

/approve
from storage POV
@thockin PTAL

@danishprakash please add a release note in the first comment of this PR, this is user-facing change.
See https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md#does-my-pull-request-need-a-release-note for details.

@danishprakash danishprakash changed the title pkg/admission/storageclass: pick random storageclass if >1 present pkg/admission/storageclass: pick one storageclass conditionally if >1 present Aug 11, 2022
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed 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 Aug 29, 2022
@jsafrane
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 Aug 29, 2022
if len(defaultClasses) > 1 {
klog.V(4).Infof("GetDefaultClass %d defaults found", len(defaultClasses))
return nil, errors.NewInternalError(fmt.Errorf("%d default StorageClasses were found", len(defaultClasses)))
klog.V(4).Infof("%d default StorageClasses were found, choosing the newest: %s", len(defaultClasses), defaultClasses[0].Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Also put in release note (and maybe the PR description) that the newest is preferred?

Should we document this in the API?

Copy link
Member

Choose a reason for hiding this comment

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

Strictly speaking this is optional and not part of the API :)

@thockin
Copy link
Member

thockin commented Oct 18, 2022

ping, I 'd love to approve this

Signed-off-by: danishprakash <grafitykoncept@gmail.com>
Signed-off-by: danishprakash <grafitykoncept@gmail.com>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 19, 2022
@thockin
Copy link
Member

thockin commented Oct 19, 2022

I updated the relnote a bit.

/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 Oct 19, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danishprakash, jsafrane, thockin

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

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/feature Categorizes issue or PR as related to a new feature. 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/apps Categorizes an issue or PR as relevant to SIG Apps. 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. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Having two Default StorageClasses should be handled better
7 participants