cliutil

package
v0.5.3 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: 31 Imported by: 0

Documentation

Overview

package opni 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

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 JoinKeyValuePairs

func JoinKeyValuePairs(pairs map[string]string) []string

func LoadClientConfig

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

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

func LoadConfigObjectsOrDie

func LoadConfigObjectsOrDie(
	configLocation string,
	lg logger.ExtendedSugaredLogger,
) meta.ObjectList

func ParseKeyValuePairs

func ParseKeyValuePairs(pairs []string) (map[string]string, error)

Parses strings of the form "key=value" into a map[string]string.

func RenderAccessMatrix

func RenderAccessMatrix(am AccessMatrix) string

func RenderBootstrapToken

func RenderBootstrapToken(token *core.BootstrapToken) string

func RenderBootstrapTokenList

func RenderBootstrapTokenList(list *core.BootstrapTokenList) string

func RenderCertInfoChain

func RenderCertInfoChain(chain []*core.CertInfo) string

func RenderClusterList

func RenderClusterList(list *core.ClusterList, stats *cortexadmin.UserIDStatsList) string

func RenderRole

func RenderRole(role *core.Role) string

func RenderRoleBinding

func RenderRoleBinding(binding *core.RoleBinding) string

func RenderRoleBindingList

func RenderRoleBindingList(list *core.RoleBindingList) string

func RenderRoleList

func RenderRoleList(list *core.RoleList) string

func WaitAndDisplayStatus

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

Types

type AccessMatrix

type AccessMatrix struct {
	// List of users (in the order they will appear in the table)
	Users []string
	// Set of known clusters (rules referencing nonexistent clusters are marked)
	KnownClusters map[string]struct{}
	// Map of tenant IDs to a set of users that have access to the tenant
	ClustersToUsers map[string]map[string]struct{}
}

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

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

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