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

enable case-insensitivity in kind field #21

Merged
merged 1 commit into from
Sep 29, 2018
Merged

Conversation

liftedkilt
Copy link
Contributor

This addresses one of the concerns presented in #4

Referencing https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#naming-conventions, it appears safe to assume that all values of type "Kind" will have an initial uppercase character.

@hausdorff
Copy link
Contributor

Wow, thanks for the PR!

This is a super good idea, and we should definitely do it, but I think client-go exposes its kind aliasing, which would allow us to write po instead of Pod, deploy instead of Deployment, svc instead of Service, and so on. Let me see if I can dig it up, and if I can, then we might consider going that route....

@liftedkilt
Copy link
Contributor Author

Thanks for the tip - I'll poke at client-go in a little bit and see what I can find.

@hausdorff
Copy link
Contributor

Hmm, let's just merge this since it's a clear improvment, and my suggestion looks like it will not be trivial. To do this "the right way (TM)" I believe we have to:

  1. Get the OpenAPI spec from the API server.
  2. Parse out the apiextensions and apiversions
  3. Loop through all the kinds, assembling a big map of alias -> kind, provided by the specification
  4. Finally, take the argument the user has given us, and look it up in the alias dictionary.

In the mean time I personally rather just hard-code the aliases for the core kinds and wait for someone to complain about the lack of aliases for CRDs. :)

@liftedkilt
Copy link
Contributor Author

in client-go/discovery/restmapper.go, there are two helper functions:

// KindFor takes a partial resource and returns back the single match.
// It returns an error if there are multiple matches.
func (d *DeferredDiscoveryRESTMapper) KindFor(resource schema.GroupVersionResource) (gvk schema.GroupVersionKind, err error) {
	del, err := d.getDelegate()
	if err != nil {
		return schema.GroupVersionKind{}, err
	}
	gvk, err = del.KindFor(resource)
	if err != nil && !d.cl.Fresh() {
		d.Reset()
		gvk, err = d.KindFor(resource)
	}
	return
}

// KindsFor takes a partial resource and returns back the list of
// potential kinds in priority order.
func (d *DeferredDiscoveryRESTMapper) KindsFor(resource schema.GroupVersionResource) (gvks []schema.GroupVersionKind, err error) {
	del, err := d.getDelegate()
	if err != nil {
		return nil, err
	}
	gvks, err = del.KindsFor(resource)
	if len(gvks) == 0 && !d.cl.Fresh() {
		d.Reset()
		gvks, err = d.KindsFor(resource)
	}
	return
}

That makes it look like you can pass a partial kind to those functions, it will query a running instance of API server to get the mappings of kinds to shortnames, and then it will validate it? At least that was as best as I could get a handle on what was going on...kubernetes internal code is such a giant ball of spaghetti - interfaces everywhere!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants