model

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Registry = map[string]ResourceMeta{

	"charts": {
		DAO:      &dao.Chart{},
		Renderer: &render.Chart{},
	},
	"containers": {
		DAO:          &dao.Container{},
		Renderer:     &render.Container{},
		TreeRenderer: &xray.Container{},
	},
	"contexts": {
		DAO:      &dao.Context{},
		Renderer: &render.Context{},
	},
	"screendumps": {
		DAO:      &dao.ScreenDump{},
		Renderer: &render.ScreenDump{},
	},
	"rbac": {
		DAO:      &dao.Rbac{},
		Renderer: &render.Rbac{},
	},
	"policy": {
		DAO:      &dao.Policy{},
		Renderer: &render.Policy{},
	},
	"users": {
		DAO:      &dao.Subject{},
		Renderer: &render.Subject{},
	},
	"groups": {
		DAO:      &dao.Subject{},
		Renderer: &render.Subject{},
	},
	"portforwards": {
		DAO:      &dao.PortForward{},
		Renderer: &render.PortForward{},
	},
	"benchmarks": {
		DAO:      &dao.Benchmark{},
		Renderer: &render.Benchmark{},
	},
	"aliases": {
		DAO:      &dao.Alias{},
		Renderer: &render.Alias{},
	},

	"v1/endpoints": {
		Renderer: &render.Endpoints{},
	},
	"v1/events": {
		Renderer: &render.Event{},
	},
	"v1/pods": {
		DAO:          &dao.Pod{},
		Renderer:     &render.Pod{},
		TreeRenderer: &xray.Pod{},
	},
	"v1/namespaces": {
		Renderer: &render.Namespace{},
	},
	"v1/nodes": {
		DAO:      &dao.Node{},
		Renderer: &render.Node{},
	},
	"v1/services": {
		DAO:          &dao.Service{},
		Renderer:     &render.Service{},
		TreeRenderer: &xray.Service{},
	},
	"v1/serviceaccounts": {
		Renderer: &render.ServiceAccount{},
	},
	"v1/persistentvolumes": {
		Renderer: &render.PersistentVolume{},
	},
	"v1/persistentvolumeclaims": {
		Renderer: &render.PersistentVolumeClaim{},
	},

	"apps/v1/deployments": {
		DAO:          &dao.Deployment{},
		Renderer:     &render.Deployment{},
		TreeRenderer: &xray.Deployment{},
	},
	"apps/v1/replicasets": {
		Renderer:     &render.ReplicaSet{},
		TreeRenderer: &xray.ReplicaSet{},
	},
	"apps/v1/statefulsets": {
		DAO:          &dao.StatefulSet{},
		Renderer:     &render.StatefulSet{},
		TreeRenderer: &xray.StatefulSet{},
	},
	"apps/v1/daemonsets": {
		DAO:          &dao.DaemonSet{},
		Renderer:     &render.DaemonSet{},
		TreeRenderer: &xray.DaemonSet{},
	},

	"extensions/v1beta1/daemonsets": {
		Renderer: &render.DaemonSet{},
	},
	"extensions/v1beta1/ingresses": {
		Renderer: &render.Ingress{},
	},
	"extensions/v1beta1/networkpolicies": {
		Renderer: &render.NetworkPolicy{},
	},
	"networking.k8s.io/v1/networkpolicies": {
		Renderer: &render.NetworkPolicy{},
	},

	"batch/v1beta1/cronjobs": {
		DAO:      &dao.CronJob{},
		Renderer: &render.CronJob{},
	},
	"batch/v1/jobs": {
		DAO:      &dao.Job{},
		Renderer: &render.Job{},
	},

	"autoscaling/v1/horizontalpodautoscalers": {
		DAO:      &dao.HorizontalPodAutoscaler{},
		Renderer: &render.HorizontalPodAutoscaler{},
	},
	"autoscaling/v2beta1/horizontalpodautoscalers": {
		DAO:      &dao.HorizontalPodAutoscaler{},
		Renderer: &render.HorizontalPodAutoscaler{},
	},
	"autoscaling/v2beta2/horizontalpodautoscalers": {
		DAO:      &dao.HorizontalPodAutoscaler{},
		Renderer: &render.HorizontalPodAutoscaler{},
	},

	"apiextensions.k8s.io/v1/customresourcedefinitions": {
		Renderer: &render.CustomResourceDefinition{},
	},
	"apiextensions.k8s.io/v1beta1/customresourcedefinitions": {
		Renderer: &render.CustomResourceDefinition{},
	},

	"storage.k8s.io/v1/storageclasses": {
		Renderer: &render.StorageClass{},
	},

	"policy/v1beta1/poddisruptionbudgets": {
		Renderer: &render.PodDisruptionBudget{},
	},

	"rbac.authorization.k8s.io/v1/clusterroles": {
		DAO:      &dao.Rbac{},
		Renderer: &render.ClusterRole{},
	},
	"rbac.authorization.k8s.io/v1/clusterrolebindings": {
		Renderer: &render.ClusterRoleBinding{},
	},
	"rbac.authorization.k8s.io/v1/roles": {
		Renderer: &render.Role{},
	},
	"rbac.authorization.k8s.io/v1/rolebindings": {
		Renderer: &render.RoleBinding{},
	},
}

