Documentation ¶
Overview ¶
Package client contains the implementation of the client side communication with the Kubernetes master. The Client class provides methods for reading, creating, updating, and deleting pods, replication controllers, services, and minions.
Most consumers should use the Config object to create a Client:
config := &client.Config{ Host: "http://localhost:8080", Username: "test", Password: "password", } client, err := client.New(&config) if err != nil { // handle error } client.ListPods()
More advanced consumers may wish to provide their own transport via a http.RoundTripper:
config := &client.Config{ Host: "https://localhost:8080", Transport: oauthclient.Transport(), } client, err := client.New(&config)
The RESTClient type implements the Kubernetes API conventions (see `docs/api-conventions.md`) for a given API path and is intended for use by consumers implementing their own Kubernetes compatible APIs.
Index ¶
- Variables
- func BindClientConfigFlags(flags FlagSet, config *Config)
- func DefaultServerURL(host, prefix, version string, defaultSecure bool) (*url.URL, error)
- func IsConfigTransportSecure(config *Config) bool
- func NewBasicAuthRoundTripper(username, password string, rt http.RoundTripper) http.RoundTripper
- func NewBearerAuthRoundTripper(bearer string, rt http.RoundTripper) http.RoundTripper
- func NewClientCertTLSTransport(certFile, keyFile, caFile string) (*http.Transport, error)
- func NewUnsafeTLSTransport() *http.Transport
- func TransportFor(config *Config) (http.RoundTripper, error)
- type APIStatus
- type Client
- func (c *Client) ControllerHasDesiredReplicas(controller api.ReplicationController) wait.ConditionFunc
- func (c *Client) CreateEndpoints(ctx api.Context, endpoints *api.Endpoints) (*api.Endpoints, error)
- func (c *Client) CreatePod(ctx api.Context, pod *api.Pod) (result *api.Pod, err error)
- func (c *Client) CreateReplicationController(ctx api.Context, controller *api.ReplicationController) (result *api.ReplicationController, err error)
- func (c *Client) CreateService(ctx api.Context, svc *api.Service) (result *api.Service, err error)
- func (c *Client) DeletePod(ctx api.Context, id string) error
- func (c *Client) DeleteReplicationController(ctx api.Context, id string) error
- func (c *Client) DeleteService(ctx api.Context, id string) error
- func (c *Client) GetEndpoints(ctx api.Context, id string) (result *api.Endpoints, err error)
- func (c *Client) GetMinion(id string) (result *api.Minion, err error)
- func (c *Client) GetPod(ctx api.Context, id string) (result *api.Pod, err error)
- func (c *Client) GetReplicationController(ctx api.Context, id string) (result *api.ReplicationController, err error)
- func (c *Client) GetService(ctx api.Context, id string) (result *api.Service, err error)
- func (c *Client) ListEndpoints(ctx api.Context, selector labels.Selector) (result *api.EndpointsList, err error)
- func (c *Client) ListMinions() (result *api.MinionList, err error)
- func (c *Client) ListPods(ctx api.Context, selector labels.Selector) (result *api.PodList, err error)
- func (c *Client) ListReplicationControllers(ctx api.Context, selector labels.Selector) (result *api.ReplicationControllerList, err error)
- func (c *Client) ListServices(ctx api.Context, selector labels.Selector) (result *api.ServiceList, err error)
- func (c *Client) ServerVersion() (*version.Info, error)
- func (c *Client) UpdateEndpoints(ctx api.Context, endpoints *api.Endpoints) (*api.Endpoints, error)
- func (c *Client) UpdatePod(ctx api.Context, pod *api.Pod) (result *api.Pod, err error)
- func (c *Client) UpdateReplicationController(ctx api.Context, controller *api.ReplicationController) (result *api.ReplicationController, err error)
- func (c *Client) UpdateService(ctx api.Context, svc *api.Service) (result *api.Service, err error)
- func (c *Client) WatchEndpoints(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error)
- func (c *Client) WatchReplicationControllers(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error)
- func (c *Client) WatchServices(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error)
- type Config
- type ContainerInfoGetter
- type EndpointsInterface
- type Fake
- func (c *Fake) CreatePod(ctx api.Context, pod *api.Pod) (*api.Pod, error)
- func (c *Fake) CreateReplicationController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error)
- func (c *Fake) CreateService(ctx api.Context, service *api.Service) (*api.Service, error)
- func (c *Fake) DeletePod(ctx api.Context, name string) error
- func (c *Fake) DeleteReplicationController(ctx api.Context, controller string) error
- func (c *Fake) DeleteService(ctx api.Context, service string) error
- func (c *Fake) GetEndpoints(ctx api.Context, name string) (*api.Endpoints, error)
- func (c *Fake) GetPod(ctx api.Context, name string) (*api.Pod, error)
- func (c *Fake) GetReplicationController(ctx api.Context, name string) (*api.ReplicationController, error)
- func (c *Fake) GetService(ctx api.Context, name string) (*api.Service, error)
- func (c *Fake) ListEndpoints(ctx api.Context, selector labels.Selector) (*api.EndpointsList, error)
- func (c *Fake) ListMinions() (*api.MinionList, error)
- func (c *Fake) ListPods(ctx api.Context, selector labels.Selector) (*api.PodList, error)
- func (c *Fake) ListReplicationControllers(ctx api.Context, selector labels.Selector) (*api.ReplicationControllerList, error)
- func (c *Fake) ListServices(ctx api.Context, selector labels.Selector) (*api.ServiceList, error)
- func (c *Fake) ServerVersion() (*version.Info, error)
- func (c *Fake) UpdatePod(ctx api.Context, pod *api.Pod) (*api.Pod, error)
- func (c *Fake) UpdateReplicationController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error)
- func (c *Fake) UpdateService(ctx api.Context, service *api.Service) (*api.Service, error)
- func (c *Fake) WatchEndpoints(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error)
- func (c *Fake) WatchReplicationControllers(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error)
- func (c *Fake) WatchServices(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error)
- type FakeAction
- type FakePodInfoGetter
- type FlagSet
- type HTTPContainerInfoGetter
- func (self *HTTPContainerInfoGetter) GetContainerInfo(host, podID, containerID string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
- func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*info.MachineInfo, error)
- func (self *HTTPContainerInfoGetter) GetRootInfo(host string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
- type HTTPPodInfoGetter
- type Interface
- type MinionInterface
- type PodInfoGetter
- type PodInterface
- type RESTClient
- type ReplicationControllerInterface
- type Request
- func (r *Request) AbsPath(path string) *Request
- func (r *Request) Body(obj interface{}) *Request
- func (r *Request) Do() Result
- func (r *Request) Param(paramName, s string) *Request
- func (r *Request) ParseSelectorParam(paramName, item string) *Request
- func (r *Request) Path(item string) *Request
- func (r *Request) PollPeriod(d time.Duration) *Request
- func (r *Request) SelectorParam(paramName string, s labels.Selector) *Request
- func (r *Request) Stream() (io.ReadCloser, error)
- func (r *Request) Sync(sync bool) *Request
- func (r *Request) Timeout(d time.Duration) *Request
- func (r *Request) UintParam(paramName string, u uint64) *Request
- func (r *Request) Watch() (watch.Interface, error)
- type Result
- type ServiceInterface
- type VersionInterface
Constants ¶
This section is empty.
Variables ¶
var ErrPodInfoNotAvailable = errors.New("no pod info available")
ErrPodInfoNotAvailable may be returned when the requested pod info is not available.
Functions ¶
func BindClientConfigFlags ¶
BindClientConfigFlags registers a standard set of CLI flags for connecting to a Kubernetes API server.
func DefaultServerURL ¶
DefaultServerURL converts a host, host:port, or URL string to the default base server API path to use with a Client at a given API version following the standard conventions for a Kubernetes API.
func IsConfigTransportSecure ¶
IsConfigTransportSecure returns true iff the provided config will result in a protected connection to the server when it is passed to client.New() or client.RESTClientFor(). Use to determine when to send credentials over the wire.
Note: the Insecure flag is ignored when testing for this value, so MITM attacks are still possible.
func NewBasicAuthRoundTripper ¶
func NewBasicAuthRoundTripper(username, password string, rt http.RoundTripper) http.RoundTripper
func NewBearerAuthRoundTripper ¶
func NewBearerAuthRoundTripper(bearer string, rt http.RoundTripper) http.RoundTripper
func NewUnsafeTLSTransport ¶
func TransportFor ¶
func TransportFor(config *Config) (http.RoundTripper, error)
TransportFor returns an http.RoundTripper that will provide the authentication or transport level security defined by the provided Config. Will return the default http.DefaultTransport if no special case behavior is needed.
Types ¶
type APIStatus ¶
APIStatus is exposed by errors that can be converted to an api.Status object for finer grained details.
type Client ¶
type Client struct {
*RESTClient
}
Client is the implementation of a Kubernetes client.
func New ¶
New creates a Kubernetes client for the given config. This client works with pods, replication controllers and services. It allows operations such as list, get, update and delete on these objects. An error is returned if the provided configuration is not valid.
func NewOrDie ¶
NewOrDie creates a Kubernetes client and panics if the provided API version is not recognized.
func (*Client) ControllerHasDesiredReplicas ¶
func (c *Client) ControllerHasDesiredReplicas(controller api.ReplicationController) wait.ConditionFunc
ControllerHasDesiredReplicas returns a condition that will be true iff the desired replica count for a controller's ReplicaSelector equals the Replicas count.
func (*Client) CreateEndpoints ¶
func (*Client) CreatePod ¶
CreatePod takes the representation of a pod. Returns the server's representation of the pod, and an error, if it occurs.
func (*Client) CreateReplicationController ¶
func (c *Client) CreateReplicationController(ctx api.Context, controller *api.ReplicationController) (result *api.ReplicationController, err error)
CreateReplicationController creates a new replication controller.
func (*Client) CreateService ¶
CreateService creates a new service.
func (*Client) DeleteReplicationController ¶
DeleteReplicationController deletes an existing replication controller.
func (*Client) DeleteService ¶
DeleteService deletes an existing service.
func (*Client) GetEndpoints ¶
GetEndpoints returns information about the endpoints for a particular service.
func (*Client) GetPod ¶
GetPod takes the id of the pod, and returns the corresponding Pod object, and an error if it occurs
func (*Client) GetReplicationController ¶
func (c *Client) GetReplicationController(ctx api.Context, id string) (result *api.ReplicationController, err error)
GetReplicationController returns information about a particular replication controller.
func (*Client) GetService ¶
GetService returns information about a particular service.
func (*Client) ListEndpoints ¶
func (c *Client) ListEndpoints(ctx api.Context, selector labels.Selector) (result *api.EndpointsList, err error)
ListEndpoints takes a selector, and returns the list of endpoints that match that selector
func (*Client) ListMinions ¶
func (c *Client) ListMinions() (result *api.MinionList, err error)
ListMinions lists all the minions in the cluster.
func (*Client) ListPods ¶
func (c *Client) ListPods(ctx api.Context, selector labels.Selector) (result *api.PodList, err error)
ListPods takes a selector, and returns the list of pods that match that selector.
func (*Client) ListReplicationControllers ¶
func (c *Client) ListReplicationControllers(ctx api.Context, selector labels.Selector) (result *api.ReplicationControllerList, err error)
ListReplicationControllers takes a selector, and returns the list of replication controllers that match that selector.
func (*Client) ListServices ¶
func (c *Client) ListServices(ctx api.Context, selector labels.Selector) (result *api.ServiceList, err error)
ListServices takes a selector, and returns the list of services that match that selector
func (*Client) ServerVersion ¶
ServerVersion retrieves and parses the server's version.
func (*Client) UpdateEndpoints ¶
func (*Client) UpdatePod ¶
UpdatePod takes the representation of a pod to update. Returns the server's representation of the pod, and an error, if it occurs.
func (*Client) UpdateReplicationController ¶
func (c *Client) UpdateReplicationController(ctx api.Context, controller *api.ReplicationController) (result *api.ReplicationController, err error)
UpdateReplicationController updates an existing replication controller.
func (*Client) UpdateService ¶
UpdateService updates an existing service.
func (*Client) WatchEndpoints ¶
func (c *Client) WatchEndpoints(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error)
WatchEndpoints returns a watch.Interface that watches the requested endpoints for a service.
type Config ¶
type Config struct { // Host must be a host string, a host:port pair, or a URL to the base of the API. Host string // Prefix is the sub path of the server. If not specified, the client will set // a default value. Use "/" to indicate the server root should be used Prefix string // Version is the API version to talk to. If not specified, the client will use // the preferred version. Version string // Server requires Basic authentication Username string Password string // Server requires Bearer authentication. This client will not attempt to use // refresh tokens for an OAuth2 flow. // TODO: demonstrate an OAuth2 compatible client. BearerToken string // Server requires TLS client certificate authentication CertFile string KeyFile string CAFile string // Server should be accessed without verifying the TLS // certificate. For testing only. Insecure bool // Transport may be used for custom HTTP behavior. This attribute may not // be specified with the TLS client certificate options. Transport http.RoundTripper }
Config holds the common attributes that can be passed to a Kubernetes client on initialization.
type ContainerInfoGetter ¶
type ContainerInfoGetter interface { // GetContainerInfo returns information about a container. GetContainerInfo(host, podID, containerID string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) // GetRootInfo returns information about the root container on a machine. GetRootInfo(host string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) // GetMachineInfo returns the machine's information like number of cores, memory capacity. GetMachineInfo(host string) (*info.MachineInfo, error) }
type EndpointsInterface ¶
type EndpointsInterface interface { ListEndpoints(ctx api.Context, selector labels.Selector) (*api.EndpointsList, error) GetEndpoints(ctx api.Context, id string) (*api.Endpoints, error) WatchEndpoints(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) }
EndpointsInterface has methods to work with Endpoints resources
type Fake ¶
type Fake struct { // Fake by default keeps a simple list of the methods that have been called. Actions []FakeAction Pods api.PodList Ctrl api.ReplicationController ServiceList api.ServiceList EndpointsList api.EndpointsList Minions api.MinionList Err error Watch watch.Interface }
Fake implements Interface. Meant to be embedded into a struct to get a default implementation. This makes faking out just the method you want to test easier.
func (*Fake) CreateReplicationController ¶
func (c *Fake) CreateReplicationController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error)
func (*Fake) CreateService ¶
func (*Fake) DeleteReplicationController ¶
func (*Fake) GetEndpoints ¶
func (*Fake) GetReplicationController ¶
func (*Fake) GetService ¶
func (*Fake) ListEndpoints ¶
func (*Fake) ListMinions ¶
func (c *Fake) ListMinions() (*api.MinionList, error)
func (*Fake) ListReplicationControllers ¶
func (*Fake) ListServices ¶
func (*Fake) UpdateReplicationController ¶
func (c *Fake) UpdateReplicationController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error)
func (*Fake) UpdateService ¶
func (*Fake) WatchEndpoints ¶
func (*Fake) WatchReplicationControllers ¶
type FakeAction ¶
type FakeAction struct { Action string Value interface{} }
type FakePodInfoGetter ¶
type FakePodInfoGetter struct {
// contains filtered or unexported fields
}
FakePodInfoGetter is a fake implementation of PodInfoGetter. It is useful for testing.
func (*FakePodInfoGetter) GetPodInfo ¶
func (c *FakePodInfoGetter) GetPodInfo(host, podNamespace string, podID string) (api.PodInfo, error)
GetPodInfo is a fake implementation of PodInfoGetter.GetPodInfo.
type FlagSet ¶
type FlagSet interface { StringVar(p *string, name, value, usage string) BoolVar(p *bool, name string, value bool, usage string) }
FlagSet abstracts the flag interface for compatibility with both Golang "flag" and cobra pflags (Posix style).
type HTTPContainerInfoGetter ¶
func (*HTTPContainerInfoGetter) GetContainerInfo ¶
func (self *HTTPContainerInfoGetter) GetContainerInfo(host, podID, containerID string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
func (*HTTPContainerInfoGetter) GetMachineInfo ¶
func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*info.MachineInfo, error)
func (*HTTPContainerInfoGetter) GetRootInfo ¶
func (self *HTTPContainerInfoGetter) GetRootInfo(host string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
type HTTPPodInfoGetter ¶
HTTPPodInfoGetter is the default implementation of PodInfoGetter, accesses the kubelet over HTTP.
func (*HTTPPodInfoGetter) GetPodInfo ¶
func (c *HTTPPodInfoGetter) GetPodInfo(host, podNamespace, podID string) (api.PodInfo, error)
GetPodInfo gets information about the specified pod.
type Interface ¶
type Interface interface { PodInterface ReplicationControllerInterface ServiceInterface VersionInterface MinionInterface }
Interface holds the methods for clients of Kubernetes, an interface to allow mock testing. TODO: these should return/take pointers.
type MinionInterface ¶
type MinionInterface interface {
ListMinions() (*api.MinionList, error)
}
type PodInfoGetter ¶
type PodInfoGetter interface { // GetPodInfo returns information about all containers which are part // Returns an api.PodInfo, or an error if one occurs. GetPodInfo(host, podNamespace, podID string) (api.PodInfo, error) }
PodInfoGetter is an interface for things that can get information about a pod's containers. Injectable for easy testing.
type PodInterface ¶
type PodInterface interface { ListPods(ctx api.Context, selector labels.Selector) (*api.PodList, error) GetPod(ctx api.Context, id string) (*api.Pod, error) DeletePod(ctx api.Context, id string) error CreatePod(ctx api.Context, pod *api.Pod) (*api.Pod, error) UpdatePod(ctx api.Context, pod *api.Pod) (*api.Pod, error) }
PodInterface has methods to work with Pod resources.
type RESTClient ¶
type RESTClient struct { // Codec is the encoding and decoding scheme that applies to a particular set of // REST resources. Codec runtime.Codec // Set specific behavior of the client. If not set http.DefaultClient will be // used. Client *http.Client Sync bool PollPeriod time.Duration Timeout time.Duration // contains filtered or unexported fields }
RESTClient imposes common Kubernetes API conventions on a set of resource paths. The baseURL is expected to point to an HTTP or HTTPS path that is the parent of one or more resources. The server should return a decodable API resource object, or an api.Status object which contains information about the reason for any failure.
Most consumers should use client.New() to get a Kubernetes API client.
func NewRESTClient ¶
func NewRESTClient(baseURL *url.URL, c runtime.Codec) *RESTClient
NewRESTClient creates a new RESTClient. This client performs generic REST functions such as Get, Put, Post, and Delete on specified paths. Codec controls encoding and decoding of responses from the server.
func RESTClientFor ¶
func RESTClientFor(config *Config) (*RESTClient, error)
RESTClientFor returns a RESTClient that satisfies the requested attributes on a client Config object.
func (*RESTClient) Delete ¶
func (c *RESTClient) Delete() *Request
Delete begins a DELETE request. Short for c.Verb("DELETE").
func (*RESTClient) Get ¶
func (c *RESTClient) Get() *Request
Get begins a GET request. Short for c.Verb("GET").
func (*RESTClient) PollFor ¶
func (c *RESTClient) PollFor(operationID string) *Request
PollFor makes a request to do a single poll of the completion of the given operation.
func (*RESTClient) Post ¶
func (c *RESTClient) Post() *Request
Post begins a POST request. Short for c.Verb("POST").
func (*RESTClient) Put ¶
func (c *RESTClient) Put() *Request
Put begins a PUT request. Short for c.Verb("PUT").
func (*RESTClient) Verb ¶
func (c *RESTClient) Verb(verb string) *Request
Verb begins a request with a verb (GET, POST, PUT, DELETE).
Example usage of RESTClient's request building interface: c := NewRESTClient(url, codec) resp, err := c.Verb("GET").
Path("pods"). SelectorParam("labels", "area=staging"). Timeout(10*time.Second). Do()
if err != nil { ... } list, ok := resp.(*api.PodList)
type ReplicationControllerInterface ¶
type ReplicationControllerInterface interface { ListReplicationControllers(ctx api.Context, selector labels.Selector) (*api.ReplicationControllerList, error) GetReplicationController(ctx api.Context, id string) (*api.ReplicationController, error) CreateReplicationController(ctx api.Context, ctrl *api.ReplicationController) (*api.ReplicationController, error) UpdateReplicationController(ctx api.Context, ctrl *api.ReplicationController) (*api.ReplicationController, error) DeleteReplicationController(ctx api.Context, id string) error WatchReplicationControllers(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) }
ReplicationControllerInterface has methods to work with ReplicationController resources.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request allows for building up a request to a server in a chained fashion. Any errors are stored until the end of your call, so you only have to check once.
func (*Request) Body ¶
Body makes the request use obj as the body. Optional. If obj is a string, try to read a file of that name. If obj is a []byte, send it directly. If obj is an io.Reader, use it directly. If obj is a runtime.Object, marshal it correctly. Otherwise, set an error.
func (*Request) Do ¶
Do formats and executes the request. Returns the API object received, or an error.
func (*Request) ParseSelectorParam ¶
ParseSelectorParam parses the given string as a resource label selector. This is a convenience function so you don't have to first check that it's a validly formatted selector.
func (*Request) PollPeriod ¶
PollPeriod sets the poll period. If the server sends back a "working" status message, then repeatedly poll the server to see if the operation has completed yet, waiting 'd' between each poll. If you want to handle the "working" status yourself (it'll be delivered as StatusErr), set d to 0 to turn off this behavior.
func (*Request) SelectorParam ¶
SelectorParam adds the given selector as a query parameter with the name paramName.
func (*Request) Stream ¶
func (r *Request) Stream() (io.ReadCloser, error)
Stream formats and executes the request, and offers streaming of the response. Returns io.ReadCloser which could be used for streaming of the response, or an error
func (*Request) Sync ¶
Sync sets sync/async call status by setting the "sync" parameter to "true"/"false".
func (*Request) Timeout ¶
Timeout makes the request use the given duration as a timeout. Sets the "timeout" parameter. Ignored if sync=false.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result contains the result of calling Request.Do().
type ServiceInterface ¶
type ServiceInterface interface { ListServices(ctx api.Context, selector labels.Selector) (*api.ServiceList, error) GetService(ctx api.Context, id string) (*api.Service, error) CreateService(ctx api.Context, srv *api.Service) (*api.Service, error) UpdateService(ctx api.Context, srv *api.Service) (*api.Service, error) DeleteService(ctx api.Context, id string) error WatchServices(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) }
ServiceInterface has methods to work with Service resources.
type VersionInterface ¶
VersionInterface has a method to retrieve the server version.