discovery

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ClusterScope is an object scoped to the cluster.
	ClusterScope = ScopeType("Cluster")
	// NamespaceScope is an object scoped to namespace.
	NamespaceScope = ScopeType("Namespace")
	// UnknownScope means we don't know the scope of the type.
	UnknownScope = ScopeType("Unknown")
)

Variables

This section is empty.

Functions

func GetResources

func GetResources(discoveryClient ServerResourcer) ([]*metav1.APIResourceList, status.Error)

GetResources gets the APIResourceLists from an existing DiscoveryClient. Invalidates the cache if possible as the server may have new resources since the client was created.

Types

type APIInfo

type APIInfo map[schema.GroupVersionKind]bool

APIInfo caches the GroupVersionKinds available on the cluster.

func NewAPIInfo

func NewAPIInfo(resourceLists []*metav1.APIResourceList) (APIInfo, status.MultiError)

NewAPIInfo constructs an APIInfo from resources retrieved from a DiscoveryClient, and a set of additional resources with known scopes.

Note that this EXCLUDES types defined in CRDs, but are not on the APIServer. This is because trying to sync CRs for a CRD that is not yet available to the cluster is an error.

func (*APIInfo) GroupVersionKinds

func (a *APIInfo) GroupVersionKinds(syncs ...*v1.Sync) map[schema.GroupVersionKind]bool

GroupVersionKinds returns a set of GroupVersionKinds represented by the slice of Syncs with only Group and Kind specified.

type AddResourcesFunc

type AddResourcesFunc func(*Scoper) status.MultiError

AddResourcesFunc is a function that accepts a Scoper and adds resources to it.

type BuildScoperFunc

type BuildScoperFunc func([]*v1beta1.CustomResourceDefinition, []ast.FileObject) (Scoper, status.MultiError)

BuildScoperFunc is a function that builds a new Scoper with the given CRDs and attempts verifies it against the given FileObjects.

func ScoperBuilder

func ScoperBuilder(sr ServerResourcer, addFuncs ...AddResourcesFunc) BuildScoperFunc

ScoperBuilder returns a BuildScoperFunc that incorporates the given ServerResourcer (for reading resources from the API server) and other optional functions for adding resources.

type GroupKindScope

type GroupKindScope struct {
	schema.GroupKind
	ScopeType
}

GroupKindScope is a Kubernetes type, and whether it is Namespaced.

type NoOpServerResourcer

type NoOpServerResourcer struct{}

NoOpServerResourcer is a ServerResourcer that returns nil.

func (NoOpServerResourcer) ServerGroupsAndResources

func (n NoOpServerResourcer) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)

ServerGroupsAndResources returns nothing.

type ScopeType

type ScopeType string

ScopeType is the namespace/cluster scope of a particular GroupKind.

type Scoper

type Scoper struct {
	// contains filtered or unexported fields
}

Scoper wraps a map from GroupKinds to ScopeType.

func APIResourceScoper

func APIResourceScoper(sr ServerResourcer) (Scoper, status.MultiError)

APIResourceScoper returns a Scoper that contains scopes for all resources available from the API server.

func CoreScoper

func CoreScoper() Scoper

CoreScoper returns a Scoper with the scopes of all core Kubernetes and Nomos types defined. Use this instead of building a Scoper from the response to an APIServer when one is unavailable.

func (*Scoper) AddAPIResourceLists

func (s *Scoper) AddAPIResourceLists(resourceLists []*metav1.APIResourceList) status.MultiError

AddAPIResourceLists adds APIResourceLists retrieved from an API Server to the Scoper. It replaces any existing scopes for the GroupKinds of the API resources.

func (*Scoper) AddCustomResources

func (s *Scoper) AddCustomResources(crds []*v1beta1.CustomResourceDefinition)

AddCustomResources updates Scoper with custom resource metadata from the provided CustomResourceDefinitions. It replaces any existing scopes for the GroupKinds of the CRDs.

func (*Scoper) AddScoper

func (s *Scoper) AddScoper(other Scoper)

AddScoper adds the scopes from the given Scoper into this one. If the two Scopers have any overlapping scopes defined, the added ones will overwrite the existing ones in this Scope.

func (*Scoper) GetGroupKindScope

func (s *Scoper) GetGroupKindScope(gk schema.GroupKind) (ScopeType, status.Error)

GetGroupKindScope returns whether the type is namespace-scoped or cluster-scoped. Returns an error if the GroupKind is unknown to the cluster.

func (*Scoper) GetObjectScope

func (s *Scoper) GetObjectScope(o client.Object) (ScopeType, status.Error)

GetObjectScope implements Scoper

func (*Scoper) HasScopesFor

func (s *Scoper) HasScopesFor(objects []ast.FileObject) bool

HasScopesFor returns true if the Scoper knows the scopes for every type in the passed slice of FileObjects.

While this could be made more general, it requests a slice of FileObjects as this is a convenience method.

func (*Scoper) SetGroupKindScope

func (s *Scoper) SetGroupKindScope(gk schema.GroupKind, scope ScopeType)

SetGroupKindScope sets the scope for the passed GroupKind.

type ServerResourcer

type ServerResourcer interface {
	ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)
}

ServerResourcer returns a the API Groups and API Resources available on the API Server.

DiscoveryInterface satisfies this interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL