Skip to content

Commit

Permalink
Fetch only server resources for a specific groupVersion, not all grou…
Browse files Browse the repository at this point in the history
…ps to detect isNamespaced (#1423)

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
  • Loading branch information
ANeumann82 committed Mar 13, 2020
1 parent 5f92571 commit 492bcdc
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pkg/engine/resource/object_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ func IsNamespacedObject(r runtime.Object, di discovery.DiscoveryInterface) (bool
// discovery client to fetch all API resources (with Groups and Versions), searches for a resource with the passed GVK
// and returns true if it's namespaced. Method returns an error if passed GVK wasn't found in the discovered resource list.
func isNamespaced(gvk schema.GroupVersionKind, di discovery.DiscoveryInterface) (bool, error) {
// Fetch namespaced API resources
_, apiResources, err := di.ServerGroupsAndResources()
resList, err := di.ServerResourcesForGroupVersion(gvk.GroupVersion().String())

if err != nil {
return false, fmt.Errorf("failed to fetch server groups and resources: %v", err)
return false, fmt.Errorf("failed to fetch server resources for %s: %v", gvk.GroupVersion().String(), err)
}
if resList == nil {
return false, fmt.Errorf("failed to find server resources for %s: %v", gvk.GroupVersion().String(), err)
}

for _, rr := range apiResources {
gv, err := schema.ParseGroupVersion(rr.GroupVersion)
if err != nil {
continue
}
for _, r := range rr.APIResources {
if gvk == gv.WithKind(r.Kind) {
return r.Namespaced, nil
}
//log.Printf("[%s], Name: %s: %v", gvk, r.Name, r.Namespaced)
gv, err := schema.ParseGroupVersion(resList.GroupVersion)
if err != nil {
return false, err
}
for _, r := range resList.APIResources {
if gvk == gv.WithKind(r.Kind) {
return r.Namespaced, nil
}
}

Expand Down

0 comments on commit 492bcdc

Please sign in to comment.