Documentation
¶
Index ¶
- type PreparedTrait
- type TraitsExtractor
- type UsageTracker
- func (u *UsageTracker) CompleteResourceUsage(usage *usagev1alpha1.ResourceUsage)
- func (u *UsageTracker) MatchesSelector(ctx context.Context, obj client.Object, ns *corev1.Namespace) (bool, error)
- func (u *UsageTracker) NamespaceRequired() bool
- func (u *UsageTracker) NewResourceUsage(obj client.Object, traitData map[string][]byte, now time.Time) *usagev1alpha1.ResourceUsage
- func (u *UsageTracker) StopTracking(usage *usagev1alpha1.ResourceUsage, now time.Time)
- func (u *UsageTracker) Track(usage *usagev1alpha1.ResourceUsage, obj client.Object, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PreparedTrait ¶ added in v1.0.0
type PreparedTrait struct {
usagev1alpha1.Trait
// contains filtered or unexported fields
}
type TraitsExtractor ¶ added in v1.0.0
type TraitsExtractor struct {
// contains filtered or unexported fields
}
TraitsExtractor is a utility struct that provides methods to extract trait information from Kubernetes objects.
func NewTraitsExtractor ¶ added in v1.0.0
func NewTraitsExtractor(defs map[string]usagev1alpha1.Trait) (*TraitsExtractor, error)
NewTraitsExtractor creates a new TraitsExtractor from the given trait definitions. This already parses the trait's jsonPath expressions and will return an error if any of the expressions are invalid.
func (*TraitsExtractor) ExtractTraits ¶ added in v1.0.0
func (te *TraitsExtractor) ExtractTraits(obj client.Object, ns *corev1.Namespace) (map[string][]byte, error)
ExtractTraits extracts the traits from the given Kubernetes object and its namespace. It returns a map of trait names to their corresponding values (in JSON representation).
type UsageTracker ¶
type UsageTracker struct {
Config *usagev1alpha1.ResourceToTrack
TraitsExtractor *TraitsExtractor
}
func NewUsageTracker ¶
func NewUsageTracker(ctx context.Context, cfg *usagev1alpha1.ResourceToTrack) (*UsageTracker, error)
func (*UsageTracker) CompleteResourceUsage ¶ added in v1.0.0
func (u *UsageTracker) CompleteResourceUsage(usage *usagev1alpha1.ResourceUsage)
CompleteResourceUsage is meant to be called on a ResourceUsage which is still 'Ongoing' according to its status, but its tracking period has ended. This basically 'cleans up' the ResourceUsage object and sets its status to 'Completed', so that a new ResourceUsage can be created for the same resource. If the latest usage trackings (resource one as well as traits) don't have an end time set, it will be set to the end of the tracking period. Modifies the object in-place (status, potentially also spec), but does not update it on the cluster. This must be done by the caller. This method can be called on a nil UsageTracker.
func (*UsageTracker) MatchesSelector ¶ added in v1.0.0
func (u *UsageTracker) MatchesSelector(ctx context.Context, obj client.Object, ns *corev1.Namespace) (bool, error)
MatchesSelector returns true if the given object matches the configured selectors for the resource and its namespace, if any. Always returns true if no selectors are configured or an error occurred while fetching the namespace or evaluating the selectors. The namespace argument may be nil if there is no namespace selector configured.
func (*UsageTracker) NamespaceRequired ¶ added in v1.0.0
func (u *UsageTracker) NamespaceRequired() bool
NamespaceRequired returns true if either the selector or any trait definition requires the namespace to be fetched for the resource, false otherwise.
func (*UsageTracker) NewResourceUsage ¶ added in v1.0.0
func (u *UsageTracker) NewResourceUsage(obj client.Object, traitData map[string][]byte, now time.Time) *usagev1alpha1.ResourceUsage
NewResourceUsage creates a new ResourceUsage object (internally only, not on the cluster). This method is intended to be called if data is to be tracked, but either no ResourceUsage exists for the tracked object yet, or the latest ResourceUsage's tracking period has ended and a new one needs to be created. Note that this method does create a new ResourceUsage object on the cluster, it just prepares the resource. The given time is truncated to minute precision and used as the start time for the new ResourceUsage's tracking period and usage tracking.
func (*UsageTracker) StopTracking ¶ added in v1.0.0
func (u *UsageTracker) StopTracking(usage *usagev1alpha1.ResourceUsage, now time.Time)
StopTracking is meant to be called on a ResourceUsage which is still 'Ongoing', but the resource is no longer tracked (e.g. because it was deleted or modified to not match a selector anymore). Note that this does not set the status to 'Completed', as further information might be added to the ResourceUsage if the resource is recreated or modified to match the selector again. Modifies the object in-place (spec only), but does not update it on the cluster. This must be done by the caller. This method can be called on a nil UsageTracker.
func (*UsageTracker) Track ¶ added in v1.0.0
func (u *UsageTracker) Track(usage *usagev1alpha1.ResourceUsage, obj client.Object, traitData map[string][]byte, now time.Time)
Track tracks new usage in the given ResourceUsage object for the given resource and its traits, based on the given trait data. This will modify the ResourceUsage object in-place (spec only), but does not update it on the cluster. This must be done by the caller. This method can be called on a nil UsageTracker.