factory

package
v0.5.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package factory implements the logic to initialize common objects for liqoctl commands.

Index

Constants

View Source
const FlagNamespace = "namespace"

FlagNamespace -> the name of the namespace flag.

Variables

This section is empty.

Functions

func Silent

func Silent(o *options)

Silent disables the output of informational messages during the initialization.

func WithScopedPrinter

func WithScopedPrinter(o *options)

WithScopedPrinter marks the generated printer as scoped.

Types

type Factory

type Factory struct {

	// Printer is the object used to output messages in the appropriate format.
	Printer *Printer
	// Whether to add a scope to the printer (i.e., local/remote).
	ScopedPrinter bool

	// Namespace is the namespace that the user has requested with the "--namespace" / "-n" flag, if registered (alternative to LiqoNamespace).
	Namespace string

	// LiqoNamespace is the namespace that the user has requested with the "--namespace" / "-n" flag, if registered (alternative to Namespace).
	LiqoNamespace string

	// RESTConfig is a Kubernetes REST config that contains the user's authentication and access configuration.
	RESTConfig *rest.Config

	// crClient is the controller runtime client.
	CRClient client.Client

	// kubeClient is a Kubernetes clientset for interacting with the base Kubernetes APIs.
	KubeClient kubernetes.Interface
	// contains filtered or unexported fields
}

Factory provides a set of clients and configurations to authenticate and access a target Kubernetes cluster. Factory will ensure that its fields are populated and valid during command execution.

func NewForLocal

func NewForLocal() *Factory

NewForLocal returns a new initialized Factory, to interact with a remote cluster.

func NewForRemote

func NewForRemote() *Factory

NewForRemote returns a new initialized Factory, to interact with a remote cluster.

func (*Factory) AddFlags

func (f *Factory) AddFlags(flags *pflag.FlagSet, register completionFuncRegisterer)

AddFlags registers the flags to interact with the Kubernetes access options, and the corresponding completion functions.

func (*Factory) AddLiqoNamespaceFlag

func (f *Factory) AddLiqoNamespaceFlag(flags *pflag.FlagSet)

AddLiqoNamespaceFlag registers the flag to select the Liqo namespace (alternative to AddNamespaceFlag).

func (*Factory) AddNamespaceFlag

func (f *Factory) AddNamespaceFlag(flags *pflag.FlagSet)

AddNamespaceFlag registers the flag to select the target namespace (alternative to AddLiqoNamespaceFlag).

func (*Factory) HelmClient

func (f *Factory) HelmClient(s ...*pterm.SpinnerPrinter) helm.Client

HelmClient returns an Helm client, initializing it if necessary. In case of error, it outputs the error (through the spinner if provided, or leveraging the printer) and exits.

func (*Factory) HelmClientOrError

func (f *Factory) HelmClientOrError() (helm.Client, error)

HelmClientOrError returns an Helm client, initializing it if necessary.

func (*Factory) Initialize

func (f *Factory) Initialize(opts ...Options) (err error)

Initialize populates the object based on the provided flags.

type Options

type Options func(*options)

Options represents an option for the initialize function.

type Printer

type Printer struct {
	Info    *pterm.PrefixPrinter
	Success *pterm.PrefixPrinter
	Warning *pterm.PrefixPrinter
	Error   *pterm.PrefixPrinter
	// contains filtered or unexported fields
}

Printer manages all kinds of outputs.

func NewFakePrinter

func NewFakePrinter(writer io.Writer) *Printer

NewFakePrinter returns a new printer to be used in tests.

func (*Printer) CheckErr

func (p *Printer) CheckErr(err error, s ...*pterm.SpinnerPrinter)

CheckErr prints a user friendly error and exits with a non-zero exit code. If the spinner it is provided, then it is leveraged to print the message, otherwise it outputs the message through the printer or, if nil, to STDERR.

func (*Printer) StartSpinner

func (p *Printer) StartSpinner(text ...interface{}) *pterm.SpinnerPrinter

StartSpinner starts a new spinner.

func (*Printer) Verbosef

func (p *Printer) Verbosef(format string, args ...interface{})

Verbosef outputs verbose messages guarded by the corresponding flag.

Jump to

Keyboard shortcuts

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