Registry tracks resources metadata. BOZO!! Break up deps and merge into single registrar

Functions

func FQN

func FQN(ns, n string) string

FQN returns a fully qualified resource name.

func MetaFQN

func MetaFQN(m metav1.ObjectMeta) string

MetaFQN returns a fully qualified resource name.

func Truncate

func Truncate(str string, width int) string

Truncate a string to the given l and suffix ellipsis if needed.

Types

type Cluster

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

Cluster represents a kubernetes resource.

func NewCluster

func NewCluster(c client.Connection, mx MetricsServer) *Cluster

NewCluster returns a new cluster info resource.

func NewClusterWithArgs

func NewClusterWithArgs(c client.Connection, mx MetricsServer) *Cluster

NewClusterWithArgs for tests only!

func (*Cluster) ClusterName

func (c *Cluster) ClusterName() string

ClusterName returns the cluster name.

func (*Cluster) ContextName

func (c *Cluster) ContextName() string

ContextName returns the context name.

func (*Cluster) Metrics

Metrics gathers node level metrics and compute utilization percentages.

func (*Cluster) UserName

func (c *Cluster) UserName() string

UserName returns the user name.

func (*Cluster) Version

func (c *Cluster) Version() string

Version returns the current K8s cluster version.

type Component

type Component interface {
	Primitive
	Igniter
	Hinter
}

Component represents a ui component

type Cruder

type Cruder interface {
	// List returns a collection of resources.
	List(ctx context.Context, ns string) ([]runtime.Object, error)

	// Get returns a resource instance.
	Get(ctx context.Context, path string) (runtime.Object, error)
}

Cruder performs crud operations.

type Describer

type Describer interface {
	// ToYAML return resource yaml.
	ToYAML(ctx context.Context, path string) (string, error)

	// Describe returns a resource description.
	Describe(client client.Connection, gvr, path string) (string, error)
}

Describer represents a resource describer.

type Hint

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

Hint represent a hint model.

func NewHint

func NewHint() *Hint

NewHint return new hint model.

func (*Hint) AddListener

func (h *Hint) AddListener(l HintListener)

AddListener adds a hint listener.

func (*Hint) Peek

func (h *Hint) Peek() MenuHints

Peek returns the model data.

func (*Hint) RemoveListener

func (h *Hint) RemoveListener(l HintListener)

RemoveListener deletes a listener.

func (*Hint) SetHints

func (h *Hint) SetHints(hh MenuHints)

SetHints set model hints.

type HintListener

type HintListener interface {
	HintsChanged(MenuHints)
}

HintListener represents a menu hints listener.

type Hinter

type Hinter interface {
	// Hints returns a collection of menu hints.
	Hints() MenuHints
}

Hinter represent a menu mnemonic provider.

type Igniter

type Igniter interface {
	// Start starts a component.
	Init(ctx context.Context) error

	// Start starts a component.
	Start()

	// Stop terminates a component.
	Stop()
}

Igniter represents a runnable view.

type Lister

type Lister interface {
	Cruder

	// Init initializes a resource.
	Init(ns, gvr string, f dao.Factory)
}

Lister represents a resource lister.

type Log

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

Log represents a resource logger.

func NewLog

func NewLog(gvr client.GVR, msg string, opts dao.LogOptions, timeOut time.Duration) *Log

NewLog returns a new model.

func (*Log) AddListener

func (l *Log) AddListener(listener LogsListener)

AddListener adds a new model listener.

func (*Log) Append

func (l *Log) Append(line string)

Append adds a log line.

func (*Log) Clear

func (l *Log) Clear()

Clear the logs.

func (*Log) ClearFilter

func (l *Log) ClearFilter()

ClearFilter resets the log filter if any.

func (*Log) Filter

func (l *Log) Filter(q string) error

Filter filters the model using either fuzzy or regexp.

func (*Log) GetContainer

func (l *Log) GetContainer() string

GetContainer returns the resource container if any or "" otherwise.

func (*Log) GetPath

