runner

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateInteractiveStreamOptions

func CreateInteractiveStreamOptions(streams IOStreams) (remotecommand.StreamOptions, func(term.SafeFunc) error)

CreateInteractiveStreamOptions constructs streaming configuration that attaches the default OS stdout, stderr, stdin, with a tty, and an additional function which should be used to wrap any interactive process that will make use of the tty.

Types

type AttachOptions

type AttachOptions struct {
	Namespace  string
	KubeConfig *rest.Config
	Name       string

	IO IOStreams

	// Lifecycle hook to notify when the state of the console changes
	Hook LifecycleHook
}

AttachOptions encapsulates the arguments to attach to a console

func (AttachOptions) WithDefaults

func (opts AttachOptions) WithDefaults() AttachOptions

WithDefaults sets any unset options to defaults

type Attacher

type Attacher interface {
	Attach(ctx context.Context, pod *corev1.Pod, containerName string, streams IOStreams) error
}

type AuthoriseOptions

type AuthoriseOptions struct {
	Namespace   string
	ConsoleName string
	Username    string
}

type ConsoleSlice

type ConsoleSlice []workloadsv1alpha1.Console

func (ConsoleSlice) Print

func (cs ConsoleSlice) Print(output io.Writer) error

type CreateOptions

type CreateOptions struct {
	Namespace      string
	Selector       string
	Timeout        time.Duration
	Reason         string
	Command        []string
	Attach         bool
	Noninteractive bool

	// Options only used when Attach is true
	KubeConfig *rest.Config
	IO         IOStreams

	// Lifecycle hook to notify when the state of the console changes
	Hook LifecycleHook
}

CreateOptions encapsulates the arguments to create a console

func (CreateOptions) WithDefaults

func (opts CreateOptions) WithDefaults() CreateOptions

WithDefaults sets any unset options to defaults

type DefaultLifecycleHook

type DefaultLifecycleHook struct {
	AttachingToPodFunc               func(*workloadsv1alpha1.Console) error
	ConsoleCreatedFunc               func(*workloadsv1alpha1.Console) error
	ConsoleRequiresAuthorisationFunc func(*workloadsv1alpha1.Console, *workloadsv1alpha1.ConsoleAuthorisationRule) error
	ConsoleReadyFunc                 func(*workloadsv1alpha1.Console) error
	TemplateFoundFunc                func(*workloadsv1alpha1.ConsoleTemplate) error
}

func (DefaultLifecycleHook) AttachingToConsole

func (d DefaultLifecycleHook) AttachingToConsole(c *workloadsv1alpha1.Console) error

func (DefaultLifecycleHook) ConsoleCreated

func (d DefaultLifecycleHook) ConsoleCreated(c *workloadsv1alpha1.Console) error

func (DefaultLifecycleHook) ConsoleReady

func (DefaultLifecycleHook) ConsoleRequiresAuthorisation

func (DefaultLifecycleHook) TemplateFound

type GetOptions

type GetOptions struct {
	Namespace   string
	ConsoleName string
}

type IOStreams

type IOStreams genericclioptions.IOStreams

Alias genericclioptions.IOStreams to avoid additional imports

type LifecycleHook

type LifecycleHook interface {
	AttachingToConsole(*workloadsv1alpha1.Console) error
	ConsoleCreated(*workloadsv1alpha1.Console) error
	ConsoleRequiresAuthorisation(*workloadsv1alpha1.Console, *workloadsv1alpha1.ConsoleAuthorisationRule) error
	ConsoleReady(*workloadsv1alpha1.Console) error
	TemplateFound(*workloadsv1alpha1.ConsoleTemplate) error
}

LifecycleHook provides a communication to react to console lifecycle changes

type ListOptions

type ListOptions struct {
	Namespace string
	Username  string
	Selector  string
	Output    io.Writer
}

type MultipleConsoleTemplateError added in v2.3.0

type MultipleConsoleTemplateError struct {
	ConsoleTemplates []workloadsv1alpha1.ConsoleTemplate
}

MultipleConsoleTemplateError is returned whenever our selector was too broad, and matched more than one ConsoleTemplate resource.

func (MultipleConsoleTemplateError) Error added in v2.3.0

type Options

type Options struct {
	Cmd     []string
	Timeout int
	Reason  string
	// Whether or not to enable a TTY for the console. Typically this
	// should be set to false but some execution environments, eg
	// Tekton, do not like attaching to TTY-enabled pods.
	Noninteractive bool
}

Options defines the parameters that can be set upon a new console

type Runner

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

Runner is responsible for managing the lifecycle of a console

func New

func New(cfg *rest.Config) (*Runner, error)

New builds a runner

func (*Runner) Attach

func (c *Runner) Attach(ctx context.Context, opts AttachOptions) error

Attach provides the ability to attach to a running console, given the console name

func (*Runner) Authorise

func (c *Runner) Authorise(ctx context.Context, opts AuthoriseOptions) error

func (*Runner) Create

Create attempts to create a console in the given in the given namespace after finding the a template using selectors.

func (*Runner) CreateResource

func (c *Runner) CreateResource(namespace string, template workloadsv1alpha1.ConsoleTemplate, opts Options) (*workloadsv1alpha1.Console, error)

CreateResource builds a console according to the supplied options and submits it to the API

func (*Runner) FindConsoleByName

func (c *Runner) FindConsoleByName(namespace, name string) (*workloadsv1alpha1.Console, error)

func (*Runner) FindTemplateBySelector

func (c *Runner) FindTemplateBySelector(namespace string, labelSelector string) (*workloadsv1alpha1.ConsoleTemplate, error)

FindTemplateBySelector will search for a template matching the given label selector and return errors if none or multiple are found (when the selector is too broad)

func (*Runner) Get

Get provides a standardised method to get a console

func (*Runner) GetAttachablePod

func (c *Runner) GetAttachablePod(ctx context.Context, csl *workloadsv1alpha1.Console) (*corev1.Pod, string, error)

GetAttachablePod returns an attachable pod for the given console

func (*Runner) List

func (c *Runner) List(ctx context.Context, opts ListOptions) (ConsoleSlice, error)

List is a wrapper around ListConsolesByLabelsAndUser that will output to a specified output. This functionality is intended to be used in a CLI setting, where you are usually outputting to os.Stdout.

func (*Runner) ListConsolesByLabelsAndUser

func (c *Runner) ListConsolesByLabelsAndUser(namespace, username, labelSelector string) (ConsoleSlice, error)

func (*Runner) WaitUntilReady

func (c *Runner) WaitUntilReady(ctx context.Context, createdCsl workloadsv1alpha1.Console, waitForAuthorisation bool) (*workloadsv1alpha1.Console, error)

WaitUntilReady will block until the console reaches a phase that indicates that it's ready to be attached to, or has failed. It will then block until an associated RoleBinding exists that contains the console user in its subject list. This RoleBinding gives the console user permission to attach to the pod.

Jump to

Keyboard shortcuts

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