genericclioptions

package
v0.0.0-...-db5eef7 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package genericclioptions contains flags which can be added to you command, bound, completed, and produce useful helper functions. Nothing in this package can depend on kube/kube

Index

Constants

View Source
const ChangeCauseAnnotation = "kubernetes.io/change-cause"

ChangeCauseAnnotation is the annotation indicating a guess at "why" something was changed

Variables

This section is empty.

Functions

func IsNoCompatiblePrinterError

func IsNoCompatiblePrinterError(err error) bool

Types

type ChangeCauseRecorder

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

ChangeCauseRecorder annotates a "change-cause" to an input runtime object

func (*ChangeCauseRecorder) MakeRecordMergePatch

func (r *ChangeCauseRecorder) MakeRecordMergePatch(obj runtime.Object) ([]byte, error)

MakeRecordMergePatch produces a merge patch for updating the recording annotation.

func (*ChangeCauseRecorder) Record

func (r *ChangeCauseRecorder) Record(obj runtime.Object) error

Record annotates a "change-cause" to a given info if either "shouldRecord" is true, or the resource info previously contained a "change-cause" annotation.

type ConfigFlags

type ConfigFlags struct {
	CacheDir   *string
	KubeConfig *string

	// config flags
	ClusterName      *string
	AuthInfoName     *string
	Context          *string
	Namespace        *string
	APIServer        *string
	Insecure         *bool
	CertFile         *string
	KeyFile          *string
	CAFile           *string
	BearerToken      *string
	Impersonate      *string
	ImpersonateGroup *[]string
	Username         *string
	Password         *string
	Timeout          *string
}

ConfigFlags composes the set of values necessary for obtaining a REST client config

func NewConfigFlags

func NewConfigFlags() *ConfigFlags

NewConfigFlags returns ConfigFlags with default values set

func (*ConfigFlags) AddFlags

func (f *ConfigFlags) AddFlags(flags *pflag.FlagSet)

AddFlags binds client configuration flags to a given flagset

func (*ConfigFlags) ToDiscoveryClient

