model

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterNamespaces

type ClusterNamespaces struct {
	Cluster    string
	Namespaces []string
}

type Container

type Container struct {
	Cluster, Namespace, Deployment, Pod, Name string
	Status                                    ContainerStatus
}

func (Container) Equals

func (c Container) Equals(other Container) bool

func (Container) HumanReadable

func (c Container) HumanReadable() string

func (Container) ID

func (c Container) ID() string

type ContainerDelta

type ContainerDelta struct {
	Time      time.Time
	Container Container
	ToDelete  bool
	Selected  bool
}

type ContainerDeltaSet

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

ContainerDeltaSet sorts ContainerDeltas by time, Container ID ascending

func (*ContainerDeltaSet) Add

func (cds *ContainerDeltaSet) Add(delta ContainerDelta)

func (ContainerDeltaSet) OrderedDeltas

func (cds ContainerDeltaSet) OrderedDeltas() []ContainerDelta

func (*ContainerDeltaSet) Size

func (cds *ContainerDeltaSet) Size() int

type ContainerListener

type ContainerListener struct {
	Cluster            string
	Namespace          string
	ContainerDeltaChan chan ContainerDelta
	StopChan           chan struct{}
	CleanupFunc        func()
}

type ContainerState

type ContainerState int
const (
	ContainerUnknown ContainerState = iota
	ContainerRunning
	ContainerTerminated
	ContainerWaiting
)

func (ContainerState) String

func (s ContainerState) String() string

type ContainerStatus

type ContainerStatus struct {
	State        ContainerState
	RunningSince time.Time
}

type Entity

type Entity struct {
	Container                                   Container
	IsCluster, IsNamespace, IsDeployment, IsPod bool
	LogScanner                                  *LogScanner
	LogScannerPending                           bool
	Terminated                                  bool
	Prefix                                      string
}

Entity represents a renderable & selectable kubernetes entity (cluster, namespace, deployment, pod, or container)

func (Entity) AssertIsContainer

func (e Entity) AssertIsContainer() error

func (Entity) EqualTo

func (e Entity) EqualTo(other Entity) bool

func (Entity) Equals

func (e Entity) Equals(other interface{}) bool

func (Entity) IsChildContainerOfCluster

func (e Entity) IsChildContainerOfCluster(cluster Entity) bool

func (Entity) IsChildContainerOfDeployment

func (e Entity) IsChildContainerOfDeployment(deployment Entity) bool

func (Entity) IsChildContainerOfNamespace

func (e Entity) IsChildContainerOfNamespace(namespace Entity) bool

func (Entity) IsChildContainerOfPod

func (e Entity) IsChildContainerOfPod(pod Entity) bool

func (Entity) IsContainer

func (e Entity) IsContainer() bool

func (Entity) IsSelected

func (e Entity) IsSelected() bool

IsSelected corresponds anything in the tree that is visually selected, i.e. has [x] in code, it corresponds to having a non-nil LogScanner if an entity isn't selected, there should be no logs displayed for it

func (Entity) Render

func (e Entity) Render() string

func (Entity) Type

func (e Entity) Type() string

type EntityTree

