-
Notifications
You must be signed in to change notification settings - Fork 298
fix: Only consider resources which supports appropriate verb for any given operation #423
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,14 +172,19 @@ func IsCRD(obj *unstructured.Unstructured) bool { | |
| return IsCRDGroupVersionKind(obj.GroupVersionKind()) | ||
| } | ||
|
|
||
| // ServerResourceForGroupVersionKind looks up and returns the API resource from | ||
| // the server for a given GVK scheme. If verb is set to the non-empty string, | ||
| // it will return the API resource which supports the verb. There are some edge | ||
| // cases, where the same GVK is represented by more than one API. | ||
| // | ||
| // See: https://github.com/ksonnet/ksonnet/blob/master/utils/client.go | ||
| func ServerResourceForGroupVersionKind(disco discovery.DiscoveryInterface, gvk schema.GroupVersionKind) (*metav1.APIResource, error) { | ||
| func ServerResourceForGroupVersionKind(disco discovery.DiscoveryInterface, gvk schema.GroupVersionKind, verb string) (*metav1.APIResource, error) { | ||
| resources, err := disco.ServerResourcesForGroupVersion(gvk.GroupVersion().String()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| for _, r := range resources.APIResources { | ||
| if r.Kind == gvk.Kind { | ||
| if r.Kind == gvk.Kind && isSupportedVerb(&r, verb) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if users will ever run into a misleading message where we report
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually agree with this comment, @jessesuen. Edge case or not, I'm going to fix this.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the logic to return Also, added some unit tests around all that. |
||
| return &r, nil | ||
| } | ||
| } | ||
|
|
||
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.
Is this something that can happen? As far as I can tell, all instances of the argument are hard-coded as values others than these two.
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.
Good question. This is intended to allow the caller to just say "I don't care about the support verbs, just resolve it". It might be a valid use-case for some.