func (l *Log) GetPath() string

GetPath returns resource path.

func (*Log) Init

func (l *Log) Init(f dao.Factory)

Init initializes the model.

func (*Log) Notify

func (l *Log) Notify(timedOut bool)

Notify fires of notifications to the listeners.

func (*Log) RemoveListener

func (l *Log) RemoveListener(listener LogsListener)

RemoveListener delete a listener from the lisl.

func (*Log) Set

func (l *Log) Set(lines []string)

Set sets the log lines (for testing only!)

func (*Log) Start

func (l *Log) Start()

Start initialize log tailer.

func (*Log) Stop

func (l *Log) Stop()

Stop terminates log tailing.

type LogsListener

type LogsListener interface {
	// LogChanged notifies the model changed.
	LogChanged([]string)

	// LogCleanred indicates logs are cleared.
	LogCleared()

	// LogFailed indicates a log failure.
	LogFailed(error)
}

LogsListener represents a log model listener.

type MenuHint struct {
	Mnemonic    string
	Description string
	Visible     bool
}

MenuHint represents keyboard mnemonic.

func (m MenuHint) IsBlank() bool

IsBlank checks if menu hint is a place holder.

type MenuHints []MenuHint

MenuHints represents a collection of hints.

func (h MenuHints) Len() int
func (h MenuHints) Less(i, j int) bool
func (h MenuHints) Swap(i, j int)

type MetricsServer

MetricsServer gather metrics information from pods and nodes.

type MetricsService

type MetricsService interface {
	HasMetrics() bool
	FetchNodesMetrics() (*mv1beta1.NodeMetricsList, error)
	FetchPodsMetrics(ns string) (*mv1beta1.PodMetricsList, error)
}

MetricsService calls the metrics server for metrics info.

type Primitive

type Primitive interface {
	tview.Primitive

	// Name returns the view name.
	Name() string
}

Primitive represents a UI primitive.

type Renderer

type Renderer interface {
	// Render converts raw resources to tabular data.
	Render(o interface{}, ns string, row *render.Row) error

	// Header returns the resource header.
	Header(ns string) render.HeaderRow

	// ColorerFunc returns a row colorer function.
	ColorerFunc() render.ColorerFunc
}

Renderer represents a resource renderer.

type ResourceMeta

type ResourceMeta struct {
	DAO          dao.Accessor
	Renderer     Renderer
	TreeRenderer TreeRenderer
}

ResourceMeta represents model info about a resource.

type Stack

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

Stack represents a stacks of components.

func NewStack

func NewStack() *Stack

NewStack returns a new initialized stack.

func (*Stack) AddListener

func (s *Stack) AddListener(l StackListener)

AddListener registers a stack listener.

func (*Stack) Clear

func (s *Stack) Clear()

Clear clear out the stack using pops.

func (*Stack) Dump

func (s *Stack) Dump()

Dump prints out the stack.

func (*Stack) Empty

func (s *Stack) Empty() bool

Empty returns true if the stack is empty.

func (*Stack) Flatten

func (s *Stack) Flatten() []string

Flatten returns a string representation of the component stack.

func (*Stack) IsLast

func (s *Stack) IsLast() bool

IsLast indicates if stack only has one item left.

func (*Stack) Peek

func (s *Stack) Peek() []Component

Peek returns stack state.

func (*Stack) Pop

func (s *Stack) Pop() (Component, bool)

Pop removed the top item and returns it.

func (*Stack) Previous

func (s *Stack) Previous() Component

Previous returns the previous component if any.

func (*Stack) Push

func (s *Stack) Push(c Component)

Push adds a new item.

func (*Stack) RemoveListener

func (s *Stack) RemoveListener(l StackListener)

RemoveListener removes a listener.

func (*Stack) Top

func (s *Stack) Top() Component

Top returns the top most item or nil if the stack is empty.

type StackAction

type StackAction int

StackAction represents an action on the stack.

const (
	// StackPush denotes an add on the stack.
	StackPush StackAction = 1 << iota

	// StackPop denotes a delete on the stack.
	StackPop
)

type StackEvent

type StackEvent struct {
	// Kind represents the event condition.
	Action StackAction

	// Item represents the targeted item.
	Component Component
}

StackEvent represents an operation on a view stack.

type StackListener

type StackListener interface {
	// StackPushed indicates a new item was added.
	StackPushed(Component)

	// StackPopped indicates an item was deleted
	StackPopped(old, new Component)

	// StackTop indicates the top of the stack
	StackTop(Component)
}

StackListener represents a stack listener.

type Table

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

Table represents a table model.

func NewTable

func NewTable(gvr string) *Table

