Documentation ¶
Overview ¶
A set of common functions needed by cmd/kubectl and pkg/kubectl packages.
Package kubectl is a set of libraries that are used by the kubectl command line tool. They are separated out into a library to support unit testing. Most functionality should be included in this package, and the main kubectl should really just be an entry point.
A set of common functions needed by cmd/kubectl and pkg/kubectl packages.
Index ¶
- Constants
- func AbortRollingUpdate(c *RollingUpdaterConfig)
- func AddDeploymentKeyToReplicationController(oldRc *api.ReplicationController, client client.Interface, ...) (*api.ReplicationController, error)
- func AddJsonFilenameFlag(cmd *cobra.Command, value *util.StringList, usage string)
- func CreateNewControllerFromCurrentController(c *client.Client, namespace, oldName, newName, image, deploymentKey string) (*api.ReplicationController, error)
- func DescribableResources() []string
- func DescribeEvents(el *api.EventList, w io.Writer)
- func FindSourceController(r RollingUpdaterClient, namespace, name string) (*api.ReplicationController, error)
- func GetApiVersions(w io.Writer, kubeClient client.Interface)
- func GetClientVersion(w io.Writer)
- func GetNextControllerAnnotation(rc *api.ReplicationController) (string, bool)
- func GetVersion(w io.Writer, kubeClient client.Interface)
- func IsNoSuchReaperError(err error) bool
- func LoadExistingNextReplicationController(c *client.Client, namespace, newName string) (*api.ReplicationController, error)
- func MakeLabels(labels map[string]string) string
- func MakeParams(cmd *cobra.Command, params []GeneratorParam) map[string]string
- func ParseLabels(labelString string) (map[string]string, error)
- func Rename(c RollingUpdaterClient, rc *api.ReplicationController, newName string) error
- func ScaleCondition(r Scaler, precondition *ScalePrecondition, namespace, name string, count uint) wait.ConditionFunc
- func SetNextControllerAnnotation(rc *api.ReplicationController, name string)
- func UpdateExistingReplicationController(c client.Interface, oldRc *api.ReplicationController, ...) (*api.ReplicationController, error)
- func ValidateParams(paramSpec []GeneratorParam, params map[string]string) error
- func WatchLoop(w watch.Interface, fn func(watch.Event) error)
- type BasicReplicationController
- type ControllerScaleError
- type ControllerScaleErrorType
- type Describer
- type Describers
- type ErrNoDescriber
- type Generator
- type GeneratorParam
- type HumanReadablePrinter
- type JSONPrinter
- type LimitRangeDescriber
- type NamespaceInfo
- type NoSuchReaperError
- type NodeDescriber
- type ObjectDescriber
- type OutputVersionMapper
- type PersistentVolumeClaimDescriber
- type PersistentVolumeDescriber
- type PodDescriber
- type PodReaper
- type PreconditionError
- type ProxyServer
- type RESTClient
- type Reaper
- type ReplicationControllerDescriber
- type ReplicationControllerReaper
- type ReplicationControllerScaler
- type ResourcePrinter
- type ResourcePrinterFunc
- type ResourceQuotaDescriber
- type RetryParams
- type RollingUpdater
- type RollingUpdaterCleanupPolicy
- type RollingUpdaterClient
- type RollingUpdaterConfig
- type ScalePrecondition
- type Scaler
- type ScalerClient
- type SecretDescriber
- type ServiceAccountDescriber
- type ServiceDescriber
- type ServiceGenerator
- type ServiceReaper
- type ShortcutExpander
- type SortableEvents
- type SortableResourceNames
- type TemplatePrinter
- type VersionedPrinter
- type YAMLPrinter
Constants ¶
const ( Interval = time.Second * 1 Timeout = time.Minute * 5 )
const MaxRetries = 3
Variables ¶
This section is empty.
Functions ¶
func AbortRollingUpdate ¶ added in v0.17.0
func AbortRollingUpdate(c *RollingUpdaterConfig)
func AddDeploymentKeyToReplicationController ¶ added in v0.17.0
func AddDeploymentKeyToReplicationController(oldRc *api.ReplicationController, client client.Interface, deploymentKey, deploymentValue, namespace string, out io.Writer) (*api.ReplicationController, error)
func AddJsonFilenameFlag ¶ added in v0.16.1
func AddJsonFilenameFlag(cmd *cobra.Command, value *util.StringList, usage string)
func CreateNewControllerFromCurrentController ¶ added in v0.17.0
func DescribableResources ¶ added in v0.16.1
func DescribableResources() []string
List of all resource types we can describe
func FindSourceController ¶ added in v0.17.0
func FindSourceController(r RollingUpdaterClient, namespace, name string) (*api.ReplicationController, error)
func GetApiVersions ¶ added in v0.14.0
func GetClientVersion ¶
func GetNextControllerAnnotation ¶ added in v0.17.0
func GetNextControllerAnnotation(rc *api.ReplicationController) (string, bool)
func IsNoSuchReaperError ¶ added in v0.16.1
func LoadExistingNextReplicationController ¶ added in v0.17.0
func MakeLabels ¶ added in v0.11.0
func MakeParams ¶ added in v0.9.0
func MakeParams(cmd *cobra.Command, params []GeneratorParam) map[string]string
MakeParams is a utility that creates generator parameters from a command line
func ParseLabels ¶ added in v0.9.0
ParseLabels turns a string representation of a label set into a map[string]string
func Rename ¶ added in v0.17.0
func Rename(c RollingUpdaterClient, rc *api.ReplicationController, newName string) error
func ScaleCondition ¶ added in v0.18.0
func ScaleCondition(r Scaler, precondition *ScalePrecondition, namespace, name string, count uint) wait.ConditionFunc
ScaleCondition is a closure around Scale that facilitates retries via util.wait
func SetNextControllerAnnotation ¶ added in v0.17.0
func SetNextControllerAnnotation(rc *api.ReplicationController, name string)
func UpdateExistingReplicationController ¶ added in v0.17.0
func UpdateExistingReplicationController(c client.Interface, oldRc *api.ReplicationController, namespace, newName, deploymentKey, deploymentValue string, out io.Writer) (*api.ReplicationController, error)
func ValidateParams ¶ added in v0.9.0
func ValidateParams(paramSpec []GeneratorParam, params map[string]string) error
ValidateParams ensures that all required params are present in the params map
Types ¶
type BasicReplicationController ¶ added in v0.9.0
type BasicReplicationController struct{}
func (BasicReplicationController) ParamNames ¶ added in v0.9.0
func (BasicReplicationController) ParamNames() []GeneratorParam
type ControllerScaleError ¶ added in v0.18.0
type ControllerScaleError struct { FailureType ControllerScaleErrorType ResourceVersion string ActualError error }
A ControllerScaleError is returned when a scale request passes preconditions but fails to actually scale the controller.
func (ControllerScaleError) Error ¶ added in v0.18.0
func (c ControllerScaleError) Error() string
type ControllerScaleErrorType ¶ added in v0.18.0
type ControllerScaleErrorType int
const ( ControllerScaleGetFailure ControllerScaleErrorType = iota ControllerScaleUpdateFailure )
type Describer ¶
Describer generates output for the named resource or an error if the output could not be generated. Implementors typically abstract the retrieval of the named object from a remote server.
type Describers ¶ added in v0.13.1
type Describers struct {
// contains filtered or unexported fields
}
Describers implements ObjectDescriber against functions registered via Add. Those functions can be strongly typed. Types are exactly matched (no conversion or assignable checks).
func (*Describers) Add ¶ added in v0.13.1
func (d *Describers) Add(fns ...interface{}) error
Add adds one or more describer functions to the Describer. The passed function must match the signature:
func(...) (string, error)
Any number of arguments may be provided.
func (*Describers) DescribeObject ¶ added in v0.13.1
func (d *Describers) DescribeObject(exact interface{}, extra ...interface{}) (string, error)
DescribeObject implements ObjectDescriber and will attempt to print the provided object to a string, if at least one describer function has been registered with the exact types passed, or if any describer can print the exact object in its first argument (the remainder will be provided empty values). If no function registered with Add can satisfy the passed objects, an ErrNoDescriber will be returned TODO: reorder and partial match extra.
type ErrNoDescriber ¶ added in v0.13.1
type ErrNoDescriber struct {
Types []string
}
ErrNoDescriber is a structured error indicating the provided object or objects cannot be described.
func (ErrNoDescriber) Error ¶ added in v0.13.1
func (e ErrNoDescriber) Error() string
Error implements the error interface.
type Generator ¶ added in v0.9.0
type Generator interface { // Generate creates an API object given a set of parameters Generate(params map[string]string) (runtime.Object, error) // ParamNames returns the list of parameters that this generator uses ParamNames() []GeneratorParam }
Generator is an interface for things that can generate API objects from input parameters.
type GeneratorParam ¶ added in v0.9.0
GeneratorParam is a parameter for a generator TODO: facilitate structured json generator input schemes
type HumanReadablePrinter ¶
type HumanReadablePrinter struct {
// contains filtered or unexported fields
}
HumanReadablePrinter is an implementation of ResourcePrinter which attempts to provide more elegant output. It is not threadsafe, but you may call PrintObj repeatedly; headers will only be printed if the object type changes. This makes it useful for printing items recieved from watches.
func NewHumanReadablePrinter ¶
func NewHumanReadablePrinter(noHeaders, withNamespace bool) *HumanReadablePrinter
NewHumanReadablePrinter creates a HumanReadablePrinter.
func (*HumanReadablePrinter) HandledResources ¶ added in v0.16.1
func (h *HumanReadablePrinter) HandledResources() []string
func (*HumanReadablePrinter) Handler ¶
func (h *HumanReadablePrinter) Handler(columns []string, printFunc interface{}) error
Handler adds a print handler with a given set of columns to HumanReadablePrinter instance. printFunc is the function that will be called to print an object. It must be of the following type:
func printFunc(object ObjectType, w io.Writer, withNamespace bool) error
where ObjectType is the type of the object that will be printed.
type JSONPrinter ¶
type JSONPrinter struct { }
JSONPrinter is an implementation of ResourcePrinter which outputs an object as JSON.
type LimitRangeDescriber ¶ added in v0.10.0
LimitRangeDescriber generates information about a limit range
type NamespaceInfo ¶
type NamespaceInfo struct {
Namespace string
}
type NoSuchReaperError ¶ added in v0.16.1
type NoSuchReaperError struct {
// contains filtered or unexported fields
}
func (*NoSuchReaperError) Error ¶ added in v0.16.1
func (n *NoSuchReaperError) Error() string
type NodeDescriber ¶ added in v0.13.0
NodeDescriber generates information about a node.
type ObjectDescriber ¶ added in v0.13.1
type ObjectDescriber interface {
DescribeObject(object interface{}, extra ...interface{}) (output string, err error)
}
ObjectDescriber is an interface for displaying arbitrary objects with extra information. Use when an object is in hand (on disk, or already retrieved). Implementors may ignore the additional information passed on extra, or use it by default. ObjectDescribers may return ErrNoDescriber if no suitable describer is found.
var DefaultObjectDescriber ObjectDescriber
DefaultObjectDescriber can describe the default Kubernetes objects.
type OutputVersionMapper ¶ added in v0.9.0
type OutputVersionMapper struct { meta.RESTMapper OutputVersion string }
OutputVersionMapper is a RESTMapper that will prefer mappings that correspond to a preferred output version (if feasible)
func (OutputVersionMapper) RESTMapping ¶ added in v0.9.0
func (m OutputVersionMapper) RESTMapping(kind string, versions ...string) (*meta.RESTMapping, error)
RESTMapping implements meta.RESTMapper by prepending the output version to the preferred version list.
type PersistentVolumeClaimDescriber ¶ added in v0.15.0
type PersistentVolumeDescriber ¶ added in v0.15.0
type PodDescriber ¶
PodDescriber generates information about a pod and the replication controllers that create it.
type PreconditionError ¶ added in v0.9.0
A PreconditionError is returned when a replication controller fails to match the scale preconditions passed to kubectl.
func (PreconditionError) Error ¶ added in v0.9.0
func (pe PreconditionError) Error() string
type ProxyServer ¶
type ProxyServer struct { httputil.ReverseProxy // contains filtered or unexported fields }
ProxyServer is a http.Handler which proxies Kubernetes APIs to remote API server.
func NewProxyServer ¶
func NewProxyServer(filebase string, apiProxyPrefix string, staticPrefix string, cfg *client.Config) (*ProxyServer, error)
NewProxyServer creates and installs a new ProxyServer. It automatically registers the created ProxyServer to http.DefaultServeMux.
func (*ProxyServer) Serve ¶
func (s *ProxyServer) Serve(port int) error
Serve starts the server (http.DefaultServeMux) on given port, loops forever.
type RESTClient ¶
type RESTClient interface { Get() *client.Request Post() *client.Request Delete() *client.Request Put() *client.Request }
RESTClient is a client helper for dealing with RESTful resources in a generic way.
type Reaper ¶ added in v0.9.1
type Reaper interface {
Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) (string, error)
}
A Reaper handles terminating an object as gracefully as possible. timeout is how long we'll wait for the termination to be successful gracePeriod is time given to an API object for it to delete itself cleanly (e.g. pod shutdown)
type ReplicationControllerDescriber ¶
ReplicationControllerDescriber generates information about a replication controller and the pods it has created.
type ReplicationControllerReaper ¶ added in v0.9.1
type ReplicationControllerReaper struct { client.Interface // contains filtered or unexported fields }
func (*ReplicationControllerReaper) Stop ¶ added in v0.9.1
func (reaper *ReplicationControllerReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) (string, error)
type ReplicationControllerScaler ¶ added in v0.18.0
type ReplicationControllerScaler struct {
// contains filtered or unexported fields
}
func (*ReplicationControllerScaler) Scale ¶ added in v0.18.0
func (scaler *ReplicationControllerScaler) Scale(namespace, name string, newSize uint, preconditions *ScalePrecondition, retry, waitForReplicas *RetryParams) error
Scale updates a ReplicationController to a new size, with optional precondition check (if preconditions is not nil), optional retries (if retry is not nil), and then optionally waits for it's replica count to reach the new value (if wait is not nil).
func (*ReplicationControllerScaler) ScaleSimple ¶ added in v0.18.0
func (scaler *ReplicationControllerScaler) ScaleSimple(namespace, name string, preconditions *ScalePrecondition, newSize uint) (string, error)
type ResourcePrinter ¶
type ResourcePrinter interface { // Print receives a runtime object, formats it and prints it to a writer. PrintObj(runtime.Object, io.Writer) error }
ResourcePrinter is an interface that knows how to print runtime objects.
func GetPrinter ¶
func GetPrinter(format, formatArgument string) (ResourcePrinter, bool, error)
GetPrinter takes a format type, an optional format argument. It will return true if the format is generic (untyped), otherwise it will return false. The printer is agnostic to schema versions, so you must send arguments to PrintObj in the version you wish them to be shown using a VersionedPrinter (typically when generic is true).
func NewVersionedPrinter ¶ added in v0.9.0
func NewVersionedPrinter(printer ResourcePrinter, convertor runtime.ObjectConvertor, version ...string) ResourcePrinter
NewVersionedPrinter wraps a printer to convert objects to a known API version prior to printing.
type ResourcePrinterFunc ¶ added in v0.9.0
ResourcePrinterFunc is a function that can print objects
type ResourceQuotaDescriber ¶ added in v0.10.0
ResourceQuotaDescriber generates information about a resource quota
type RetryParams ¶ added in v0.15.0
RetryParams encapsulates the retry parameters used by kubectl's scaler.
func NewRetryParams ¶ added in v0.18.0
func NewRetryParams(interval, timeout time.Duration) *RetryParams
type RollingUpdater ¶ added in v0.9.0
type RollingUpdater struct {
// contains filtered or unexported fields
}
RollingUpdater provides methods for updating replicated pods in a predictable, fault-tolerant way.
func NewRollingUpdater ¶ added in v0.9.0
func NewRollingUpdater(namespace string, c RollingUpdaterClient) *RollingUpdater
NewRollingUpdater creates a RollingUpdater from a client
func (*RollingUpdater) Update ¶ added in v0.9.0
func (r *RollingUpdater) Update(config *RollingUpdaterConfig) error
Update all pods for a ReplicationController (oldRc) by creating a new controller (newRc) with 0 replicas, and synchronously scaling oldRc,newRc by 1 until oldRc has 0 replicas and newRc has the original # of desired replicas. Cleanup occurs based on a RollingUpdaterCleanupPolicy.
If an update from newRc to oldRc is already in progress, we attempt to drive it to completion. If an error occurs at any step of the update, the error will be returned.
TODO: make this handle performing a rollback of a partially completed rollout.
type RollingUpdaterCleanupPolicy ¶ added in v0.16.1
type RollingUpdaterCleanupPolicy string
RollingUpdaterCleanupPolicy is a cleanup action to take after the deployment is complete.
const ( // DeleteRollingUpdateCleanupPolicy means delete the old controller. DeleteRollingUpdateCleanupPolicy RollingUpdaterCleanupPolicy = "Delete" // PreserveRollingUpdateCleanupPolicy means keep the old controller. PreserveRollingUpdateCleanupPolicy RollingUpdaterCleanupPolicy = "Preserve" // RenameRollingUpdateCleanupPolicy means delete the old controller, and rename // the new controller to the name of the old controller. RenameRollingUpdateCleanupPolicy RollingUpdaterCleanupPolicy = "Rename" )
type RollingUpdaterClient ¶ added in v0.16.1
type RollingUpdaterClient interface { ListReplicationControllers(namespace string, selector labels.Selector) (*api.ReplicationControllerList, error) GetReplicationController(namespace, name string) (*api.ReplicationController, error) UpdateReplicationController(namespace string, rc *api.ReplicationController) (*api.ReplicationController, error) CreateReplicationController(namespace string, rc *api.ReplicationController) (*api.ReplicationController, error) DeleteReplicationController(namespace, name string) error ControllerHasDesiredReplicas(rc *api.ReplicationController) wait.ConditionFunc }
RollingUpdaterClient abstracts access to ReplicationControllers.
func NewRollingUpdaterClient ¶ added in v0.16.1
func NewRollingUpdaterClient(c client.Interface) RollingUpdaterClient
type RollingUpdaterConfig ¶ added in v0.16.1
type RollingUpdaterConfig struct { // Out is a writer for progress output. Out io.Writer // OldRC is an existing controller to be replaced. OldRc *api.ReplicationController // NewRc is a controller that will take ownership of updated pods (will be // created if needed). NewRc *api.ReplicationController // UpdatePeriod is the time to wait between individual pod updates. UpdatePeriod time.Duration // Interval is the time to wait between polling controller status after // update. Interval time.Duration // Timeout is the time to wait for controller updates before giving up. Timeout time.Duration // CleanupPolicy defines the cleanup action to take after the deployment is // complete. CleanupPolicy RollingUpdaterCleanupPolicy }
RollingUpdaterConfig is the configuration for a rolling deployment process.
type ScalePrecondition ¶ added in v0.18.0
ScalePrecondition describes a condition that must be true for the scale to take place If CurrentSize == -1, it is ignored. If CurrentResourceVersion is the empty string, it is ignored. Otherwise they must equal the values in the replication controller for it to be valid.
func (*ScalePrecondition) Validate ¶ added in v0.18.0
func (precondition *ScalePrecondition) Validate(controller *api.ReplicationController) error
Validate ensures that the preconditions match. Returns nil if they are valid, an error otherwise
type Scaler ¶ added in v0.18.0
type Scaler interface { // Scale scales the named resource after checking preconditions. It optionally // retries in the event of resource version mismatch (if retry is not nil), // and optionally waits until the status of the resource matches newSize (if wait is not nil) Scale(namespace, name string, newSize uint, preconditions *ScalePrecondition, retry, wait *RetryParams) error // ScaleSimple does a simple one-shot attempt at scaling - not useful on it's own, but // a necessary building block for Scale ScaleSimple(namespace, name string, preconditions *ScalePrecondition, newSize uint) (string, error) }
type ScalerClient ¶ added in v0.18.0
type ScalerClient interface { GetReplicationController(namespace, name string) (*api.ReplicationController, error) UpdateReplicationController(namespace string, rc *api.ReplicationController) (*api.ReplicationController, error) ControllerHasDesiredReplicas(rc *api.ReplicationController) wait.ConditionFunc }
ScalerClient abstracts access to ReplicationControllers.
func NewScalerClient ¶ added in v0.18.0
func NewScalerClient(c client.Interface) ScalerClient
type SecretDescriber ¶ added in v0.18.0
SecretDescriber generates information about a secret
type ServiceAccountDescriber ¶ added in v0.18.0
ServiceAccountDescriber generates information about a service.
type ServiceDescriber ¶
ServiceDescriber generates information about a service.
type ServiceGenerator ¶ added in v0.11.0
type ServiceGenerator struct{}
func (ServiceGenerator) ParamNames ¶ added in v0.11.0
func (ServiceGenerator) ParamNames() []GeneratorParam
type ServiceReaper ¶ added in v0.9.1
func (*ServiceReaper) Stop ¶ added in v0.9.1
func (reaper *ServiceReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) (string, error)
type ShortcutExpander ¶ added in v0.9.0
type ShortcutExpander struct {
meta.RESTMapper
}
ShortcutExpander is a RESTMapper that can be used for Kubernetes resources.
func (ShortcutExpander) VersionAndKindForResource ¶ added in v0.9.0
func (e ShortcutExpander) VersionAndKindForResource(resource string) (defaultVersion, kind string, err error)
VersionAndKindForResource implements meta.RESTMapper. It expands the resource first, then invokes the wrapped mapper.
type SortableEvents ¶ added in v0.8.0
SortableEvents implements sort.Interface for []api.Event based on the Timestamp field
func (SortableEvents) Len ¶ added in v0.8.0
func (list SortableEvents) Len() int
func (SortableEvents) Less ¶ added in v0.8.0
func (list SortableEvents) Less(i, j int) bool
func (SortableEvents) Swap ¶ added in v0.8.0
func (list SortableEvents) Swap(i, j int)
type SortableResourceNames ¶ added in v0.10.0
type SortableResourceNames []api.ResourceName
func (SortableResourceNames) Len ¶ added in v0.10.0
func (list SortableResourceNames) Len() int
func (SortableResourceNames) Less ¶ added in v0.10.0
func (list SortableResourceNames) Less(i, j int) bool
func (SortableResourceNames) Swap ¶ added in v0.10.0
func (list SortableResourceNames) Swap(i, j int)
type TemplatePrinter ¶
type TemplatePrinter struct {
// contains filtered or unexported fields
}
TemplatePrinter is an implementation of ResourcePrinter which formats data with a Go Template.
func NewTemplatePrinter ¶
func NewTemplatePrinter(tmpl []byte) (*TemplatePrinter, error)
type VersionedPrinter ¶ added in v0.9.0
type VersionedPrinter struct {
// contains filtered or unexported fields
}
VersionedPrinter takes runtime objects and ensures they are converted to a given API version prior to being passed to a nested printer.
type YAMLPrinter ¶
type YAMLPrinter struct {
// contains filtered or unexported fields
}
YAMLPrinter is an implementation of ResourcePrinter which outputs an object as YAML. The input object is assumed to be in the internal version of an API and is converted to the given version first.