kubeba

package module
v0.0.0-...-af3e112 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoPodInRunningState emitted when TCP connection is ok but no pods are currently ready to accept the request
	ErrNoPodInRunningState = errors.New("no pod is in running state")
	// ErrNoPodsMatchedQuery emitted when TCP connection is ok but no pods matched query (can happen also during scale)
	ErrNoPodsMatchedQuery = errors.New("no pods matched query")
)

Functions

func ReadLinesFromKeyboard

func ReadLinesFromKeyboard(ctx context.Context, chanTimeout time.Duration) <-chan string

ReadLinesFromKeyboard will return a channel that will emit full lines Notice: setting Stdin.SetReadDeadline is not always possible (depends OS and stdin type such as PIPE)

the method will ignore the error,
if you need to use stdin on other context
read from returned channel until it is closed

func Run

func Run()

Run the cli

Types

type AsyncChanBundle

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

AsyncChanBundle is a bundle to match some k8s apis

func NewAsyncChanBundle

func NewAsyncChanBundle() *AsyncChanBundle

NewAsyncChanBundle constructor

func (*AsyncChanBundle) Error

func (a *AsyncChanBundle) Error(err error)

Error will stop the bundle and send error to err channel

func (*AsyncChanBundle) GetErrorChannel

func (a *AsyncChanBundle) GetErrorChannel() <-chan error

GetErrorChannel returns error channel as readonly to write to the channel use .Error method

func (*AsyncChanBundle) GetReadyChannel

func (a *AsyncChanBundle) GetReadyChannel() chan struct{}

GetReadyChannel returns the ready channel

func (*AsyncChanBundle) GetStopChannel

func (a *AsyncChanBundle) GetStopChannel() <-chan struct{}

GetStopChannel returns the stop channel as readonly

func (*AsyncChanBundle) RaceCloseTimer

func (a *AsyncChanBundle) RaceCloseTimer(ctx context.Context, duration time.Duration) (isClosed bool)

RaceCloseTimer will emit the first of ctx.Done, duration or bundle stop

func (*AsyncChanBundle) Ready

func (a *AsyncChanBundle) Ready()

Ready blocks until reports ready

func (*AsyncChanBundle) Stop

func (a *AsyncChanBundle) Stop()

Stop the bundle, can be called multiple times

func (*AsyncChanBundle) WaitReady

func (a *AsyncChanBundle) WaitReady(ctx context.Context) error

WaitReady waits until bundle reports it is ready or cancelled

type CliContext

type CliContext struct {
	Ctx     *cli.Context
	KClient *KubernetesClient
	Scope   Scope

	Pods []v1.Pod

	App labelKeyValue
	// contains filtered or unexported fields
}

CliContext is the main api for kubeba currently kubeba is coupled to run as CLI program

func NewFromContext

func NewFromContext(ctx *cli.Context) *CliContext

NewFromContext creates CLI context from urfave cli

func (*CliContext) FilterPods

func (cc *CliContext) FilterPods()

FilterPods will clear pods which isnt in scope k8s api doesn't allow complex conditions so it has to be done on the client side

func (*CliContext) Load

func (cc *CliContext) Load() error

Load will initialize all relevant pods

func (*CliContext) LoadApp

func (cc *CliContext) LoadApp() (err error)

LoadApp load relevant deployment

func (*CliContext) LoadNamespace

func (cc *CliContext) LoadNamespace() (err error)

LoadNamespace will load a namespace if more than one found \ exists \ matched query

func (*CliContext) LoadPods

func (cc *CliContext) LoadPods() error

LoadPods will force to reload pods list

type DeletePod

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

DeletePod holds info for delete pod request

func NewDeletePod

func NewDeletePod(pod v1.Pod, client *KubernetesClient, noValidate bool, quickKill bool) *DeletePod

NewDeletePod Create delete pod request

func (*DeletePod) Start

func (r *DeletePod) Start() error

Start delete pod

type KubernetesClient

type KubernetesClient struct {
	*kubernetes.Clientset
	Config *rest.Config
}

KubernetesClient wraps google k8s client

func NewClient

func NewClient(kubeconfig string) (*KubernetesClient, error)

NewClient generate wrapped k8s client

func (*KubernetesClient) GetPodsForScope

func (k *KubernetesClient) GetPodsForScope(scope Scope) ([]v1.Pod, error)

GetPodsForScope filter only relevant pods matching scope

func (*KubernetesClient) WatchPod

func (k *KubernetesClient) WatchPod(pod v1.Pod, cancelChannel <-chan struct{}) (chan v1.Pod, error)

WatchPod is none blocking method that will notify when pod state is changing if pod is removed or there's an error, the returned channel will close

type PortForward

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

PortForward instance of port forward to pod instance

func NewPortForward

func NewPortForward(pod v1.Pod, client *KubernetesClient, localPort int, podPort int) *PortForward

NewPortForward constructs port forward request (but wont start it yet)

func (*PortForward) Start

func (p *PortForward) Start(bundle *AsyncChanBundle, stdout io.Writer, stderr io.Writer)

Start the port forward, blocks until channel is closed or error happened.

type RemoteExec

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

RemoteExec for specific exec instance

func NewRemoteExec

func NewRemoteExec(pod v1.Pod, client *KubernetesClient, cmd string) *RemoteExec

NewRemoteExec creates remote exec instance but wont start yet

func (*RemoteExec) Start

func (r *RemoteExec) Start(tty bool) error

Start the remote exec

type RemoteExecOptions

type RemoteExecOptions struct {
	Cmd         []string
	Container   string
	Pod         v1.Pod
	Tty         bool
	Interactive bool
}

RemoteExecOptions for RemoteExec

type Scope

type Scope struct {
	Namespace string
	// name contains and not equals
	FreeName string
	Labels   []string
	Fields   []string
	// since k8s doesn't support OR condition for fields (fieldA=x OR fieldB=y)
	// this will perform the or condition logically inside the app
	OrLabels map[string]string
	OrFields map[string]string
}

Scope filters all the pods in the cluster to a specific app / deployment

func (*Scope) AddField

func (s *Scope) AddField(expression string)

AddField to filter

func (*Scope) AddLabel

func (s *Scope) AddLabel(expression string)

AddLabel to filter

func (*Scope) AddOrField

func (s *Scope) AddOrField(key string, value string)

AddOrField isn't supported by k8s and will happen on client side

func (*Scope) AddOrLabel

func (s *Scope) AddOrLabel(key string, value string)

AddOrLabel isn't supported by k8s and will happen on client side

func (*Scope) BuildListOptions

func (s *Scope) BuildListOptions() (options v1.ListOptions)

BuildListOptions converts the scope options to k8s api request

func (*Scope) IsPodInScope

func (s *Scope) IsPodInScope(pod v1Core.Pod) bool

IsPodInScope checks if a specific pod belongs to scope since some filters can only happen on client side, this is needed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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