NewTable returns a new table model.

func (*Table) AddListener

func (t *Table) AddListener(l TableListener)

AddListener adds a new model listener.

func (*Table) ClusterWide

func (t *Table) ClusterWide() bool

ClusterWide checks if resource is scope for all namespaces.

func (*Table) Delete

func (t *Table) Delete(ctx context.Context, path string, cascade, force bool) error

Delete deletes a resource.

func (*Table) Describe

func (t *Table) Describe(ctx context.Context, path string) (string, error)

Describe describes a given resource.

func (*Table) Empty

func (t *Table) Empty() bool

Empty return true if no model data.

func (*Table) Get

func (t *Table) Get(ctx context.Context, path string) (runtime.Object, error)

Get returns a resource instance if found, else an error.

func (*Table) GetNamespace

func (t *Table) GetNamespace() string

GetNamespace returns the model namespace.

func (*Table) InNamespace

func (t *Table) InNamespace(ns string) bool

InNamespace checks if current namespace matches desired namespace.

func (*Table) Peek

func (t *Table) Peek() render.TableData

Peek returns model data.

func (*Table) Refresh

func (t *Table) Refresh(ctx context.Context)

Refresh update the model now.

func (*Table) RemoveListener

func (t *Table) RemoveListener(l TableListener)

RemoveListener delete a listener from the list.

func (*Table) SetInstance

func (t *Table) SetInstance(path string)

SetInstance sets a single entry table.

func (*Table) SetNamespace

func (t *Table) SetNamespace(ns string)

SetNamespace sets up model namespace.

func (*Table) SetRefreshRate

func (t *Table) SetRefreshRate(d time.Duration)

SetRefreshRate sets model refresh duration.

func (*Table) ToYAML

func (t *Table) ToYAML(ctx context.Context, path string) (string, error)

ToYAML returns a resource yaml.

func (*Table) Watch

func (t *Table) Watch(ctx context.Context)

Watch initiates model updates.

type TableListener

type TableListener interface {
	// TableDataChanged notifies the model data changed.
	TableDataChanged(render.TableData)

	// TableLoadFailed notifies the load failed.
	TableLoadFailed(error)
}

TableListener represents a table model listener.

type Tree

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

Tree represents a tree model.

func NewTree

func NewTree(gvr string) *Tree

NewTree returns a new model.

func (*Tree) AddListener

func (t *Tree) AddListener(l TreeListener)

AddListener adds a listener.

func (*Tree) ClearFilter

func (t *Tree) ClearFilter()

ClearFilter clears out active filter.

func (*Tree) ClusterWide

func (t *Tree) ClusterWide() bool

ClusterWide checks if resource is scope for all namespaces.

func (*Tree) Describe

func (t *Tree) Describe(ctx context.Context, gvr, path string) (string, error)

Describe describes a given resource.

func (*Tree) Empty

func (t *Tree) Empty() bool

Empty return true if no model data.

func (*Tree) GetNamespace

func (t *Tree) GetNamespace() string

GetNamespace returns the model namespace.

func (*Tree) InNamespace

func (t *Tree) InNamespace(ns string) bool

InNamespace checks if current namespace matches desired namespace.

func (*Tree) Peek

func (t *Tree) Peek() *xray.TreeNode

Peek returns model data.

func (*Tree) Refresh

func (t *Tree) Refresh(ctx context.Context)

Refresh update the model now.

func (*Tree) RemoveListener

func (t *Tree) RemoveListener(l TreeListener)

RemoveListener delete a listener.

func (*Tree) SetFilter

func (t *Tree) SetFilter(q string)

SetFilter sets the current filter.

func (*Tree) SetNamespace

func (t *Tree) SetNamespace(ns string)

SetNamespace sets up model namespace.

func (*Tree) SetRefreshRate

func (t *Tree) SetRefreshRate(d time.Duration)

SetRefreshRate sets model refresh duration.

func (*Tree) ToYAML

func (t *Tree) ToYAML(ctx context.Context, gvr, path string) (string, error)

ToYAML returns a resource yaml.

func (*Tree) Watch

func (t *Tree) Watch(ctx context.Context)

Watch initiates model updates.

type TreeListener

type TreeListener interface {
	// TreeChanged notifies the model data changed.
	TreeChanged(*xray.TreeNode)

	// TreeLoadFailed notifies the load failed.
	TreeLoadFailed(error)
}

TreeListener represents a tree model listener.

type TreeRenderer

type TreeRenderer interface {
	Render(ctx context.Context, ns string, o interface{}) error
}

TreeRenderer represents an xray node.

Jump to

Keyboard shortcuts

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