Introduce singularNameProvider for core types

This introduces `singularNameProvider`. This provider will be used
by core types to have their singular names are defined in discovery
endpoint. Thanks to that, core resources singular name always have
higher precedence than CRDs shortcuts or singular names.
This commit is contained in:
Arda Güçlü
2022-11-02 12:53:56 +03:00
parent ab376e09dd
commit 0990ba1cc9
65 changed files with 501 additions and 1 deletions

View File

@@ -79,6 +79,13 @@ func (r *REST) Categories() []string {
return []string{"api-extensions"}
}
var _ rest.SingularNameProvider = &REST{}
// SingularName implements the SingularNameProvider interfaces. This returns singular name of core resource.
func (r *REST) SingularName() string {
return "customresourcedefinition"
}
// Delete adds the CRD finalizer to the list
func (r *REST) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions) (runtime.Object, bool, error) {
obj, err := r.Get(ctx, name, &metav1.GetOptions{})

View File

@@ -1080,6 +1080,9 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
if categoriesProvider, ok := storage.(rest.CategoriesProvider); ok {
apiResource.Categories = categoriesProvider.Categories()
}
if singularNameProvider, ok := storage.(rest.SingularNameProvider); ok {
apiResource.SingularName = singularNameProvider.SingularName()
}
if gvkProvider, ok := storage.(rest.GroupVersionKindProvider); ok {
gvk := gvkProvider.GroupVersionKind(a.group.GroupVersion)
apiResource.Group = gvk.Group

View File

@@ -89,6 +89,12 @@ type CategoriesProvider interface {
Categories() []string
}
// SingularNameProvider returns singular name of resources. This is used by kubectl discovery to have singular
// name representation of resources. In case of shortcut conflicts(with CRD shortcuts) singular name should always map to this resource.
type SingularNameProvider interface {
SingularName() string
}
// GroupVersionKindProvider is used to specify a particular GroupVersionKind to discovery. This is used for polymorphic endpoints
// which generally point to foreign versions. Scale refers to Scale.v1beta1.extensions for instance.
// This trumps KindProvider since it is capable of providing the information required.