resources

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Added    = "ADDED"
	Modified = "MODIFIED"
	Deleted  = "DELETED"
)
View Source
const MAX_HISTORY_LENGTH = 200

Variables

This section is empty.

Functions

func AddCustomListeners

func AddCustomListeners(informer cache.SharedIndexInformer, runtimeCache *Cache)

AddCustomListeners adds additional listeners to a shared informer for updating Custom Resource informers

func HasCRD

func HasCRD(targetGVR schema.GroupVersionResource, CRDs *ResourceList) bool

func ToUnstructured

func ToUnstructured(obj interface{}) (*unstructured.Unstructured, error)

ToUnstructured converts an object to an Unstructured

Types

type Cache

type Cache struct {

	// Core resources
	Events     *ResourceList
	Namespaces *ResourceList
	Nodes      *ResourceList

	// Workload resources
	Pods         *ResourceList
	Deployments  *ResourceList
	Daemonsets   *ResourceList
	Statefulsets *ResourceList
	Jobs         *ResourceList
	CronJobs     *ResourceList

	// UDS resources
	UDSPackages   *ResourceList
	UDSExemptions *ResourceList

	// Config resources
	Configmaps *ResourceList
	Secrets    *ResourceList

	// Cluster ops resources
	MutatingWebhooks     *ResourceList
	ValidatingWebhooks   *ResourceList
	HPAs                 *ResourceList
	PriorityClasses      *ResourceList
	RuntimeClasses       *ResourceList
	PodDisruptionBudgets *ResourceList
	LimitRanges          *ResourceList
	ResourceQuotas       *ResourceList

	// Network resources
	Services        *ResourceList
	NetworkPolicies *ResourceList
	Endpoints       *ResourceList
	VirtualServices *ResourceList

	// Storage resources
	PersistentVolumes      *ResourceList
	PersistentVolumeClaims *ResourceList
	StorageClasses         *ResourceList

	// Metrics
	PodMetrics     *PodMetrics
	MetricsChanges chan struct{}

	// CustomResourceDefinitions
	CRDs *ResourceList

	// Gateways
	Gateways *ResourceList
	// contains filtered or unexported fields
}

func NewCache

func NewCache(ctx context.Context, clients *client.Clients) (*Cache, error)

func (*Cache) CalculateUsage

func (c *Cache) CalculateUsage(metrics *v1beta1.PodMetrics) (float64, float64)

Update the CalculateUsage function

func (*Cache) StartMetricsCollection

func (c *Cache) StartMetricsCollection(ctx context.Context, metricsClient metricsv1beta1.MetricsV1beta1Interface)

StartMetricsCollection starts a goroutine to collect metrics for all pods in the cache

type PodMetrics

type PodMetrics struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewPodMetrics

func NewPodMetrics() *PodMetrics

func (*PodMetrics) Delete

func (pm *PodMetrics) Delete(podUID string)

Delete removes the metrics for a pod from the cache

func (*PodMetrics) Get

func (pm *PodMetrics) Get(podUID string) *unstructured.Unstructured

Get returns the metrics for a pod in the cache

func (*PodMetrics) GetAll

func (pm *PodMetrics) GetAll(namespace string, _ string) []unstructured.Unstructured

GetAll returns all metrics in the cache with optional filtering by namespace, second argument is ignored

func (*PodMetrics) GetCount

func (pm *PodMetrics) GetCount() int

GetCount returns the number of metrics in the cache

func (*PodMetrics) GetHistoricalUsage

func (pm *PodMetrics) GetHistoricalUsage() []Usage

GetHistoricalUsage returns the historical usage data

func (*PodMetrics) GetUsage

func (pm *PodMetrics) GetUsage() (cpu float64, mem float64)

GetUsage returns the current CPU and memory usage

func (*PodMetrics) Update

func (pm *PodMetrics) Update(podUID string, metrics *unstructured.Unstructured)

Update updates the metrics for a pod in the cache

type ResourceList

type ResourceList struct {
	Resources       map[string]*unstructured.Unstructured
	SparseResources map[string]*unstructured.Unstructured
	HasSynced       cache.InformerSynced
	Changes         chan struct{}

	GVR       schema.GroupVersionResource
	CRDExists bool
	// contains filtered or unexported fields
}

ResourceList is a thread-safe struct to store the list of resources and notify subscribers of changes.

func NewDynamicResourceList

func NewDynamicResourceList(informer cache.SharedIndexInformer, gvk schema.GroupVersionKind, gvr schema.GroupVersionResource) *ResourceList

NewDynamicResourceList initializes a ResourceList with a gvr.

func NewResourceList

func NewResourceList(informer cache.SharedIndexInformer, gvk schema.GroupVersionKind) *ResourceList

NewResourceList initializes a ResourceList and sets up event handlers for resource changes.

func (*ResourceList) CRDExistsInCluster

func (r *ResourceList) CRDExistsInCluster() bool

CRDExistsInCluster returns the value of the MissingCRD field for the ResourceList.

func (*ResourceList) GetResource

func (r *ResourceList) GetResource(uid string) (unstructured.Unstructured, bool)

GetResource returns a resource by UID.

func (*ResourceList) GetResources

func (r *ResourceList) GetResources(namespace string, namePartial string) []unstructured.Unstructured

GetResources returns a slice of the current resources.

func (*ResourceList) GetSparseResources

func (r *ResourceList) GetSparseResources(namespace string, namePartial string) []unstructured.Unstructured

GetSparseResources returns a slice of the current resources with only metadata and status fields.

type Usage

type Usage struct {
	Timestamp time.Time
	CPU       float64
	Memory    float64
}

Jump to

Keyboard shortcuts

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