type EntityTree interface {
	// AddOrReplace adds or updates an entity in the tree
	// if a Container entity is added that doesn't have the relevant parents in the tree already,
	// the parents are also added
	// if a Container entity is added in a namespace that the tree isn't aware of yet, the namespace will
	// be inserted in alphabetical order
	AddOrReplace(entity Entity)

	// GetEntities returns all entities in the tree
	// within a cluster and namespace, sorted by deployment, pod, and container
	GetEntities() []Entity

	// GetVisibleEntities returns all entities that match the filter, any of their children match the filter,
	// or any of their parents match the filter. Returns in same order as GetEntities
	GetVisibleEntities(filter filter.Model) []Entity

	// GetClusterNamespaces returns all cluster namespaces
	GetClusterNamespaces() []ClusterNamespaces

	// AnyPendingContainers returns true if any container in the tree is pending
	AnyPendingContainers() bool

	// IsVisibleGivenFilter returns true if the entity or any of its children or parents match the filter
	IsVisibleGivenFilter(entity Entity, filter filter.Model) bool

	// GetContainerEntities returns all entities that are containers in the tree
	GetContainerEntities() []Entity

	// Remove removes an entity from the tree. If it is the last entity in a parent, the parent is also removed,
	// all the way up the tree
	Remove(entity Entity)

	// GetSelectionActions returns a map of container Entity's to a boolean indicating if they
	// should be activated or deactivated based on the current selection
	// If an Entity doesn't match the filter, it is not included in the map
	// If an Entity is pending, it is not included in the map
	// If the selection is a container, only the selection is returned
	// If it is a cluster, namespace, deployment, or pod, all children containers are returned
	// If the request is to activate, only running containers are returned
	GetSelectionActions(selectedEntity Entity, filter filter.Model) map[Entity]bool

	// GetEntity gets an entity by its Container
	GetEntity(container Container) *Entity

	// UpdatePrettyPrintPrefixes updates the Prefix field of all entities in the tree
	// such that the tree renders as a nice visual tree given the current filter
	UpdatePrettyPrintPrefixes(filter filter.Model)

	// ContainerToShortName returns a function mapping a container to its short name
	// Short names are unique identifiers given all the other containers in the tree
	ContainerToShortName(minCharsEachSide int) func(Container) (string, error)
}

EntityTree is a tree of entities with hierarchy Cluster > Namespace > Deployment > Pod > Container can contain multiple clusters

func NewEntityTree

func NewEntityTree(allClusterNamespaces []ClusterNamespaces) EntityTree

type Log

type Log struct {
	Timestamp time.Time
	Content   string
	Container Container
}

type LogScanner

type LogScanner struct {
	Container Container
	LogChan   chan Log
	ErrChan   chan error
	// contains filtered or unexported fields
}

func NewLogScanner

func NewLogScanner(container Container, scanner *bufio.Scanner, cancelK8sStream context.CancelFunc) LogScanner

func (LogScanner) Cancel

func (ls LogScanner) Cancel()

func (LogScanner) Equals

func (ls LogScanner) Equals(other LogScanner) bool

func (LogScanner) StartReadingLogs

func (ls LogScanner) StartReadingLogs()

StartReadingLogs starts a goroutine that reads logs from the scanner and sends them to the LogChan

type NewSelectorArgs

type NewSelectorArgs struct {
	Cluster    string
	Namespace  string
	Deployment string
	Pod        string
	Container  string
}

type PageLog

type PageLog struct {
	Log              Log
	ContainerNames   PageLogContainerNames
	CurrentName      string
	Timestamps       PageLogTimestamps
	CurrentTimestamp string
	Terminated       bool
}

func (PageLog) Equals

func (l PageLog) Equals(other interface{}) bool

func (PageLog) Render

func (l PageLog) Render() string

type PageLogContainer

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

func NewPageLogContainer

func NewPageLogContainer(ascending bool) *PageLogContainer

func (*PageLogContainer) AppendLog

func (lc *PageLogContainer) AppendLog(log PageLog, _ interface{})

func (PageLogContainer) Ascending

func (lc PageLogContainer) Ascending() bool

func (PageLogContainer) GetOrderedLogs

func (lc PageLogContainer) GetOrderedLogs() []PageLog

func (*PageLogContainer) RemoveAllLogs

func (lc *PageLogContainer) RemoveAllLogs()

func (*PageLogContainer) ToggleAscending

func (lc *PageLogContainer) ToggleAscending()

type PageLogContainerNames

type PageLogContainerNames struct {
	Short string
	Full  string
}

type PageLogTimestamps

type PageLogTimestamps struct {
	Short string
	Full  string
}

type Selectors

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

func NewSelectors

func NewSelectors(args NewSelectorArgs) (*Selectors, error)

func (Selectors) SelectContainer

func (m Selectors) SelectContainer(c Container) bool

type SinceTime

type SinceTime struct {
	UUID         string
	Time         time.Time
	LookbackMins int
}

func NewSinceTime

func NewSinceTime(t time.Time, lookbackMins int) SinceTime

func (SinceTime) TimeToNextUpdate

func (st SinceTime) TimeToNextUpdate() time.Duration

type ValidRegex

type ValidRegex struct {
	*regexp.Regexp
}

func NewValidRegex

func NewValidRegex(pattern string) (*ValidRegex, error)

Jump to

Keyboard shortcuts

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