本文整理汇总了Golang中k8s/io/kubernetes/pkg/api/meta.RESTMapper.KindsFor方法的典型用法代码示例。如果您正苦于以下问题:Golang RESTMapper.KindsFor方法的具体用法?Golang RESTMapper.KindsFor怎么用?Golang RESTMapper.KindsFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/api/meta.RESTMapper
的用法示例。
在下文中一共展示了RESTMapper.KindsFor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FindAllCanonicalResources
// FindAllCanonicalResources returns all resource names that map directly to their kind (Kind -> Resource -> Kind)
// and are not subresources. This is the closest mapping possible from the client side to resources that can be
// listed and updated. Note that this may return some virtual resources (like imagestreamtags) that can be otherwise
// represented.
// TODO: add a field to APIResources for "virtual" (or that points to the canonical resource).
// TODO: fallback to the scheme when discovery is not possible.
func FindAllCanonicalResources(d discovery.DiscoveryInterface, m meta.RESTMapper) ([]unversioned.GroupResource, error) {
set := make(map[unversioned.GroupResource]struct{})
all, err := d.ServerResources()
if err != nil {
return nil, err
}
for apiVersion, v := range all {
gv, err := unversioned.ParseGroupVersion(apiVersion)
if err != nil {
continue
}
for _, r := range v.APIResources {
// ignore subresources
if strings.Contains(r.Name, "/") {
continue
}
// because discovery info doesn't tell us whether the object is virtual or not, perform a lookup
// by the kind for resource (which should be the canonical resource) and then verify that the reverse
// lookup (KindsFor) does not error.
if mapping, err := m.RESTMapping(unversioned.GroupKind{Group: gv.Group, Kind: r.Kind}, gv.Version); err == nil {
if _, err := m.KindsFor(mapping.GroupVersionKind.GroupVersion().WithResource(mapping.Resource)); err == nil {
set[unversioned.GroupResource{Group: mapping.GroupVersionKind.Group, Resource: mapping.Resource}] = struct{}{}
}
}
}
}
var groupResources []unversioned.GroupResource
for k := range set {
groupResources = append(groupResources, k)
}
sort.Sort(groupResourcesByName(groupResources))
return groupResources, nil
}