client

package
v0.0.0-...-ac8ee45 Latest Latest
Warning

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

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

Documentation

Overview

Package client contains the implementation of the client side communication with the Kubernetes master.

Index

Constants

This section is empty.

Variables

View Source
var ErrPodInfoNotAvailable = errors.New("no pod info available")

ErrPodInfoNotAvailable may be returned when the requested pod info is not available.

Functions

This section is empty.

Types

type AuthInfo

type AuthInfo struct {
	User     string
	Password string
}

AuthInfo is used to store authorization information.

type Client

type Client struct {
	*RESTClient
}

Client is the actual implementation of a Kubernetes client.

func New

func New(host string, auth *AuthInfo) (*Client, error)

New creates a Kubernetes client. This client works with pods, replication controllers and services. It allows operations such as list, get, update and delete on these objects. host must be a host string, a host:port combo, or an http or https URL. Passing a prefix to a URL will prepend the server path. Returns an error if host cannot be converted to a valid URL.

func NewOrDie

func NewOrDie(host string, auth *AuthInfo) *Client

NewOrDie creates a Kubernetes client and panics if the provided host is invalid.

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) CreatePod

func (c *Client) CreatePod(pod *api.Pod) (result *api.Pod, err error)

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(controller *api.ReplicationController) (result *api.ReplicationController, err error)

CreateReplicationController creates a new replication controller.

func (*Client) CreateService

func (c *Client) CreateService(svc *api.Service) (result *api.Service, err error)

CreateService creates a new service.

func (*Client) DeletePod

func (c *Client) DeletePod(id string) error

DeletePod takes the id of the pod, and returns an error if one occurs

func (*Client) DeleteReplicationController

func (c *Client) DeleteReplicationController(id string) error

DeleteReplicationController deletes an existing replication controller.

func (*Client) DeleteService

func (c *Client) DeleteService(id string) error

DeleteService deletes an existing service.

func (*Client) GetPod

func (c *Client) GetPod(id string) (result *api.Pod, err error)

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(id string) (result *api.ReplicationController, err error)

GetReplicationController returns information about a particular replication controller.

func (*Client) GetService

func (c *Client) GetService(id string) (result *api.Service, err error)

GetService returns information about a particular service.

func (*Client) ListEndpoints

func (c *Client) ListEndpoints(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(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(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(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

func (c *Client) ServerVersion() (*version.Info, error)

ServerVersion retrieves and parses the server's version.

func (*Client) UpdatePod

func (c *Client) UpdatePod(pod *api.Pod) (result *api.Pod, err error)

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(controller *api.ReplicationController) (result *api.ReplicationController, err error)

UpdateReplicationController updates an existing replication controller.

func (*Client) UpdateService

func (c *Client) UpdateService(svc *api.Service) (result *api.Service, err error)

UpdateService updates an existing service.

func (*Client) WatchEndpoints

func (c *Client) WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)

WatchEndpoints returns a watch.Interface that watches the requested endpoints for a service.

func (*Client) WatchReplicationControllers

func (c *Client) WatchReplicationControllers(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)

WatchReplicationControllers returns a watch.Interface that watches the requested controllers.

func (*Client) WatchServices

func (c *Client) WatchServices(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)

WatchServices returns a watch.Interface that watches the requested services.

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(selector labels.Selector) (*api.EndpointsList, error)
	WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (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
	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) CreatePod

func (c *Fake) CreatePod(pod *api.Pod) (*api.Pod, error)

func (*Fake) CreateReplicationController

func (c *Fake) CreateReplicationController(controller *api.ReplicationController) (*api.ReplicationController, error)

func (*Fake) CreateService

func (c *Fake) CreateService(service *api.Service) (*api.Service, error)

func (*Fake) DeletePod

func (c *Fake) DeletePod(name string) error

func (*Fake) DeleteReplicationController

func (c *Fake) DeleteReplicationController(controller string) error

func (*Fake) DeleteService

func (c *Fake) DeleteService(service string) error

func (*Fake) GetPod

func (c *Fake) GetPod(name string) (*api.Pod, error)

func (*Fake) GetReplicationController

func (c *Fake) GetReplicationController(name string) (*api.ReplicationController, error)

func (*Fake) GetService

func (c *Fake) GetService(name string) (*api.Service, error)

func (*Fake) ListEndpoints

func (c *Fake) ListEndpoints(selector labels.Selector) (*api.EndpointsList, error)

func (*Fake) ListMinions

func (c *Fake) ListMinions() (*api.MinionList, error)

func (*Fake) ListPods

func (c *Fake) ListPods(selector labels.Selector) (*api.PodList, error)

func (*Fake) ListReplicationControllers

func (c *Fake) ListReplicationControllers(selector labels.Selector) (*api.ReplicationControllerList, error)

func (*Fake) ListServices

func (c *Fake) ListServices(selector labels.Selector) (*api.ServiceList, error)

func (*Fake) ServerVersion

func (c *Fake) ServerVersion() (*version.Info, error)

func (*Fake) UpdatePod

func (c *Fake) UpdatePod(pod *api.Pod) (*api.Pod, error)

func (*Fake) UpdateReplicationController

func (c *Fake) UpdateReplicationController(controller *api.ReplicationController) (*api.ReplicationController, error)

func (*Fake) UpdateService

func (c *Fake) UpdateService(service *api.Service) (*api.Service, error)

func (*Fake) WatchEndpoints

func (c *Fake) WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)

func (*Fake) WatchReplicationControllers

func (c *Fake) WatchReplicationControllers(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)

func (*Fake) WatchServices

func (c *Fake) WatchServices(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)

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, podID string) (api.PodInfo, error)

GetPodInfo is a fake implementation of PodInfoGetter.GetPodInfo.

type HTTPContainerInfoGetter

type HTTPContainerInfoGetter struct {
	Client *http.Client
	Port   int
}

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

type HTTPPodInfoGetter

type HTTPPodInfoGetter struct {
	Client *http.Client
	Port   uint
}

HTTPPodInfoGetter is the default implementation of PodInfoGetter, accesses the kubelet over HTTP.

func (*HTTPPodInfoGetter) GetPodInfo

func (c *HTTPPodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error)

GetPodInfo gets information about the specified pod.

type Interface

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, 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(selector labels.Selector) (*api.PodList, error)
	GetPod(id string) (*api.Pod, error)
	DeletePod(id string) error
	CreatePod(*api.Pod) (*api.Pod, error)
	UpdatePod(*api.Pod) (*api.Pod, error)
}

