discovery

package
v0.37.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 25 Imported by: 15,728

Documentation

Overview

Package discovery provides ways to discover server-supported API groups, versions and resources.

Index

Constants

View Source
const (
	AcceptV1 = runtime.ContentTypeJSON
	// Aggregated discovery content-type. NOTE: content-type parameters
	// MUST be ordered (g, v, as) for server in "Accept" header (BUT we are resilient
	// to ordering when comparing returned values in "Content-Type" header).
	AcceptV2       = runtime.ContentTypeJSON + ";" + "g=apidiscovery.k8s.io;v=v2;as=APIGroupDiscoveryList"
	AcceptV2NoPeer = runtime.ContentTypeJSON + ";" + "g=apidiscovery.k8s.io;v=v2;as=APIGroupDiscoveryList;profile=nopeer"
)

Variables

This section is empty.

Functions

func ContentTypeIsGVK added in v0.27.6

func ContentTypeIsGVK(contentType string, gvk schema.GroupVersionKind) (bool, error)

ContentTypeIsGVK checks of the content-type string is both "application/json" and matches the provided GVK. An error is returned if the content type string is malformed. NOTE: This function is resilient to the ordering of the content-type parameters, as well as parameters added by intermediaries such as proxies or gateways. Examples:

("application/json; g=apidiscovery.k8s.io;v=v2;as=APIGroupDiscoveryList", {apidiscovery.k8s.io, v2, APIGroupDiscoveryList}) = (true, nil)
("application/json; as=APIGroupDiscoveryList;v=v2;g=apidiscovery.k8s.io", {apidiscovery.k8s.io, v2, APIGroupDiscoveryList}) = (true, nil)
("application/json; as=APIGroupDiscoveryList;v=v2;g=apidiscovery.k8s.io;charset=utf-8", {apidiscovery.k8s.io, v2, APIGroupDiscoveryList}) = (true, nil)
("application/json", any GVK) = (false, nil)
("application/json; charset=UTF-8", any GVK) = (false, nil)
("malformed content type string", any GVK) = (false, error)

func FilteredBy

FilteredBy filters by the given predicate. Empty APIResourceLists are dropped.

func GroupDiscoveryFailedErrorGroups added in v0.29.0

func GroupDiscoveryFailedErrorGroups(err error) (map[schema.GroupVersion]error, bool)

GroupDiscoveryFailedErrorGroups returns true if the error is an ErrGroupDiscoveryFailed error, along with the map of group versions that failed discovery.

func GroupVersionResources

func GroupVersionResources(rls []*metav1.APIResourceList) (map[schema.GroupVersionResource]struct{}, error)

GroupVersionResources converts APIResourceLists to the GroupVersionResources.

func IsGroupDiscoveryFailedError

func IsGroupDiscoveryFailedError(err error) bool

IsGroupDiscoveryFailedError returns true if the provided error indicates the server was unable to discover a complete list of APIs for the client to use.

func IsResourceEnabled added in v0.24.0

func IsResourceEnabled(client DiscoveryInterface, resourceToCheck schema.GroupVersionResource) (bool, error)

IsResourceEnabled queries the server to determine if the resource specified is present on the server. This is particularly helpful when writing a controller or an e2e test that requires a particular resource to function.

func MatchesServerVersion

func MatchesServerVersion(clientVersion apimachineryversion.Info, client DiscoveryInterface) error

MatchesServerVersion queries the server to compares the build version (git hash) of the client with the server's build version. It returns an error if it failed to contact the server or if the versions are not an exact match.

func ServerGroupsAndResources

func ServerGroupsAndResources(d DiscoveryInterface) ([]*metav1.APIGroup, []*metav1.APIResourceList, error)

ServerGroupsAndResourcesWithContext is a better alternative because it supports contextual logging and cancellation.

Contextual logging: Use ServerGroupsAndResourcesWithContext instead.

func ServerGroupsAndResourcesWithContext added in v0.37.0

func ServerGroupsAndResourcesWithContext(ctx context.Context, d DiscoveryInterfaceWithContext) ([]*metav1.APIGroup, []*metav1.APIResourceList, error)

func ServerPreferredNamespacedResources

func ServerPreferredNamespacedResources(d DiscoveryInterface) ([]*metav1.APIResourceList, error)

ServerPreferredNamespacedResources uses the provided discovery interface to look up preferred namespaced resources

ServerPreferredNamespacedResourcesWithContext is a better alternative because it supports contextual logging and cancellation.

Contextual logging: Use ServerPreferredNamespacedResourcesWithContext instead.