MCPcopy
hub / github.com/kubernetes/client-go / ScaleForResource

Method ScaleForResource

scale/util.go:63–88  ·  view source on GitHub ↗
(inputRes schema.GroupVersionResource)

Source from the content-addressed store, hash-verified

61}
62
63func (r *discoveryScaleResolver) ScaleForResource(inputRes schema.GroupVersionResource) (scaleVersion schema.GroupVersionKind, err error) {
64 groupVerResources, err := r.discoveryClient.ServerResourcesForGroupVersion(inputRes.GroupVersion().String())
65 if err != nil {
66 return schema.GroupVersionKind{}, fmt.Errorf("unable to fetch discovery information for %s: %v", inputRes.String(), err)
67 }
68
69 for _, resource := range groupVerResources.APIResources {
70 resourceParts := strings.SplitN(resource.Name, "/", 2)
71 if len(resourceParts) != 2 || resourceParts[0] != inputRes.Resource || resourceParts[1] != "scale" {
72 // skip non-scale resources, or scales for resources that we're not looking for
73 continue
74 }
75
76 scaleGV := inputRes.GroupVersion()
77 if resource.Group != "" && resource.Version != "" {
78 scaleGV = schema.GroupVersion{
79 Group: resource.Group,
80 Version: resource.Version,
81 }
82 }
83
84 return scaleGV.WithKind(resource.Kind), nil
85 }
86
87 return schema.GroupVersionKind{}, fmt.Errorf("could not find scale subresource for %s in discovery information", inputRes.String())
88}
89
90// cachedScaleKindResolver is a ScaleKindResolver that caches results
91// from another ScaleKindResolver, re-fetching on cache misses.

Callers

nothing calls this directly

Calls 3

StringMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected