本文整理匯總了Golang中k8s/io/client-go/pkg/runtime/schema.GroupVersion.WithResource方法的典型用法代碼示例。如果您正苦於以下問題:Golang GroupVersion.WithResource方法的具體用法?Golang GroupVersion.WithResource怎麽用?Golang GroupVersion.WithResource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/client-go/pkg/runtime/schema.GroupVersion
的用法示例。
在下文中一共展示了GroupVersion.WithResource方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: serverPreferredResources
// serverPreferredResources returns the supported resources with the version preferred by the
// server. If namespaced is true, only namespaced resources will be returned.
func (d *DiscoveryClient) serverPreferredResources(namespaced bool) ([]schema.GroupVersionResource, error) {
// retry in case the groups supported by the server change after ServerGroup() returns.
const maxRetries = 2
var failedGroups map[schema.GroupVersion]error
var results []schema.GroupVersionResource
var resources map[schema.GroupResource]string
RetrieveGroups:
for i := 0; i < maxRetries; i++ {
results = []schema.GroupVersionResource{}
resources = map[schema.GroupResource]string{}
failedGroups = make(map[schema.GroupVersion]error)
serverGroupList, err := d.ServerGroups()
if err != nil {
return results, err
}
for _, apiGroup := range serverGroupList.Groups {
versions := apiGroup.Versions
for _, version := range versions {
groupVersion := schema.GroupVersion{Group: apiGroup.Name, Version: version.Version}
apiResourceList, err := d.ServerResourcesForGroupVersion(version.GroupVersion)
if err != nil {
if i < maxRetries-1 {
continue RetrieveGroups
}
failedGroups[groupVersion] = err
continue
}
for _, apiResource := range apiResourceList.APIResources {
// ignore the root scoped resources if "namespaced" is true.
if namespaced && !apiResource.Namespaced {
continue
}
if strings.Contains(apiResource.Name, "/") {
continue
}
gvr := groupVersion.WithResource(apiResource.Name)
if _, ok := resources[gvr.GroupResource()]; ok {
if gvr.Version != apiGroup.PreferredVersion.Version {
continue
}
// remove previous entry, because it will be replaced with a preferred one
for i := range results {
if results[i].GroupResource() == gvr.GroupResource() {
results = append(results[:i], results[i+1:]...)
}
}
}
resources[gvr.GroupResource()] = gvr.Version
results = append(results, gvr)
}
}
}
if len(failedGroups) == 0 {
return results, nil
}
}
return results, &ErrGroupDiscoveryFailed{Groups: failedGroups}
}