-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Allow to specify categories for custom resources #59561
Allow to specify categories for custom resources #59561
Conversation
|
||
// Categories implements the CategoriesProvider interface. Returns a list of categories a resource is part of. | ||
func (r *REST) Categories() []string { | ||
return []string{"all"} |
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 sure we really want that. The resources in all
are manually curated because we don't want to see certain resources in there that are internal and not relevant for a user.
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.
Yeah, we don't really want this here. I could see allowing a user to specify their categories.
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 could see allowing a user to specify their categories.
Maybe as another field in the CRD spec (?)
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.
Exactly
|
||
// Categories implements the CategoriesProvider interface. Returns a list of categories a resource is part of. | ||
func (r *REST) Categories() []string { | ||
return []string{"all"} |
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.
all
is for user facing resources. CRDs are highly privileged. They don't belong in the all list.
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.
Right, came across https://github.com/kubernetes/community/blob/master/contributors/devel/kubectl-conventions.md#rules-for-extending-special-resource-alias---all now. 👍
/cc @liggitt since you mentioned about this on slack.
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.
@deads2k: I could see allowing a user to specify their categories.
that is what I meant
e36f1c8
to
8d2b8e1
Compare
@@ -30,6 +30,8 @@ type CustomResourceDefinitionSpec struct { | |||
Scope ResourceScope | |||
// Validation describes the validation methods for CustomResources | |||
Validation *CustomResourceValidation | |||
// Categories is a list of grouped resources custom resources belong to (e.g. 'all') | |||
Categories []string |
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 expected this next to ShortNames
, is there a reason not to put it there?
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 expected this next to ShortNames, is there a reason not to put it there?
My first instinct was to include it next to ShortNames as well.
However, CustomResourceDefinitionNames
is unique to the CRD and is used in the naming_controller
too. Categories
can be the same across CRDs and we don't really need to include it in the naming_controller
. So I thought we could include it as a field in the CRD Spec...
Putting it in CustomResourceDefinitionNames
should also be fine. @liggitt Wdyt?
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.
Done.
@@ -158,7 +158,6 @@ func ValidateCustomResourceDefinitionNames(names *apiextensions.CustomResourceDe | |||
if errs := validationutil.IsDNS1035Label(shortName); len(errs) > 0 { | |||
allErrs = append(allErrs, field.Invalid(fldPath.Child("shortNames").Index(i), shortName, strings.Join(errs, ","))) | |||
} | |||
|
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.
need to validate categories (probably the same validation we apply to shortnames)
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.
Added.
4f00c4c
to
0bf0507
Compare
To confirm - do we need a feature gate for this? Technically, it is an alpha field in an already beta API... |
/kind api-change |
Needs a release note. |
Added. Ptal. |
I'm fine with it as beta. I also expected it to be near names though. |
0bf0507
to
7f0ec58
Compare
} | ||
|
||
// WithCategories sets the categories for the resource and returns the RESTStorage object. | ||
func (r *REST) WithCategories(categories []string) *REST { |
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 don't think you need this
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.
Removed and rebased.
/lgtm /assign @liggitt |
7f0ec58
to
957751a
Compare
957751a
to
8b02c95
Compare
@@ -111,6 +111,7 @@ func (c *NamingConditionController) getAcceptedNamesForGroup(group string) (allR | |||
|
|||
allKinds.Insert(item.Status.AcceptedNames.Kind) | |||
allKinds.Insert(item.Status.AcceptedNames.ListKind) | |||
allKinds.Insert(item.Status.AcceptedNames.Categories...) |
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.
categories are not kinds... why are we adding them here? multiple CRDs can share the same categories... no duplicate checking is required
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.
Removed.
8b02c95
to
53452ab
Compare
code looks good. I expected a test exercising the function (ensuring a specified category makes it through to the discovery doc) |
53452ab
to
7ac2b3c
Compare
We can group custom resources into categories i.e. use them with kubectl get all.
Added. Also added a unit test. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, liggitt, nikhita 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 |
Automatic merge from submit-queue (batch tested with PRs 60302, 57921, 59042, 60126, 59561). If you want to cherry-pick this change to another branch, please follow the instructions here. |
Do we plan to add categories to built-in types? |
Technically we can (for quite some time already): https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/registry/rest/rest.go#L76 Are you asking for more categories by default? |
@sttts No, I'm not asking for more default categories. I'm trying to figure out why we need categories. "all" (which is misleading) is the only default category? This is just intended for CLI shortcuts similar to resource-type short names? |
/cc @kubernetes/sig-cli-misc |
Allow to specify categories for custom resources so that we can get it working with
kubectl get all
.Adds a new field
Categories
in the CRD spec.Release note:
/cc sttts liggitt deads2k