resources

package
v0.0.0-...-052eaa2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const WATCHER_STEP = time.Second * 1

Variables

This section is empty.

Functions

func IsLogging

func IsLogging(r types.Resource) bool

func RegisterResourceRenderer

func RegisterResourceRenderer(k string, r ResourceRenderer)

func ToggleLogs

func ToggleLogs(r types.Resource, containerName string)

Types

type ContainerInfo

type ContainerInfo struct {
	Image       string
	CPULimit    int64
	MemoryLimit int64
}

type Copyable

type Copyable interface {
	Copy() Copyable
}

type DAO

type DAO interface {
	AddResource(Resource)
	UpdateResource(Resource)
	DeleteResource(Resource)
	GetResourcesAt(timestamp time.Time, kind string, namespace string) []Resource
	GetResourceAt(timestamp time.Time, uid string) (Resource, error)
}

type K8sResource

type K8sResource interface {
	GetObjectMeta() v1.Object
}

type K8sWatcher

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

Watches for a variety of k8s resources state changes and tracks their values over time

func GetK8sWatcher

func GetK8sWatcher(data DAO) *K8sWatcher

func (*K8sWatcher) Add

func (w *K8sWatcher) Add(r Resource)

Add a resource to the temporal map

func (*K8sWatcher) ChangedSince

func (w *K8sWatcher) ChangedSince(t time.Time) bool

See if anything we watch has changed since a certain time

func (*K8sWatcher) Delete

func (w *K8sWatcher) Delete(r Resource)

Delete a resource in the temporal map

func (*K8sWatcher) OnChange

func (w *K8sWatcher) OnChange(onChange func())

Set the onChange callback

func (*K8sWatcher) StartWatching

func (w *K8sWatcher) StartWatching(ctx context.Context, client conn.KhronosConn, dao DAO, lc *LogCollector, ns string) error

func (*K8sWatcher) Update

func (w *K8sWatcher) Update(r Resource)

Update a resource in the temporal map

type LogCollector

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

func GetLogCollector

func GetLogCollector(client conn.KhronosConn) *LogCollector

type NodeExtra

type NodeExtra struct {
	NodeMetrics           map[string]string
	NodeCreationTimestamp time.Time
	CPUCapacity           int64
	MemCapacity           int64
	Uptime                time.Duration
	PodMetrics            map[string]map[string]PodMetric
}

func (NodeExtra) Copy

func (n NodeExtra) Copy() Copyable

type Pod

type Pod struct {
	Spec struct {
		Containers []struct {
			Image     string `json:"image"`
			Name      string `json:"name"`
			Resources struct {
				Limits struct {
					CPU    string `json:"cpu"`
					Memory string `json:"memory"`
				} `json:"limits"`
			} `json:"resources"`
		} `json:"containers"`
		NodeName string `json:"nodeName"`
	} `json:"spec"`
	Status struct {
		Phase string `json:"phase"`
	} `json:"status"`
}

type PodExtra

type PodExtra struct {
	Phase      string
	NodeName   string
	Metrics    map[string]PodMetric
	Uptime     time.Duration
	StartTime  serializable.Time
	Containers map[string]ContainerInfo
	Logs       []string
	Logging    []string
}

func (PodExtra) Copy

func (p PodExtra) Copy() Copyable

func (PodExtra) GetValue

func (r PodExtra) GetValue(key string) any

type PodMetric

type PodMetric struct {
	CPUPercentage    float64
	MemoryPercentage float64
}

type PodRenderer

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

func (PodRenderer) Render

func (r PodRenderer) Render(resource Resource, details bool) []string

type Resource

type Resource struct {
	Uid       string            // The Uid of the k8s object
	Timestamp serializable.Time // The timestamp that this resource is valid for
	Kind      string            // The k8s kind of resource
	Namespace string            // The k8s namespace, may be empty for things like namespace and node resources
	Name      string            // The name of the resource
	RawJSON   string            // Raw json for this k8s resource
	Extra     Copyable          // This should be a custom, gob registered and serializable object if used
}

func NewK8sResource

func NewK8sResource(kind string, obj K8sResource, extra Copyable) Resource

func NewResource

func NewResource(uuid string, timestmap time.Time, kind string, namespace string, name string) Resource

func (Resource) GetDetails

func (r Resource) GetDetails() []string

Render the details of the Resource

func (Resource) GetExtra

func (r Resource) GetExtra() any

func (Resource) GetKind

func (r Resource) GetKind() string

func (Resource) GetName

func (r Resource) GetName() string

func (Resource) GetNamespace

func (r Resource) GetNamespace() string

func (Resource) GetTimestamp

func (r Resource) GetTimestamp() time.Time

func (Resource) GetUID

func (r Resource) GetUID() string

func (Resource) Key

func (r Resource) Key() string

func (Resource) String

func (r Resource) String() string

Render a short version of the Resource

type ResourceEventWatcher

type ResourceEventWatcher interface {
	ToResource(obj runtime.Object) Resource // Converts a kubernetes object to a Resource
	Tick()                                  // Called at a regular interval and can be used to do any needed work to update Resources not handled by Add/Modified/Del like metrics & logs
	Renderer() ResourceRenderer
	Kind() string
}

Interface for watching resource events.

type ResourceRenderer

type ResourceRenderer interface {
	Render(resource Resource, detailed bool) []string
}

func GetRenderer

func GetRenderer(k string) ResourceRenderer

Jump to

Keyboard shortcuts

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