Documentation
¶
Overview ¶
Package resourcetracker records what an owner has applied, so it can be garbage-collected when the owner stops rendering it or goes away.
Tracked is what an owner implements: its identity, how it marks the resources it owns, and how its trackers are named and found. Base is the default behaviour, marking resources and trackers with owner.oam.dev/* labels; a kind embeds it and overrides what differs. Embedding gives no virtual dispatch, so anything Base does that a kind must be able to vary is asked of the interface by CreateTracker rather than called on Base.
The package is part of the library described in pkg/resourcekeeper's package doc, and carries the same dependency limits.
Index ¶
- Constants
- func Configure(c Config)
- func CreateTracker(ctx context.Context, cli client.Client, t Tracked, ...) (*v1beta1.ResourceTracker, error)
- func DeletedManifestInResourceTracker(ctx context.Context, cli client.Client, rt *v1beta1.ResourceTracker, ...) error
- func HasAnyOwnerLabel(labels map[string]string) bool
- func LabelsForKey(key string) map[string]string
- func OnList(kind string)
- func OwnerKeyFromLabels(labels map[string]string) string
- func OwnerLabelKeys() []string
- func RecordManifestsInResourceTracker(ctx context.Context, cli client.Client, rt *v1beta1.ResourceTracker, ...) error
- func SortResourceTrackersByVersion(rts []*v1beta1.ResourceTracker, descending bool) []*v1beta1.ResourceTracker
- type Base
- func (b *Base) ControlledBy(obj client.Object) string
- func (b *Base) Deleting() bool
- func (b *Base) Key() string
- func (b *Base) Kind() string
- func (b *Base) Labels() map[string]string
- func (b *Base) LoadTrackers(ctx context.Context, cli client.Client) (Trackers, error)
- func (b *Base) Name() string
- func (b *Base) Namespace() string
- func (b *Base) NewTracker(rtType v1beta1.ResourceTrackerType) (*v1beta1.ResourceTracker, error)
- func (b *Base) Orphaning() bool
- func (b *Base) Release(obj *unstructured.Unstructured)
- func (b *Base) Stamp(obj *unstructured.Unstructured)
- func (b *Base) TrackerLabels() map[string]string
- type Config
- type Owner
- type Tracked
- type Trackers
Constants ¶
const (
// Finalizer for resourcetracker to clean up recorded resources
Finalizer = "resourcetracker.core.oam.dev/finalizer"
)
Variables ¶
This section is empty.
Functions ¶
func Configure ¶
func Configure(c Config)
Configure sets this package's Config for the process. Hosts call it at start-up.
func CreateTracker ¶
func CreateTracker(ctx context.Context, cli client.Client, t Tracked, rtType v1beta1.ResourceTrackerType) (*v1beta1.ResourceTracker, error)
CreateTracker creates a new tracker of the given type for t.
func DeletedManifestInResourceTracker ¶
func DeletedManifestInResourceTracker(ctx context.Context, cli client.Client, rt *v1beta1.ResourceTracker, manifest *unstructured.Unstructured, remove bool) error
DeletedManifestInResourceTracker marks resources as deleted in resourcetracker, if remove is true, resources will be removed from resourcetracker
func HasAnyOwnerLabel ¶
HasAnyOwnerLabel reports whether labels carry any owner.oam.dev/* mark, so a kind whose own marks are absent can tell "nobody has claimed this" from "somebody did, incompletely".
func LabelsForKey ¶
LabelsForKey returns the labels that mark a resource as controlled by the owner with this key: owner.oam.dev/* and the kind's own (Config.KindLabels). The key may be in either form (see apply.CanonicalOwnerKey); nil if it names no kind.
func OnList ¶
func OnList(kind string)
OnList reports a listing of an owner kind's trackers to the configured OnList.
func OwnerKeyFromLabels ¶
OwnerKeyFromLabels returns the key the owner.oam.dev/* labels name, "" if they name none. Kinds read their labels once and pass them here, since reading them copies the map.
func OwnerLabelKeys ¶
func OwnerLabelKeys() []string
OwnerLabelKeys are the labels Base puts on the resources it owns.
func RecordManifestsInResourceTracker ¶ added in v1.2.3
func RecordManifestsInResourceTracker( ctx context.Context, cli client.Client, rt *v1beta1.ResourceTracker, manifests []*unstructured.Unstructured, metaOnly bool, skipGC bool, creator string) error
RecordManifestsInResourceTracker records resources in ResourceTracker
func SortResourceTrackersByVersion ¶
func SortResourceTrackersByVersion(rts []*v1beta1.ResourceTracker, descending bool) []*v1beta1.ResourceTracker
SortResourceTrackersByVersion sort resourceTrackers by version
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base is the behaviour every kind shares: owner.oam.dev/* labels on trackers and on owned resources, trackers named <namespace>-<name>[-v<generation>], and the current tracker chosen by generation.
func (*Base) ControlledBy ¶
ControlledBy reads the owner.oam.dev/* labels.
func (*Base) LoadTrackers ¶
LoadTrackers lists the owner's trackers by its owner.oam.dev/* labels.
func (*Base) NewTracker ¶
func (b *Base) NewTracker(rtType v1beta1.ResourceTrackerType) (*v1beta1.ResourceTracker, error)
NewTracker names a root or versioned tracker. Other types belong to the kind.
func (*Base) Release ¶
func (b *Base) Release(obj *unstructured.Unstructured)
Release removes the owner.oam.dev/* labels.
func (*Base) Stamp ¶
func (b *Base) Stamp(obj *unstructured.Unstructured)
Stamp adds the owner.oam.dev/* labels.
func (*Base) TrackerLabels ¶
TrackerLabels are the owner.oam.dev/* labels, including the owner's uid.
type Config ¶
type Config struct {
// Compression returns how new ResourceTrackers compress their records; "" leaves them
// uncompressed. Default "" (KubeVela: ZstdResourceTracker, else GzipResourceTracker).
Compression func() compression.Type
// OnList is called whenever an owner's trackers are listed, with the owner kind as that
// kind spells it ("Application", "Component"). Default none (KubeVela: a counter metric).
OnList func(kind string)
// KindLabels returns the labels an owner kind puts on its resources besides
// owner.oam.dev/*, so a resource handed to the next sharer is labelled as that kind
// labels its own. Default: none (KubeVela: app.oam.dev/* for Applications).
KindLabels func(kind, namespace, name string) map[string]string
}
Config holds the behaviour the host binary decides for this package. Its functions are called on every use, so a host can back them with settings that change at runtime. A nil function takes the default documented on it, which matches KubeVela's default.
func CurrentConfig ¶
func CurrentConfig() Config
CurrentConfig returns the Config in effect (the zero Config if Configure was never called).
type Owner ¶
type Owner struct {
Kind, Namespace, Name string
UID types.UID
Generation int64
// Deleting reports that the owner itself is being deleted.
Deleting bool
}
Owner identifies the owner a Base speaks for. A struct rather than parameters: kind, namespace and name are all strings, and swapping two of them compiles.
type Tracked ¶
type Tracked interface {
Kind() string
Name() string
Namespace() string
// Key identifies the owner in ownership checks and sharer lists.
Key() string
// Deleting reports that the owner itself is being deleted, so all its trackers are inactive.
Deleting() bool
// ControlledBy returns the key of whoever controls obj, or "" if nobody does.
ControlledBy(obj client.Object) string
// Stamp marks a manifest as owned by this owner before it is applied.
Stamp(obj *unstructured.Unstructured)
// Release removes the marks Stamp (or the owner's kind) put on a resource that is being
// left behind rather than deleted.
Release(obj *unstructured.Unstructured)
// Orphaning reports that the owner's resources are to be left behind, not deleted,
// when it lets them go.
Orphaning() bool
// TrackerLabels are the labels every tracker of the owner carries.
TrackerLabels() map[string]string
// NewTracker returns a tracker of the given type, named and typed for this owner and not
// yet created. CreateTracker adds TrackerLabels to whatever it returns, so an
// implementation adds only the labels and annotations peculiar to it.
NewTracker(rtType v1beta1.ResourceTrackerType) (*v1beta1.ResourceTracker, error)
// LoadTrackers finds the owner's existing trackers.
LoadTrackers(ctx context.Context, cli client.Client) (Trackers, error)
}
Tracked is whoever a set of ResourceTrackers, and the resources they record, belongs to. Each kind of owner implements it, embedding Base and overriding only where it differs; the constructors live with the kind, not in this package.
type Trackers ¶
type Trackers struct {
Root *v1beta1.ResourceTracker
Current *v1beta1.ResourceTracker
History []*v1beta1.ResourceTracker
ComponentRevision *v1beta1.ResourceTracker
}
Trackers are an owner's trackers: the root (life-long resources), the current version, older versions sorted oldest first, and any component-revision tracker.