AnyEvent::Kubernetes
version 0.01
AnyEvent::Kubernetes is an event driven interface to the Kubernetes REST API. The primary motivation for building this module is to expose some more advanced features of the API (watching) and allow some more advanced additional functionality (rolling-update), which really only make sense in an event driven set up.
my $kube = AnyEvent::Kubernetes->new(url=>'http://127.0.0.1:8080', username=>'dave', password=>'davespassword');
$kube->list_pods(onSuccess => sub{
my($pod_list) = @_;
}, onError => sub {
my($message) = @_;
print "Ohh no! An error occured: ".$message."\n";
});
$kube->list_pods(onChange => sub {
my($pod) = @_;
});
$kube->get_rc('my-controller', onSuccess => sub {
my $rc = shift;
$rc->spec->{template}{containers}[0]{image} = 'myimages/image:release-12345';
$rc->rolling_update(onSuccess=> sub {
print "Woot! rolling update successfull\n";
});
});
Most methods take a couple of standard arguments.
- onSuccess => sub { ... }
-
onSuccess is accepted by almost all methods, and will be invocked upon successfull completion of the operation. The supplied callback will be passed the involved oject, either a Resource object or a ResourceList Object.
- onError => sub { }
-
onError is also accepted by almost all methods, and is simply the converse of onSuccess. The supplied callback will be passed a message which could be a simple string, or a hasref. Simple strings generally indicate a communication failure with the api server, a hashref would be the decoded response from kubernetes.
- onChange => sub { ... }
-
onChange is an optional argument to all "list" methods which will fundementally change the behavoir of the function, and should not be used in conjunction with onSuccess. When onChange is supplied, the resulting connection to kubernetes api will be a streaming connection sending real time updates for changes to any of the resources in the resulting list. The onChange callback will be evoked continuously every time a resource changes, and will be passed the resource object which changed, as well as the type of change (ADDED|MODIFIED|DELETED). It will also be called once for each item in the list (with a type of ADDED) immediately which will allow the building of an initial list.
When onChange is supplied, the method will return a code reference which is effectively a cancellation callback. When you want to stop listening for changes to the list, invoke this callback and the persisten connection to the API server will be terminated, and the onChange callback will no longer be called.
All "list" methods accept the following parameters to filter the list of returned resources.
- labels => {}
-
The supplied hashref of key value pairs will be translated into labelSelector's for the kubernetes api.
- fields => {}
-
The supplied hashref of key value pairs will be translated into fieldSelector's for the kubernetes api.
Creates a new instance of AnyEvent::Kubernetes.
Required Arguments:
- url
-
The base url to the kubernetes api. For Example http://172.18.8.101:8080/api/v1
Optional Arguments:
- username, password
-
Credentials used to authenticate to the kubernetes API server.
- ssl_cert_file, ssl_key_file, ssl_ca_file
-
SSL certificate key and CA for client cert based authentication to kubernetes
- ssl_verify
-
Boolean flag to verify the source of the kubenetes server certificate. Defaults to true.
- token
-
An authorization token to be sent to kubernetes
List kubernetes name spaces.
Fetch a specific namespace by name
List kubernetes name spaces.
List kubernetes minions/nodes.
Get a specific node.
Create a new kubernetes resource. This method accepts either a path to a json or yaml file or a hashref of the equivelent datastructure.
The following methods can be called on the kube object and will be automatically delegated to the default namespace
- list_pods
- list_services
- list_replication_controllers
- list_rc
- list_events
- list_endpoints
- list_secrets
- get_rc
- get_service
- get_pod
- get_event
See AnyEvent::Kubernetes::Rescource::Namepsace for details on each of these.