Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Delegate GroupVersion parsing to schema.ParseGroupVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Feb 26, 2019
1 parent 93bccbf commit 1d86d57
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions cluster/kubernetes/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,12 @@ func (c *Cluster) getResourcesBySelector(selector string) (map[string]*kuberesou
continue
}

namespaced := apiResource.Namespaced

// get group and version
var group, version string
groupVersion := resource.GroupVersion
if strings.Contains(groupVersion, "/") {
a := strings.SplitN(groupVersion, "/", 2)
group = a[0]
version = a[1]
} else {
group = ""
version = groupVersion
groupVersion, err := schema.ParseGroupVersion(resource.GroupVersion)
if err != nil {
return nil, err
}

resourceClient := c.client.dynamicClient.Resource(schema.GroupVersionResource{
Group: group,
Version: version,
Resource: apiResource.Name,
})
resourceClient := c.client.dynamicClient.Resource(groupVersion.WithResource(apiResource.Name))
data, err := resourceClient.List(listOptions)
if err != nil {
return nil, err
Expand All @@ -238,7 +225,7 @@ func (c *Cluster) getResourcesBySelector(selector string) (map[string]*kuberesou
}
// TODO(michael) also exclude anything that has an ownerReference (that isn't "standard"?)

res := &kuberesource{obj: &data.Items[i], namespaced: namespaced}
res := &kuberesource{obj: &data.Items[i], namespaced: apiResource.Namespaced}
result[res.ResourceID().String()] = res
}
}
Expand Down

0 comments on commit 1d86d57

Please sign in to comment.