Documentation
¶
Overview ¶
Package unversioned 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, daemons, services, and nodes.
Most consumers should use the Config object to create a Client:
import (
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
)
[...]
config := &client.Config{
Host: "http://localhost:8080",
Username: "test",
Password: "password",
}
client, err := client.New(config)
if err != nil {
// handle error
}
pods, err := client.Pods(api.NamespaceDefault).List(labels.Everything(), fields.Everything())
if err != nil {
// handle error
}
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/devel/api-conventions.md`) for a given API path and is intended for use by consumers implementing their own Kubernetes compatible APIs.
Index ¶
- Constants
- Variables
- func ControllerHasDesiredReplicas(c Interface, controller *api.ReplicationController) wait.ConditionFunc
- func DeploymentHasDesiredReplicas(c ExtensionsInterface, deployment *extensions.Deployment) wait.ConditionFunc
- func GetInvolvedObjectNameFieldLabel(version string) string
- func IsTimeout(err error) bool
- func JobHasDesiredParallelism(c ExtensionsInterface, job *extensions.Job) wait.ConditionFunc
- func MatchesServerVersion(client *Client, c *restclient.Config) error
- func NegotiateVersion(client *Client, c *restclient.Config, requestedGV *unversioned.GroupVersion, ...) (*unversioned.GroupVersion, error)
- func ReplicaSetHasDesiredReplicas(c ExtensionsInterface, replicaSet *extensions.ReplicaSet) wait.ConditionFunc
- func RetryOnConflict(backoff wait.Backoff, fn func() error) error
- func SetKubernetesDefaults(config *restclient.Config) error
- type AutoscalingClient
- type AutoscalingInterface
- type BatchClient
- type BatchInterface
- type Client
- func (c *Client) Autoscaling() AutoscalingInterface
- func (c *Client) Batch() BatchInterface
- func (c *Client) ComponentStatuses() ComponentStatusInterface
- func (c *Client) ConfigMaps(namespace string) ConfigMapsInterface
- func (c *Client) Discovery() discovery.DiscoveryInterface
- func (c *Client) Endpoints(namespace string) EndpointsInterface
- func (c *Client) Events(namespace string) EventInterface
- func (c *Client) Extensions() ExtensionsInterface
- func (c *Client) LimitRanges(namespace string) LimitRangeInterface
- func (c *Client) Namespaces() NamespaceInterface
- func (c *Client) Nodes() NodeInterface
- func (c *Client) PersistentVolumeClaims(namespace string) PersistentVolumeClaimInterface
- func (c *Client) PersistentVolumes() PersistentVolumeInterface
- func (c *Client) PodTemplates(namespace string) PodTemplateInterface
- func (c *Client) Pods(namespace string) PodInterface
- func (c *Client) ReplicationControllers(namespace string) ReplicationControllerInterface
- func (c *Client) ResourceQuotas(namespace string) ResourceQuotaInterface
- func (c *Client) Secrets(namespace string) SecretsInterface
- func (c *Client) ServiceAccounts(namespace string) ServiceAccountsInterface
- func (c *Client) Services(namespace string) ServiceInterface
- type ComponentStatusInterface
- type ComponentStatusesInterface
- type ConfigMaps
- func (c *ConfigMaps) Create(cfg *api.ConfigMap) (*api.ConfigMap, error)
- func (c *ConfigMaps) Delete(name string) error
- func (c *ConfigMaps) Get(name string) (*api.ConfigMap, error)
- func (c *ConfigMaps) List(opts api.ListOptions) (*api.ConfigMapList, error)
- func (c *ConfigMaps) Update(cfg *api.ConfigMap) (*api.ConfigMap, error)
- func (c *ConfigMaps) Watch(opts api.ListOptions) (watch.Interface, error)
- type ConfigMapsInterface
- type ConfigMapsNamespacer
- type ContainerInfoGetter
- type DaemonSetInterface
- type DaemonSetsNamespacer
- type DeploymentInterface
- type DeploymentsNamespacer
- type EndpointsInterface
- type EndpointsNamespacer
- type EventInterface
- type EventNamespacer
- type ExtensionsClient
- func (c *ExtensionsClient) DaemonSets(namespace string) DaemonSetInterface
- func (c *ExtensionsClient) Deployments(namespace string) DeploymentInterface
- func (c *ExtensionsClient) HorizontalPodAutoscalers(namespace string) HorizontalPodAutoscalerInterface
- func (c *ExtensionsClient) Ingress(namespace string) IngressInterface
- func (c *ExtensionsClient) Jobs(namespace string) JobInterface
- func (c *ExtensionsClient) PodSecurityPolicies() PodSecurityPolicyInterface
- func (c *ExtensionsClient) ReplicaSets(namespace string) ReplicaSetInterface
- func (c *ExtensionsClient) Scales(namespace string) ScaleInterface
- func (c *ExtensionsClient) ThirdPartyResources(namespace string) ThirdPartyResourceInterface
- type ExtensionsInterface
- type FlagSet
- type HTTPContainerInfoGetter
- func (self *HTTPContainerInfoGetter) GetContainerInfo(host, podID, containerID string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error)
- func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*cadvisorapi.MachineInfo, error)
- func (self *HTTPContainerInfoGetter) GetRootInfo(host string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error)
- type HorizontalPodAutoscalerInterface
- type HorizontalPodAutoscalersNamespacer
- type IngressInterface
- type IngressNamespacer
- type Interface
- type JobInterface
- type JobsNamespacer
- type LimitRangeInterface
- type LimitRangesNamespacer
- type NamespaceInterface
- type NamespacesInterface
- type NodeInterface
- type NodesInterface
- type PersistentVolumeClaimInterface
- type PersistentVolumeClaimsNamespacer
- type PersistentVolumeInterface
- type PersistentVolumesInterface
- type PodInterface
- type PodSecurityPoliciesInterface
- type PodSecurityPolicyInterface
- type PodTemplateInterface
- type PodTemplatesNamespacer
- type PodsNamespacer
- type ReplicaSetInterface
- type ReplicaSetsNamespacer
- type ReplicationControllerInterface
- type ReplicationControllersNamespacer
- type ResourceQuotaInterface
- type ResourceQuotasNamespacer
- type ScaleInterface
- type ScaleNamespacer
- type SecretsInterface
- type SecretsNamespacer
- type ServiceAccountsInterface
- type ServiceAccountsNamespacer
- type ServiceInterface
- type ServicesNamespacer
- type ThirdPartyResourceInterface
- type ThirdPartyResourceNamespacer
Constants ¶
const (
ConfigMapResourceName string = "configmaps"
)
Variables ¶
var DefaultBackoff = wait.Backoff{ Steps: 4, Duration: 10 * time.Millisecond, Factor: 5.0, Jitter: 0.1, }
DefaultBackoff is the recommended backoff for a conflict where a client may be attempting to make an unrelated modification to a resource under active management by one or more controllers.
var DefaultRetry = wait.Backoff{ Steps: 5, Duration: 10 * time.Millisecond, Factor: 1.0, Jitter: 0.1, }
DefaultRetry is the recommended retry for a conflict where multiple clients are making changes to the same resource.
Functions ¶
func ControllerHasDesiredReplicas ¶
func ControllerHasDesiredReplicas(c Interface, controller *api.ReplicationController) wait.ConditionFunc
ControllerHasDesiredReplicas returns a condition that will be true if and only if the desired replica count for a controller's ReplicaSelector equals the Replicas count.
func DeploymentHasDesiredReplicas ¶ added in v1.2.0
func DeploymentHasDesiredReplicas(c ExtensionsInterface, deployment *extensions.Deployment) wait.ConditionFunc
DeploymentHasDesiredReplicas returns a condition that will be true if and only if the desired replica count for a deployment equals its updated replicas count. (non-terminated pods that have the desired template spec).
func GetInvolvedObjectNameFieldLabel ¶ added in v1.2.0
Returns the appropriate field label to use for name of the involved object as per the given API version.
func IsTimeout ¶
IsTimeout tests if this is a timeout error in the underlying transport. This is unbelievably ugly. See: http://stackoverflow.com/questions/23494950/specifically-check-for-timeout-error for details
func JobHasDesiredParallelism ¶
func JobHasDesiredParallelism(c ExtensionsInterface, job *extensions.Job) wait.ConditionFunc
JobHasDesiredParallelism returns a condition that will be true if the desired parallelism count for a job equals the current active counts or is less by an appropriate successful/unsuccessful count.
func MatchesServerVersion ¶
func MatchesServerVersion(client *Client, c *restclient.Config) error
MatchesServerVersion queries the server to compares the build version (git hash) of the client with the server's build version. It returns an error if it failed to contact the server or if the versions are not an exact match.
func NegotiateVersion ¶
func NegotiateVersion(client *Client, c *restclient.Config, requestedGV *unversioned.GroupVersion, clientRegisteredGVs []unversioned.GroupVersion) (*unversioned.GroupVersion, error)
NegotiateVersion queries the server's supported api versions to find a version that both client and server support.
- If no version is provided, try registered client versions in order of preference.
- If version is provided, but not default config (explicitly requested via commandline flag), and is unsupported by the server, print a warning to stderr and try client's registered versions in order of preference.
- If version is config default, and the server does not support it, return an error.
func ReplicaSetHasDesiredReplicas ¶ added in v1.2.0
func ReplicaSetHasDesiredReplicas(c ExtensionsInterface, replicaSet *extensions.ReplicaSet) wait.ConditionFunc
ReplicaSetHasDesiredReplicas returns a condition that will be true if and only if the desired replica count for a ReplicaSet's ReplicaSelector equals the Replicas count.
func RetryOnConflict ¶ added in v1.2.0
RetryConflict executes the provided function repeatedly, retrying if the server returns a conflicting write. Callers should preserve previous executions if they wish to retry changes. It performs an exponential backoff.
var pod *api.Pod
err := RetryOnConflict(DefaultBackoff, func() (err error) {
pod, err = c.Pods("mynamespace").UpdateStatus(podStatus)
return
})
if err != nil {
// may be conflict if max retries were hit
return err
}
...
TODO: Make Backoff an interface?
func SetKubernetesDefaults ¶
func SetKubernetesDefaults(config *restclient.Config) error
SetKubernetesDefaults sets default values on the provided client config for accessing the Kubernetes API or returns an error if any of the defaults are impossible or invalid. TODO: this method needs to be split into one that sets defaults per group, expected to be fix in PR "Refactoring clientcache.go and helper.go #14592"
Types ¶
type AutoscalingClient ¶ added in v1.2.0
type AutoscalingClient struct {
*restclient.RESTClient
}
AutoscalingClient is used to interact with Kubernetes autoscaling features.
func NewAutoscaling ¶ added in v1.2.0
func NewAutoscaling(c *restclient.Config) (*AutoscalingClient, error)
func NewAutoscalingOrDie ¶ added in v1.2.0
func NewAutoscalingOrDie(c *restclient.Config) *AutoscalingClient
func (*AutoscalingClient) HorizontalPodAutoscalers ¶ added in v1.2.0
func (c *AutoscalingClient) HorizontalPodAutoscalers(namespace string) HorizontalPodAutoscalerInterface
type AutoscalingInterface ¶ added in v1.2.0
type AutoscalingInterface interface {
HorizontalPodAutoscalersNamespacer
}
type BatchClient ¶ added in v1.2.0
type BatchClient struct {
*restclient.RESTClient
}
BatchClient is used to interact with Kubernetes batch features.
func NewBatch ¶ added in v1.2.0
func NewBatch(c *restclient.Config) (*BatchClient, error)
func NewBatchOrDie ¶ added in v1.2.0
func NewBatchOrDie(c *restclient.Config) *BatchClient
func (*BatchClient) Jobs ¶ added in v1.2.0
func (c *BatchClient) Jobs(namespace string) JobInterface
type BatchInterface ¶ added in v1.2.0
type BatchInterface interface {
JobsNamespacer
}
type Client ¶
type Client struct {
*restclient.RESTClient
*AutoscalingClient
*BatchClient
*ExtensionsClient
*discovery.DiscoveryClient
}
Client is the implementation of a Kubernetes client.
func New ¶
func New(c *restclient.Config) (*Client, error)
New creates a Kubernetes client for the given config. This client works with pods, replication controllers, daemons, 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 NewInCluster ¶
NewInCluster is a shortcut for calling InClusterConfig() and then New().
func NewOrDie ¶
func NewOrDie(c *restclient.Config) *Client
NewOrDie creates a Kubernetes client and panics if the provided API version is not recognized.
func (*Client) Autoscaling ¶ added in v1.2.0
func (c *Client) Autoscaling() AutoscalingInterface
func (*Client) Batch ¶ added in v1.2.0
func (c *Client) Batch() BatchInterface
func (*Client) ComponentStatuses ¶
func (c *Client) ComponentStatuses() ComponentStatusInterface
func (*Client) ConfigMaps ¶ added in v1.2.0
func (c *Client) ConfigMaps(namespace string) ConfigMapsInterface
func (*Client) Discovery ¶ added in v1.1.1
func (c *Client) Discovery() discovery.DiscoveryInterface
func (*Client) Endpoints ¶
func (c *Client) Endpoints(namespace string) EndpointsInterface
func (*Client) Events ¶
func (c *Client) Events(namespace string) EventInterface
func (*Client) Extensions ¶ added in v1.1.1
func (c *Client) Extensions() ExtensionsInterface