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

Allow to specify categories for custom resources #59561

Merged

Conversation

nikhita
Copy link
Member

@nikhita nikhita commented Feb 8, 2018

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:

Custom resources can be listed with a set of grouped resources (category) by specifying the categories in the CustomResourceDefinition spec. Example: They can be used with `kubectl get all`, where `all` is a category.

/cc sttts liggitt deads2k

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 8, 2018

// Categories implements the CategoriesProvider interface. Returns a list of categories a resource is part of.
func (r *REST) Categories() []string {
return []string{"all"}
Copy link
Contributor

@sttts sttts Feb 8, 2018

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.

Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Member

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"}
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

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

@nikhita nikhita mentioned this pull request Feb 9, 2018
54 tasks
@nikhita nikhita force-pushed the customresources-kubectl-get-all branch from e36f1c8 to 8d2b8e1 Compare February 11, 2018 22:15
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 11, 2018
@nikhita nikhita changed the title apiextensions: implement CategoriesProvider [WIP] Allow to specify categories for custom resources Feb 12, 2018
@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 Feb 12, 2018
@@ -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
Copy link
Member

@liggitt liggitt Feb 12, 2018

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?

Copy link
Member Author

@nikhita nikhita Feb 12, 2018

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?

Copy link
Member Author

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, ",")))
}

Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

@nikhita nikhita force-pushed the customresources-kubectl-get-all branch 2 times, most recently from 4f00c4c to 0bf0507 Compare February 12, 2018 21:24
@nikhita
Copy link
Member Author

nikhita commented Feb 12, 2018

To confirm - do we need a feature gate for this? Technically, it is an alpha field in an already beta API...

@nikhita
Copy link
Member Author

nikhita commented Feb 13, 2018

/kind api-change

@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 Feb 13, 2018
@sttts
Copy link
Contributor

sttts commented Feb 19, 2018

Needs a release note.

@nikhita nikhita changed the title [WIP] Allow to specify categories for custom resources Allow to specify categories for custom resources Feb 19, 2018
@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 Feb 19, 2018
@sttts
Copy link
Contributor

sttts commented Feb 19, 2018

do we need a feature gate for this? Technically, it is an alpha field in an already beta API...

I tend to add it as a beta field. This is simple enough IMO.

@deads2k @liggitt opinions?

@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 release-note-none Denotes a PR that doesn't merit a release note. labels Feb 19, 2018
@nikhita
Copy link
Member Author

nikhita commented Feb 19, 2018

Needs a release note.

Added. Ptal.

@deads2k
Copy link
Contributor

deads2k commented Feb 20, 2018

I tend to add it as a beta field. This is simple enough IMO.

I'm fine with it as beta. I also expected it to be near names though.

@nikhita nikhita force-pushed the customresources-kubectl-get-all branch from 0bf0507 to 7f0ec58 Compare February 20, 2018 21:45
}

// WithCategories sets the categories for the resource and returns the RESTStorage object.
func (r *REST) WithCategories(categories []string) *REST {
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed and rebased.

@deads2k
Copy link
Contributor

deads2k commented Feb 22, 2018

/lgtm

/assign @liggitt
@kubernetes/api-approvers

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 22, 2018
@nikhita nikhita force-pushed the customresources-kubectl-get-all branch from 7f0ec58 to 957751a Compare February 23, 2018 04:58
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 23, 2018
@nikhita nikhita force-pushed the customresources-kubectl-get-all branch from 957751a to 8b02c95 Compare February 23, 2018 05:24
@@ -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...)
Copy link
Member

@liggitt liggitt Feb 23, 2018

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed.

@nikhita nikhita force-pushed the customresources-kubectl-get-all branch from 8b02c95 to 53452ab Compare February 23, 2018 16:36
@liggitt
Copy link
Member

liggitt commented Feb 23, 2018

code looks good. I expected a test exercising the function (ensuring a specified category makes it through to the discovery doc)

@nikhita nikhita force-pushed the customresources-kubectl-get-all branch from 53452ab to 7ac2b3c Compare February 23, 2018 16:58
We can group custom resources into categories i.e.
use them with kubectl get all.
@nikhita
Copy link
Member Author

nikhita commented Feb 23, 2018

I expected a test exercising the function (ensuring a specified category makes it through to the discovery doc)

Added.

Also added a unit test.

@liggitt
Copy link
Member

liggitt commented Feb 23, 2018

/lgtm

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

[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 /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 Feb 23, 2018
@k8s-github-robot
Copy link

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.

@k8s-github-robot k8s-github-robot merged commit 8d406bf into kubernetes:master Feb 23, 2018
@nikhita nikhita deleted the customresources-kubectl-get-all branch February 23, 2018 22:03
@bgrant0607
Copy link
Member

Do we plan to add categories to built-in types?

@sttts
Copy link
Contributor

sttts commented Apr 3, 2018

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?

@bgrant0607
Copy link
Member

@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?

@sttts
Copy link
Contributor

sttts commented Apr 4, 2018

/cc @kubernetes/sig-cli-misc

@k8s-ci-robot k8s-ci-robot added the sig/cli Categorizes an issue or PR as relevant to SIG CLI. label Apr 4, 2018
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 lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. 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.

7 participants