Documentation
¶
Index ¶
- Constants
- func SortUnstructured(items []unstructured.Unstructured)
- type Descriptor
- type Descriptors
- type Filter
- type FilterType
- type Filters
- type InvalidSelectorError
- type PartialGVK
- type Resource
- func (r *Resource) APIVersion() string
- func (r *Resource) Annotations() map[string]string
- func (r *Resource) GetFolder() string
- func (r *Resource) GetManagerKind() utils.ManagerKind
- func (r *Resource) Group() string
- func (r *Resource) GroupVersionKind() schema.GroupVersionKind
- func (r *Resource) IsEmpty() bool
- func (r *Resource) IsFolder() bool
- func (r *Resource) IsManaged() bool
- func (r *Resource) Kind() string
- func (r *Resource) Labels() map[string]string
- func (r *Resource) Name() string
- func (r *Resource) Namespace() string
- func (r *Resource) Ref() ResourceRef
- func (r *Resource) SetSource(source SourceInfo)
- func (r *Resource) SetUnstructured(obj *unstructured.Unstructured) error
- func (r *Resource) SourceFormat() format.Format
- func (r *Resource) SourcePath() string
- func (r *Resource) Spec() (any, error)
- func (r *Resource) ToUnstructured() unstructured.Unstructured
- func (r *Resource) Version() string
- type ResourceRef
- type Resources
- func (r *Resources) Add(resources ...*Resource)
- func (r *Resources) AsList() []*Resource
- func (r *Resources) Clear()
- func (r *Resources) Find(kind string, name string) (*Resource, bool)
- func (r *Resources) ForEach(callback func(*Resource) error) error
- func (r *Resources) ForEachConcurrently(ctx context.Context, maxInflight int, ...) error
- func (r *Resources) GroupByKind() map[string]*Resources
- func (r *Resources) Len() int
- func (r *Resources) Merge(resources *Resources)
- func (r *Resources) OnChange(callback func(resource *Resource))
- func (r *Resources) ToUnstructuredList() unstructured.UnstructuredList
- type Selector
- type Selectors
- type SourceInfo
Constants ¶
const ( // ResourceManagerKind is the manager kind used for gcx. // TODO: change once we have a proper manager kind for gcx. ResourceManagerKind = utils.ManagerKindKubectl // AnnotationSavedFromUI is the annotation key for resources saved from the UI. // TODO: move this to grafana/grafana. AnnotationSavedFromUI = "grafana.app/saved-from-ui" )
Variables ¶
This section is empty.
Functions ¶
func SortUnstructured ¶
func SortUnstructured(items []unstructured.Unstructured)
SortUnstructured sorts a list of unstructured objects by group, version, kind, and name.
Types ¶
type Descriptor ¶
type Descriptor struct {
GroupVersion schema.GroupVersion
Kind string
Singular string
Plural string
}
Descriptor describes a resource.
func (Descriptor) GroupVersionKind ¶
func (d Descriptor) GroupVersionKind() schema.GroupVersionKind
GroupVersionKind returns the GroupVersionKind for the descriptor.
func (Descriptor) GroupVersionResource ¶
func (d Descriptor) GroupVersionResource() schema.GroupVersionResource
GroupVersionResource returns the GroupVersionResource for the descriptor.
func (Descriptor) Matches ¶
func (d Descriptor) Matches(gvk schema.GroupVersionKind) bool
Matches returns true if the descriptor matches the given GroupVersionKind.
func (Descriptor) String ¶
func (d Descriptor) String() string
type Descriptors ¶
type Descriptors []Descriptor
Descriptors is a list of descriptors.
func (Descriptors) Sorted ¶
func (d Descriptors) Sorted() Descriptors
Sorted sorts the descriptors by group, version, kind, and name.
type Filter ¶
type Filter struct {
Type FilterType
Descriptor Descriptor
ResourceUIDs []string
}
Filter is a filter to filter resources from Grafana. Unlike Selector, filters use the Descriptor to identify the resource type, which fully defines the target API resource.
type FilterType ¶
type FilterType int
FilterType is the type of a resource selector. It identifies whether the selector needs to select all resources of a type, select a single resource by UID, or select multiple resources by UID.
const ( // FilterTypeUnknown is the default fallback value for a selector. FilterTypeUnknown FilterType = iota // FilterTypeAll is the selector is to select all resources of a type. FilterTypeAll // FilterTypeMultiple is the selector is to select multiple resources by UID. FilterTypeMultiple // FilterTypeSingle is the selector is to select a single resource by UID. FilterTypeSingle )
func (FilterType) String ¶
func (t FilterType) String() string
type Filters ¶
type Filters []Filter
Filters is a list of filters.
type InvalidSelectorError ¶
InvalidSelectorError is an error that occurs when a command is invalid.
func (InvalidSelectorError) Error ¶
func (e InvalidSelectorError) Error() string
type PartialGVK ¶
type PartialGVK struct {
// Group represents the API group.
// It may or may not be set, depending on the user input.
// It can also be in a short or long format.
Group string
// Version represents the API version.
// It may or may not be set, depending on the user input.
Version string
// Resource is any identifier of API resource.
// It may be one of (kind, singular, plural).
Resource string
}
PartialGVK is a partial identifier of an API resource. Not all fields are required to be set. It is expected that anything that accepts a PartialGVK will handle the discovery of the resource based on the fields that are present.
func (*PartialGVK) ParseString ¶
func (gvk *PartialGVK) ParseString(src string) error
ParseString parses a PartialGVK from a string.
func (*PartialGVK) String ¶
func (gvk *PartialGVK) String() string
type Resource ¶
type Resource struct {
Raw utils.GrafanaMetaAccessor
Object unstructured.Unstructured
Source SourceInfo
}
Resource is a resource in the Grafana API.
func FromUnstructured ¶
func FromUnstructured(obj *unstructured.Unstructured) (*Resource, error)
FromUnstructured creates a new Resource from an unstructured object.
func MustFromObject ¶
func MustFromObject(obj map[string]any, source SourceInfo) *Resource
MustFromObject creates a new Resource from an object. If the object is not a valid Grafana resource, it will panic.
func MustFromUnstructured ¶
func MustFromUnstructured(obj *unstructured.Unstructured) *Resource
MustFromUnstructured creates a new Resource from an unstructured object. If the object is not a valid Grafana resource, it will panic.
func (*Resource) APIVersion ¶
APIVersion returns the API version of the resource.
func (*Resource) Annotations ¶
Annotations returns the annotations of the resource.
func (*Resource) GetFolder ¶
GetFolder returns the parent folder UID from the annotation. Returns empty string if the folder has no parent (is a root folder).
func (*Resource) GetManagerKind ¶
func (r *Resource) GetManagerKind() utils.ManagerKind
GetManagerKind returns the kind of the manager that manages the resource.
func (*Resource) GroupVersionKind ¶
func (r *Resource) GroupVersionKind() schema.GroupVersionKind
GroupVersionKind returns the GroupVersionKind of the resource.
func (*Resource) Ref ¶
func (r *Resource) Ref() ResourceRef
Ref returns a unique identifier for the resource.
func (*Resource) SetSource ¶
func (r *Resource) SetSource(source SourceInfo)
SetSource sets the source of the resource.
func (*Resource) SetUnstructured ¶
func (r *Resource) SetUnstructured(obj *unstructured.Unstructured) error
SetUnstructured sets the resource to the given unstructured object.
func (*Resource) SourceFormat ¶
SourceFormat returns the source format of the resource.
func (*Resource) SourcePath ¶
SourcePath returns the source path of the resource.
func (*Resource) ToUnstructured ¶
func (r *Resource) ToUnstructured() unstructured.Unstructured
ToUnstructured converts the resource to an unstructured object.
type Resources ¶
type Resources struct {
// contains filtered or unexported fields
}
Resources is a collection of resources.
func MakeResources ¶
MakeResources makes a new empty Resources collection of the given size.
func NewResources ¶
NewResources creates a new Resources collection.
func NewResourcesFromUnstructured ¶
func NewResourcesFromUnstructured(resources unstructured.UnstructuredList) (*Resources, error)
NewResourcesFromUnstructured creates a new Resources collection from an unstructured list.
func (*Resources) Clear ¶
func (r *Resources) Clear()
Clear removes all resources from the collection by resetting the underlying map. The new map will have the same capacity as the old one.
func (*Resources) Find ¶
Find finds a resource by kind and name. TODO: kind + name isn't enough to unambiguously identify a resource.
func (*Resources) ForEach ¶
ForEach iterates over all resources in the collection and calls the callback for each resource.
func (*Resources) ForEachConcurrently ¶
func (r *Resources) ForEachConcurrently( ctx context.Context, maxInflight int, callback func(context.Context, *Resource) error, ) error
ForEachConcurrently iterates over all resources in the collection and calls the callback for each resource. The callback is called concurrently, up to maxInflight at a time.
func (*Resources) GroupByKind ¶
GroupByKind groups resources by kind.
func (*Resources) OnChange ¶
OnChange adds a callback that will be called when a resource is added to the collection.
func (*Resources) ToUnstructuredList ¶
func (r *Resources) ToUnstructuredList() unstructured.UnstructuredList
ToUnstructuredList converts the resources to an unstructured list.
type Selector ¶
type Selector struct {
Type FilterType
GroupVersionKind PartialGVK
ResourceUIDs []string
}
Selector is a selector to select a resource from Grafana. Unlike Filter, selectors use the PartialGVK to identify the resource type, which only describes the target API resource partially and does not guarantee that the it is supported.
func (*Selector) IsNamedSelector ¶
func (*Selector) ParseString ¶
ParseString parses the selector from a string.
type Selectors ¶
type Selectors []Selector
Selectors is a list of resource selectors.
func ParseSelectors ¶
ParseSelectors parses a list of resource selector strings into a list of Selectors.
func (Selectors) HasNamedSelectorsOnly ¶
func (Selectors) IsSingleTarget ¶
IsSingleTarget returns true if the selector is to get a single resource.
type SourceInfo ¶
SourceInfo is information about the source of a resource.
func (*SourceInfo) String ¶
func (s *SourceInfo) String() string
Directories
¶
| Path | Synopsis |
|---|---|
|
Package adapter defines the ResourceAdapter interface for bridging provider REST clients to the gcx resources pipeline.
|
Package adapter defines the ResourceAdapter interface for bridging provider REST clients to the gcx resources pipeline. |