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

unable to expand resource shortcut for resource provided by extension apiserver #1365

Open
Diaphteiros opened this issue Jul 12, 2024 · 0 comments

Comments

@Diaphteiros
Copy link

Diaphteiros commented Jul 12, 2024

I'm trying to write a kubectl-style CLI tool for improving my ops activities. I'm working with a k8s cluster that runs the Gardener extension apiserver, which - among others - provides the shoots resource (api group core.gardener.cloud, version v1beta1).

I create a new shortcut expander by using NewShortcutExpander and then call KindFor(schema.GroupVersionResource{Resource: myResource}) to resolve the shortcut in myResource.
For resources provided by CRDs, the shortcut resolution works fine, but if I try to resolve shoot, I eventually end up here.

At this point, the resource variable contains what I initially put into the KindFor method, which looks like this:

{
  Group: ""
  Version: ""
  Resource: "shoot"
}

The content of the apiRes variable in the loop looks like this

{
  Name: "shoots"
  SingularName: "shoot"
  Namespaced: true
  Group: ""
  Version: ""
  Kind: "Shoot"
}

while the gv variable of the loop holds the correct group/version information:

{
  Group: "core.gardener.cloud"
  Version: "v1beta1"
}

However, in the linked code line, resource is returned, which contains only the resource name and no group or version. This is then fed into the rest mapper, which will never succeed with an empty group.

What I'm confused about is that in the mentioned code line, all required information is there. Shouldn't this part look like this instead?

if resource.Resource == apiRes.Name || resource.Resource == apiRes.SingularName {
  resource.Group = gv.Group
  resource.Version = gv.Version
  return resource
}

Is it ever correct/useful to return the unmodified value of resource?

Or am I using the shortcut expander wrongly here?

What I'm effectively trying to do is to resolve shoot from a CLI like myCLI get shoot foo -n bar to Group: core.gardener.cloud, Version: v1beta1, Kind: Shoot.

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

No branches or pull requests

1 participant