opnictl

package
Version: v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package opnictl contains various utility and helper functions that are used by the Opnictl CLI.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCanceled           = fmt.Errorf("operation canceled")
	ErrNoEditor           = fmt.Errorf("EDITOR environment variable not set")
	ErrObjectDecodeFailed = fmt.Errorf("object decode failed")
)

Functions

func CheckBarFiller

func CheckBarFiller(
	waitCtx context.Context,
	success func(context.Context) bool,
) func(mpb.BarFiller) mpb.BarFiller

CheckBarFiller creates a mpb.BarFiller which can be used to replace a bar or spinner with a ✓ or ✗ status indicator based on the return value of the provided success function. The success function will be called once when the bar is completed or when waitCtx is canceled, whichever happens first.

func CreateClientOrDie

func CreateClientOrDie(opts ...ClientOption) (*api.Config, *rest.Config, client.Client)

CreateClientOrDie constructs a new controller-runtime client, or exit with a fatal error if an error occurs.

func CreateScheme

func CreateScheme() *runtime.Scheme

CreateScheme creates a new scheme with the types necessary for opnictl.

func EditObject added in v0.2.0

func EditObject(obj runtime.Object, scheme *runtime.Scheme) (runtime.Object, error)

EditObject edits an object in a temporary file using the user's default editor. It will retry on basic yaml decoding errors but will not validate the object against the schema. On success, the provided object will be modified in-place. If an error occurs, it will not be modified.

func ForEachStagingResource

func ForEachStagingResource(
	clientConfig *rest.Config,
	callback func(dynamic.ResourceInterface, *unstructured.Unstructured) error,
) (errors []string)

ForEachStagingResource will call the given callback function for each Kubernetes resource embedded in the binary. See the staging package for more details. This function will not abort if the callback returns an error, rather it will collect all errors that have been returned and return them all at once.

func LoadClientConfig

func LoadClientConfig(opts ...ClientOption) (*api.Config, *rest.Config)

LoadClientConfig loads the user's kubeconfig using the same logic as kubectl.

func WaitAndDisplayStatus added in v0.2.0

func WaitAndDisplayStatus(
	ctx context.Context,
	timeout time.Duration,
	k8sClient client.Client,
	obj StatusObject,
) error

Types

type ClientOption

type ClientOption func(*ClientOptions)

func WithConfigOverrides

func WithConfigOverrides(overrides *clientcmd.ConfigOverrides) ClientOption

WithConfigOverrides allows overriding specific kubeconfig fields from the user's loaded kubeconfig.

func WithExplicitPath added in v0.2.0

func WithExplicitPath(path string) ClientOption

type ClientOptions

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

ClientOptions can be passed to some of the functions in this package when creating clients and/or client configurations.

func (*ClientOptions) Apply

func (o *ClientOptions) Apply(opts ...ClientOption)

type StatusObject added in v0.2.0

type StatusObject interface {
	client.Object
	GetState() string
	GetConditions() []string
}

Jump to

Keyboard shortcuts

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