mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
apimachinery: rename meta.{ -> UnsafeGuess}KindToResource
This commit is contained in:
parent
20df61009d
commit
b0b711119b
@ -34,7 +34,7 @@ func (c *scales) Get(kind string, name string) (result *v1beta1.Scale, err error
|
|||||||
|
|
||||||
// TODO this method needs to take a proper unambiguous kind
|
// TODO this method needs to take a proper unambiguous kind
|
||||||
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
||||||
resource, _ := meta.KindToResource(fullyQualifiedKind)
|
resource, _ := meta.UnsafeGuessKindToResource(fullyQualifiedKind)
|
||||||
|
|
||||||
err = c.client.Get().
|
err = c.client.Get().
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
@ -51,7 +51,7 @@ func (c *scales) Update(kind string, scale *v1beta1.Scale) (result *v1beta1.Scal
|
|||||||
|
|
||||||
// TODO this method needs to take a proper unambiguous kind
|
// TODO this method needs to take a proper unambiguous kind
|
||||||
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
||||||
resource, _ := meta.KindToResource(fullyQualifiedKind)
|
resource, _ := meta.UnsafeGuessKindToResource(fullyQualifiedKind)
|
||||||
|
|
||||||
err = c.client.Put().
|
err = c.client.Put().
|
||||||
Namespace(scale.Namespace).
|
Namespace(scale.Namespace).
|
||||||
|
@ -34,7 +34,7 @@ func (c *scales) Get(kind string, name string) (result *extensions.Scale, err er
|
|||||||
|
|
||||||
// TODO this method needs to take a proper unambiguous kind
|
// TODO this method needs to take a proper unambiguous kind
|
||||||
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
||||||
resource, _ := meta.KindToResource(fullyQualifiedKind)
|
resource, _ := meta.UnsafeGuessKindToResource(fullyQualifiedKind)
|
||||||
|
|
||||||
err = c.client.Get().
|
err = c.client.Get().
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
@ -51,7 +51,7 @@ func (c *scales) Update(kind string, scale *extensions.Scale) (result *extension
|
|||||||
|
|
||||||
// TODO this method needs to take a proper unambiguous kind
|
// TODO this method needs to take a proper unambiguous kind
|
||||||
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
||||||
resource, _ := meta.KindToResource(fullyQualifiedKind)
|
resource, _ := meta.UnsafeGuessKindToResource(fullyQualifiedKind)
|
||||||
|
|
||||||
err = c.client.Put().
|
err = c.client.Put().
|
||||||
Namespace(scale.Namespace).
|
Namespace(scale.Namespace).
|
||||||
|
4
pkg/master/thirdparty/thirdparty.go
vendored
4
pkg/master/thirdparty/thirdparty.go
vendored
@ -110,7 +110,7 @@ func (m *ThirdPartyResourceServer) HasThirdPartyResource(rsrc *extensions.ThirdP
|
|||||||
if entry == nil {
|
if entry == nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
plural, _ := meta.KindToResource(schema.GroupVersionKind{
|
plural, _ := meta.UnsafeGuessKindToResource(schema.GroupVersionKind{
|
||||||
Group: group,
|
Group: group,
|
||||||
Version: rsrc.Versions[0].Name,
|
Version: rsrc.Versions[0].Name,
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
@ -258,7 +258,7 @@ func (m *ThirdPartyResourceServer) InstallThirdPartyResource(rsrc *extensions.Th
|
|||||||
if len(rsrc.Versions) == 0 {
|
if len(rsrc.Versions) == 0 {
|
||||||
return fmt.Errorf("ThirdPartyResource %s has no defined versions", rsrc.Name)
|
return fmt.Errorf("ThirdPartyResource %s has no defined versions", rsrc.Name)
|
||||||
}
|
}
|
||||||
plural, _ := meta.KindToResource(schema.GroupVersionKind{
|
plural, _ := meta.UnsafeGuessKindToResource(schema.GroupVersionKind{
|
||||||
Group: group,
|
Group: group,
|
||||||
Version: rsrc.Versions[0].Name,
|
Version: rsrc.Versions[0].Name,
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
|
@ -74,7 +74,7 @@ type thirdPartyResourceDataMapper struct {
|
|||||||
var _ meta.RESTMapper = &thirdPartyResourceDataMapper{}
|
var _ meta.RESTMapper = &thirdPartyResourceDataMapper{}
|
||||||
|
|
||||||
func (t *thirdPartyResourceDataMapper) getResource() schema.GroupVersionResource {
|
func (t *thirdPartyResourceDataMapper) getResource() schema.GroupVersionResource {
|
||||||
plural, _ := meta.KindToResource(t.getKind())
|
plural, _ := meta.UnsafeGuessKindToResource(t.getKind())
|
||||||
|
|
||||||
return plural
|
return plural
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ func NewDefaultRESTMapper(defaultGroupVersions []schema.GroupVersion, f VersionI
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *DefaultRESTMapper) Add(kind schema.GroupVersionKind, scope RESTScope) {
|
func (m *DefaultRESTMapper) Add(kind schema.GroupVersionKind, scope RESTScope) {
|
||||||
plural, singular := KindToResource(kind)
|
plural, singular := UnsafeGuessKindToResource(kind)
|
||||||
|
|
||||||
m.singularToPlural[singular] = plural
|
m.singularToPlural[singular] = plural
|
||||||
m.pluralToSingular[plural] = singular
|
m.pluralToSingular[plural] = singular
|
||||||
@ -136,10 +136,10 @@ var unpluralizedSuffixes = []string{
|
|||||||
"endpoints",
|
"endpoints",
|
||||||
}
|
}
|
||||||
|
|
||||||
// KindToResource converts Kind to a resource name.
|
// UnsafeGuessKindToResource converts Kind to a resource name.
|
||||||
// Broken. This method only "sort of" works when used outside of this package. It assumes that Kinds and Resources match
|
// Broken. This method only "sort of" works when used outside of this package. It assumes that Kinds and Resources match
|
||||||
// and they aren't guaranteed to do so.
|
// and they aren't guaranteed to do so.
|
||||||
func KindToResource(kind schema.GroupVersionKind) ( /*plural*/ schema.GroupVersionResource /*singular*/, schema.GroupVersionResource) {
|
func UnsafeGuessKindToResource(kind schema.GroupVersionKind) ( /*plural*/ schema.GroupVersionResource /*singular*/, schema.GroupVersionResource) {
|
||||||
kindName := kind.Kind
|
kindName := kind.Kind
|
||||||
if len(kindName) == 0 {
|
if len(kindName) == 0 {
|
||||||
return schema.GroupVersionResource{}, schema.GroupVersionResource{}
|
return schema.GroupVersionResource{}, schema.GroupVersionResource{}
|
||||||
|
@ -485,7 +485,7 @@ func TestKindToResource(t *testing.T) {
|
|||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
version := schema.GroupVersion{}
|
version := schema.GroupVersion{}
|
||||||
|
|
||||||
plural, singular := KindToResource(version.WithKind(testCase.Kind))
|
plural, singular := UnsafeGuessKindToResource(version.WithKind(testCase.Kind))
|
||||||
if singular != version.WithResource(testCase.Singular) || plural != version.WithResource(testCase.Plural) {
|
if singular != version.WithResource(testCase.Singular) || plural != version.WithResource(testCase.Plural) {
|
||||||
t.Errorf("%d: unexpected plural and singular: %v %v", i, plural, singular)
|
t.Errorf("%d: unexpected plural and singular: %v %v", i, plural, singular)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func (c *scales) Get(kind string, name string) (result *v1beta1.Scale, err error
|
|||||||
|
|
||||||
// TODO this method needs to take a proper unambiguous kind
|
// TODO this method needs to take a proper unambiguous kind
|
||||||
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
||||||
resource, _ := meta.KindToResource(fullyQualifiedKind)
|
resource, _ := meta.UnsafeGuessKindToResource(fullyQualifiedKind)
|
||||||
|
|
||||||
err = c.client.Get().
|
err = c.client.Get().
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
@ -51,7 +51,7 @@ func (c *scales) Update(kind string, scale *v1beta1.Scale) (result *v1beta1.Scal
|
|||||||
|
|
||||||
// TODO this method needs to take a proper unambiguous kind
|
// TODO this method needs to take a proper unambiguous kind
|
||||||
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
|
||||||
resource, _ := meta.KindToResource(fullyQualifiedKind)
|
resource, _ := meta.UnsafeGuessKindToResource(fullyQualifiedKind)
|
||||||
|
|
||||||
err = c.client.Put().
|
err = c.client.Put().
|
||||||
Namespace(scale.Namespace).
|
Namespace(scale.Namespace).
|
||||||
|
Loading…
Reference in New Issue
Block a user