PodInterface has methods to work with Pod resources.

type RESTClient

type RESTClient struct {
	Sync       bool
	PollPeriod time.Duration
	Timeout    time.Duration
	Codec      runtime.Codec
	// contains filtered or unexported fields
}

RESTClient holds common code used to work with API resources that follow the Kubernetes API pattern. Host is the http://... base for the URL

func NewRESTClient

func NewRESTClient(host string, auth *AuthInfo, path string, c runtime.Codec) (*RESTClient, error)

NewRESTClient creates a new RESTClient. This client performs generic REST functions such as Get, Put, Post, and Delete on specified paths.

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) Secure

func (c *RESTClient) Secure() bool

Secure returns true if the client is configured for secure connections.

func (*RESTClient) Verb

func (c *RESTClient) Verb(verb string) *Request

Verb begins a request with a verb (GET, POST, PUT, DELETE).

Example usage of Client's request building interface: auth, err := LoadAuth(filename) c := New(url, auth) 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(selector labels.Selector) (*api.ReplicationControllerList, error)
	GetReplicationController(id string) (*api.ReplicationController, error)
	CreateReplicationController(*api.ReplicationController) (*api.ReplicationController, error)
	UpdateReplicationController(*api.ReplicationController) (*api.ReplicationController, error)
	DeleteReplicationController(string) error
	WatchReplicationControllers(label, field labels.Selector, resourceVersion uint64) (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) AbsPath

func (r *Request) AbsPath(path string) *Request

AbsPath overwrites an existing path with the path parameter.

func (*Request) Body

func (r *Request) Body(obj interface{}) *Request

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

func (r *Request) Do() Result

Do formats and executes the request. Returns the API object received, or an error.

func (*Request) ParseSelectorParam

func (r *Request) ParseSelectorParam(paramName, item string) *Request

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) Path

func (r *Request) Path(item string) *Request

Path appends an item to the request path. You must call Path at least once.

func (*Request) PollPeriod

func (r *Request) PollPeriod(d time.Duration) *Request

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

func (r *Request) SelectorParam(paramName string, s labels.Selector) *Request

SelectorParam adds the given selector as a query parameter with the name paramName.

func (*Request) Sync

func (r *Request) Sync(sync bool) *Request

Sync sets sync/async call status by setting the "sync" parameter to "true"/"false".

func (*Request) Timeout

func (r *Request) Timeout(d time.Duration) *Request

Timeout makes the request use the given duration as a timeout. Sets the "timeout" parameter. Ignored if sync=false.

func (*Request) UintParam

func (r *Request) UintParam(paramName string, u uint64) *Request

UintParam creates a query parameter with the given value.

func (*Request) Watch

func (r *Request) Watch() (watch.Interface, error)

Watch attempts to begin watching the requested location. Returns a watch.Interface, or an error.

type Result

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

Result contains the result of calling Request.Do().

func (Result) Error

func (r Result) Error() error

Error returns the error executing the request, nil if no error occurred.

func (Result) Get

func (r Result) Get() (runtime.Object, error)

Get returns the result as an object.

func (Result) Into

func (r Result) Into(obj runtime.Object) error

Into stores the result into obj, if possible.

func (Result) Raw

func (r Result) Raw() ([]byte, error)

Raw returns the raw result.

type ServiceInterface

type ServiceInterface interface {
	ListServices(selector labels.Selector) (*api.ServiceList, error)
	GetService(id string) (*api.Service, error)
	CreateService(*api.Service) (*api.Service, error)
	UpdateService(*api.Service) (*api.Service, error)
	DeleteService(string) error
	WatchServices(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
}

ServiceInterface has methods to work with Service resources.

type StatusErr

type StatusErr struct {
	Status api.Status
}

StatusErr might get returned from an api call if your request is still being processed and hence the expected return data is not available yet.

func (*StatusErr) Error

func (s *StatusErr) Error() string

type VersionInterface

type VersionInterface interface {
	ServerVersion() (*version.Info, error)
}

VersionInterface has a method to retrieve the server version.

Directories

Path Synopsis
Package cache is a client-side caching mechanism.
Package cache is a client-side caching mechanism.

Jump to

Keyboard shortcuts

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