resources

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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.

func (Filter) Matches

func (f Filter) Matches(res Resource) bool

Matches returns true if the filter matches the resource.

func (Filter) String

func (f Filter) String() string

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.

func (Filters) IsEmpty

func (f Filters) IsEmpty() bool

IsEmpty returns true if the filters are empty.

func (Filters) Matches

func (f Filters) Matches(res Resource) bool

Matches returns true if any of the filters matches the resource.

type InvalidSelectorError

type InvalidSelectorError struct {
	Command string
	Err     string
}

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

func (r *Resource) APIVersion() string

APIVersion returns the API version of the resource.

func (*Resource) Annotations

func (r *Resource) Annotations() map[string]string

Annotations returns the annotations of the resource.

func (*Resource) GetFolder

func (r *Resource) GetFolder() string

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) Group

func (r *Resource) Group() string

Group returns the group of the resource.

func (*Resource) GroupVersionKind

func (r *Resource) GroupVersionKind() schema.GroupVersionKind

GroupVersionKind returns the GroupVersionKind of the resource.

func (*Resource) IsEmpty

func (r *Resource) IsEmpty() bool

IsEmpty returns true if the resource is empty.

func (*Resource) IsFolder

func (r *Resource) IsFolder() bool

IsFolder returns true if the resource is a folder.

func (*Resource) IsManaged

func (r *Resource) IsManaged() bool

IsManaged returns true if the resource is managed by gcx.

func (*Resource) Kind

func (r *Resource) Kind() string

Kind returns the kind of the resource.

func (*Resource) Labels

func (r *Resource) Labels() map[string]string

Labels returns the labels of the resource.

func (*Resource) Name

func (r *Resource) Name() string

Name returns the name of the resource.

func (*Resource) Namespace

func (r *Resource) Namespace() string

Namespace returns the namespace 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

func (r *Resource) SourceFormat() format.Format

SourceFormat returns the source format of the resource.

func (*Resource) SourcePath

func (r *Resource) SourcePath() string

SourcePath returns the source path of the resource.

func (*Resource) Spec

func (r *Resource) Spec() (any, error)

Spec returns the spec of the resource.

func (*Resource) ToUnstructured

func (r *Resource) ToUnstructured() unstructured.Unstructured

ToUnstructured converts the resource to an unstructured object.

func (*Resource) Version

func (r *Resource) Version() string

Version returns the version of the resource.

type ResourceRef

type ResourceRef string

ResourceRef is a unique identifier for a resource.

type Resources

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

Resources is a collection of resources.

func MakeResources

func MakeResources(size int) *Resources

MakeResources makes a new empty Resources collection of the given size.

func NewResources

func NewResources(resources ...*Resource) *Resources

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) Add

func (r *Resources) Add(resources ...*Resource)

Add adds resources to the collection.

func (*Resources) AsList

func (r *Resources) AsList() []*Resource

AsList returns a list of resources from the collection.

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

func (r *Resources) Find(kind string, name string) (*Resource, bool)

Find finds a resource by kind and name. TODO: kind + name isn't enough to unambiguously identify a resource.

func (*Resources) ForEach

func (r *Resources) ForEach(callback func(*Resource) error) error

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

func (r *Resources) GroupByKind() map[string]*Resources

GroupByKind groups resources by kind.

func (*Resources) Len

func (r *Resources) Len() int

Len returns the number of resources in the collection.

func (*Resources) Merge

func (r *Resources) Merge(resources *Resources)

Merge merges another resources collection into the current one.

func (*Resources) OnChange

func (r *Resources) OnChange(callback func(resource *Resource))

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 (sel *Selector) IsNamedSelector() bool

func (*Selector) ParseString

func (sel *Selector) ParseString(src string) error

ParseString parses the selector from a string.

func (*Selector) String

func (sel *Selector) String() string

type Selectors

type Selectors []Selector

Selectors is a list of resource selectors.

func ParseSelectors

func ParseSelectors(sels []string) (Selectors, error)

ParseSelectors parses a list of resource selector strings into a list of Selectors.

func (Selectors) HasNamedSelectorsOnly

func (s Selectors) HasNamedSelectorsOnly() bool

func (Selectors) IsSingleTarget

func (s Selectors) IsSingleTarget() bool

IsSingleTarget returns true if the selector is to get a single resource.

type SourceInfo

type SourceInfo struct {
	Path   string
	Format format.Format
}

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.

Jump to

Keyboard shortcuts

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