func (f *ConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

ToDiscoveryClient implements RESTClientGetter. Expects the AddFlags method to have been called. Returns a CachedDiscoveryInterface using a computed RESTConfig.

func (*ConfigFlags) ToRESTConfig

func (f *ConfigFlags) ToRESTConfig() (*rest.Config, error)

ToRESTConfig implements RESTClientGetter. Returns a REST client configuration based on a provided path to a .kubeconfig file, loading rules, and config flag overrides. Expects the AddFlags method to have been called.

func (*ConfigFlags) ToRESTMapper

func (f *ConfigFlags) ToRESTMapper() (meta.RESTMapper, error)

ToRESTMapper returns a mapper.

func (*ConfigFlags) ToRawKubeConfigLoader

func (f *ConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig

ToRawKubeConfigLoader binds config flag values to config overrides Returns an interactive clientConfig if the password flag is enabled, or a non-interactive clientConfig otherwise.

func (*ConfigFlags) WithDeprecatedPasswordFlag

func (f *ConfigFlags) WithDeprecatedPasswordFlag() *ConfigFlags

WithDeprecatedPasswordFlag enables the username and password config flags

type FileNameFlags

type FileNameFlags struct {
	Usage string

	Filenames *[]string
	Recursive *bool
}

Usage of this struct by itself is discouraged. These flags are composed by ResourceBuilderFlags which should be used instead.

func (*FileNameFlags) AddFlags

func (o *FileNameFlags) AddFlags(flags *pflag.FlagSet)

func (*FileNameFlags) ToOptions

func (o *FileNameFlags) ToOptions() resource.FilenameOptions

type IOStreams

type IOStreams struct {
	// In think, os.Stdin
	In io.Reader
	// Out think, os.Stdout
	Out io.Writer
	// ErrOut think, os.Stderr
	ErrOut io.Writer
}

IOStreams provides the standard names for iostreams. This is useful for embedding and for unit testing. Inconsistent and different names make it hard to read and review code

func NewTestIOStreams

func NewTestIOStreams() (IOStreams, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer)

NewTestIOStreams returns a valid IOStreams and in, out, errout buffers for unit tests

func NewTestIOStreamsDiscard

func NewTestIOStreamsDiscard() IOStreams

NewTestIOStreamsDiscard returns a valid IOStreams that just discards

type JSONYamlPrintFlags

type JSONYamlPrintFlags struct {
}

JSONYamlPrintFlags provides default flags necessary for json/yaml printing. Given the following flag values, a printer can be requested that knows how to handle printing based on these values.

func NewJSONYamlPrintFlags

func NewJSONYamlPrintFlags() *JSONYamlPrintFlags

NewJSONYamlPrintFlags returns flags associated with yaml or json printing, with default values set.

func (*JSONYamlPrintFlags) AddFlags

func (f *JSONYamlPrintFlags) AddFlags(c *cobra.Command)

AddFlags receives a *cobra.Command reference and binds flags related to JSON or Yaml printing to it

func (*JSONYamlPrintFlags) AllowedFormats

func (f *JSONYamlPrintFlags) AllowedFormats() []string

func (*JSONYamlPrintFlags) ToPrinter

func (f *JSONYamlPrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrinter, error)

ToPrinter receives an outputFormat and returns a printer capable of handling --output=(yaml|json) printing. Returns false if the specified outputFormat does not match a supported format. Supported Format types can be found in pkg/printers/printers.go

type NamePrintFlags

type NamePrintFlags struct {
	// Operation describes the name of the action that
	// took place on an object, to be included in the
	// finalized "successful" message.
	Operation string
}

NamePrintFlags provides default flags necessary for printing a resource's fully-qualified Kind.group/name, or a successful message about that resource if an Operation is provided.

func NewNamePrintFlags

func NewNamePrintFlags(operation string) *NamePrintFlags

NewNamePrintFlags returns flags associated with --name printing, with default values set.

func (*NamePrintFlags) AddFlags

func (f *NamePrintFlags) AddFlags(c *cobra.Command)

AddFlags receives a *cobra.Command reference and binds flags related to name printing to it

func (*NamePrintFlags) AllowedFormats

func (f *NamePrintFlags) AllowedFormats() []string

func (*NamePrintFlags) Complete

func (f *NamePrintFlags) Complete(successTemplate string) error

func (*NamePrintFlags) ToPrinter

func (f *NamePrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrinter, error)

ToPrinter receives an outputFormat and returns a printer capable of handling --output=name printing. Returns false if the specified outputFormat does not match a supported format. Supported format types can be found in pkg/printers/printers.go

type NoCompatiblePrinterError

type NoCompatiblePrinterError struct {
	OutputFormat   *string
	AllowedFormats []string
	Options        interface{}
}

func (NoCompatiblePrinterError) Error

func (e NoCompatiblePrinterError) Error() string

type NoopRecorder

type NoopRecorder struct{}

NoopRecorder does nothing. It is a "do nothing" that can be returned so code doesn't switch on it.

func (NoopRecorder) MakeRecordMergePatch

func (r NoopRecorder) MakeRecordMergePatch(obj runtime.Object) ([]byte, error)

MakeRecordMergePatch implements Recorder

func (NoopRecorder) Record

func (r NoopRecorder) Record(obj runtime.Object) error

Record implements Recorder

type PrintFlags

type PrintFlags struct {
	JSONYamlPrintFlags *JSONYamlPrintFlags
	NamePrintFlags     *NamePrintFlags

	TypeSetterPrinter *printers.TypeSetterPrinter

	OutputFormat *string
}

PrintFlags composes common printer flag structs used across all commands, and provides a method of retrieving a known printer based on flag values provided.

func NewPrintFlags

func NewPrintFlags(operation string) *PrintFlags

func (*PrintFlags) AddFlags

func (f *PrintFlags) AddFlags(cmd *cobra.Command)

func (*PrintFlags) AllowedFormats

func (f *PrintFlags) AllowedFormats() []string

func (*PrintFlags) Complete

func (f *PrintFlags) Complete(successTemplate string) error

func (*PrintFlags) ToPrinter

func (f *PrintFlags) ToPrinter() (printers.ResourcePrinter, error)

func (*PrintFlags) WithDefaultOutput

func (f *PrintFlags) WithDefaultOutput(output string) *PrintFlags

WithDefaultOutput sets a default output format if one is not provided through a flag value

func (*PrintFlags) WithTypeSetter

func (f *PrintFlags) WithTypeSetter(scheme *runtime.Scheme) *PrintFlags

WithTypeSetter sets a wrapper than will surround the returned printer with a printer to type resources

type RESTClientGetter

type RESTClientGetter interface {
	// ToRESTConfig returns restconfig
	ToRESTConfig() (*rest.Config, error)
	// ToDiscoveryClient returns discovery client
	ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)
	// ToRESTMapper returns a restmapper
	ToRESTMapper() (meta.RESTMapper, error)
	// ToRawKubeConfigLoader return kubeconfig loader as-is
	ToRawKubeConfigLoader() clientcmd.ClientConfig
}

RESTClientGetter is an interface that the ConfigFlags describe to provide an easier way to mock for commands and eliminate the direct coupling to a struct type. Users may wish to duplicate this type in their own packages as per the golang type overlapping.

type RecordFlags

type RecordFlags struct {
	// Record indicates the state of the recording flag.  It is a pointer so a caller can opt out or rebind
	Record *bool
	// contains filtered or unexported fields
}

RecordFlags contains all flags associated with the "--record" operation

func NewRecordFlags

func NewRecordFlags() *RecordFlags

NewRecordFlags provides a RecordFlags with reasonable default values set for use

func (*RecordFlags) AddFlags

func (f *RecordFlags) AddFlags(cmd *cobra.Command)

AddFlags binds the requested flags to the provided flagset TODO have this only take a flagset

func (*RecordFlags) Complete

func (f *RecordFlags) Complete(cmd *cobra.Command) error

Complete is called before the command is run, but after it is invoked to finish the state of the struct before use.

func (*RecordFlags) CompleteWithChangeCause

func (f *RecordFlags) CompleteWithChangeCause(cause string) error

func (*RecordFlags) ToRecorder

func (f *RecordFlags) ToRecorder() (Recorder, error)

ToRecorder returns a ChangeCause recorder if --record=false was not explicitly given by the user

type Recorder

type Recorder interface {
	// Record records why a runtime.Object was changed in an annotation.
	Record(runtime.Object) error
	MakeRecordMergePatch(runtime.Object) ([]byte, error)
}

Recorder is used to record why a runtime.Object was changed in an annotation.

type ResourceBuilderFlags

type ResourceBuilderFlags struct {
	FileNameFlags *FileNameFlags

	LabelSelector        *string
	FieldSelector        *string
	AllNamespaces        *bool
	All                  *bool
	Local                *bool
	IncludeUninitialized *bool

	Scheme           *runtime.Scheme
	Latest           bool
	StopOnFirstError bool
}

ResourceBuilderFlags are flags for finding resources TODO(juanvallejo): wire --local flag from commands through

func NewResourceBuilderFlags

func NewResourceBuilderFlags() *ResourceBuilderFlags

NewResourceBuilderFlags returns a default ResourceBuilderFlags

func (*ResourceBuilderFlags) AddFlags

func (o *ResourceBuilderFlags) AddFlags(flagset *pflag.FlagSet)

AddFlags registers flags for finding resources

func (*ResourceBuilderFlags) StopOnError

func (o *ResourceBuilderFlags) StopOnError() *ResourceBuilderFlags

func (*ResourceBuilderFlags) ToBuilder

func (o *ResourceBuilderFlags) ToBuilder(restClientGetter RESTClientGetter, resources []string) ResourceFinder

ToBuilder gives you back a resource finder to visit resources that are located

func (*ResourceBuilderFlags) WithAll

func (o *ResourceBuilderFlags) WithAll(defaultVal bool) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithAllNamespaces

func (o *ResourceBuilderFlags) WithAllNamespaces(defaultVal bool) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithFieldSelector

func (o *ResourceBuilderFlags) WithFieldSelector(selector string) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithFile

func (o *ResourceBuilderFlags) WithFile(recurse bool, files ...string) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithLabelSelector

func (o *ResourceBuilderFlags) WithLabelSelector(selector string) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithLatest

func (o *ResourceBuilderFlags) WithLatest() *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithLocal

func (o *ResourceBuilderFlags) WithLocal(defaultVal bool) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithScheme

func (o *ResourceBuilderFlags) WithScheme(scheme *runtime.Scheme) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithUninitialized

func (o *ResourceBuilderFlags) WithUninitialized(defaultVal bool) *ResourceBuilderFlags

WithUninitialized is using an alpha feature and may be dropped

type ResourceFindBuilderWrapper

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

ResourceFindBuilderWrapper wraps a builder in an interface

func (*ResourceFindBuilderWrapper) Do

Do finds you resources to check

type ResourceFinder

type ResourceFinder interface {
	Do() resource.Visitor
}

ResourceFinder allows mocking the resource builder TODO resource builders needs to become more interfacey

func NewSimpleFakeResourceFinder

func NewSimpleFakeResourceFinder(infos ...*resource.Info) ResourceFinder

NewSimpleResourceFinder builds a super simple ResourceFinder that just iterates over the objects you provided

func ResourceFinderForResult

func ResourceFinderForResult(result resource.Visitor) ResourceFinder

ResourceFinderForResult skins a visitor for re-use as a ResourceFinder

type ResourceFinderFunc

type ResourceFinderFunc func() resource.Visitor

ResourceFinderFunc is a handy way to make a ResourceFinder

func (ResourceFinderFunc) Do

Do implements ResourceFinder

type TestConfigFlags

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

func NewTestConfigFlags

func NewTestConfigFlags() *TestConfigFlags

func (*TestConfigFlags) ToDiscoveryClient

func (f *TestConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

func (*TestConfigFlags) ToRESTConfig

func (f *TestConfigFlags) ToRESTConfig() (*rest.Config, error)

func (*TestConfigFlags) ToRESTMapper

func (f *TestConfigFlags) ToRESTMapper() (meta.RESTMapper, error)

func (*TestConfigFlags) ToRawKubeConfigLoader

func (f *TestConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig

func (*TestConfigFlags) WithClientConfig

func (f *TestConfigFlags) WithClientConfig(clientConfig clientcmd.ClientConfig) *TestConfigFlags

func (*TestConfigFlags) WithDiscoveryClient

func (*TestConfigFlags) WithNamespace

func (f *TestConfigFlags) WithNamespace(ns string) *TestConfigFlags

func (*TestConfigFlags) WithRESTMapper

func (f *TestConfigFlags) WithRESTMapper(mapper meta.RESTMapper) *TestConfigFlags

Directories

Path Synopsis
Package resource assists clients in dealing with RESTful objects that match the Kubernetes API conventions.
Package resource assists clients in dealing with RESTful objects that match the Kubernetes API conventions.

Jump to

Keyboard shortcuts

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