Skip to content

perljedi/perl-anyevent-kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

AnyEvent::Kubernetes

VERSION

version 0.01

Description

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.

SYNOPSIS

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";
  });
});

Standard Arguments

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.

List Filtering arguments

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.

Methods

new

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_namespaces

List kubernetes name spaces.

get_namespace("default")

Fetch a specific namespace by name

list_service_accounts

List kubernetes name spaces.

list_nodes

List kubernetes minions/nodes.

get_node("myNode")

Get a specific node.

create(FILENAME | {})

Create a new kubernetes resource. This method accepts either a path to a json or yaml file or a hashref of the equivelent datastructure.

Delegated Methods

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages