| 1 | package Net::Kubernetes::Resource::Node; | ||||||||||
| 2 | # ABSTRACT: Object representatioon of a Kubernetes Pod | ||||||||||
| 3 | 4 | $Net::Kubernetes::Resource::Node::VERSION = '1.03'; | |||||||||
| 4 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | extends 'Net::Kubernetes::Resource'; | |||||||||
| 7 | |||||||||||
| 8 | 4 | with 'Net::Kubernetes::Resource::Role::State'; | |||||||||
| 9 | 4 | with 'Net::Kubernetes::Resource::Role::Spec'; | |||||||||
| 10 | |||||||||||
| 11 | 3 | ▶ | sub get_pods { | ||||||||
|
Subroutine
get_pods: called CC=7 SCAR=25.7
Pod
undocumented
| |||||||||||
| 12 | 3 | my($self) = shift; | |||||||||
| 13 | 3 | my $uri = URI->new($self->url.'/api/'.$self->api_version.'/pods'); | |||||||||
| 14 | 3 | my $selector = {}; | |||||||||
| 15 | 3 | ▶ | if($self->api_version eq 'v1'){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 3 | $selector->{'spec.nodeName'} = $self->metadata->{name}; | |||||||||
| 17 | }else{ | ||||||||||
| 18 | 0 | $selector->{'spec.host'} = $self->metadata->{name}; | |||||||||
| 19 | } | ||||||||||
| 20 | 3 | $uri->query_form(fieldSelector=>$self->_build_selector_from_hash($selector)); | |||||||||
| 21 | 3 | print "Query with $uri\n"; | |||||||||
| 22 | 3 | my $res = $self->ua->request($self->create_request(GET => $uri)); | |||||||||
| 23 | 3 | ▶ | if ($res->is_success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 3 | my $pod_list = $self->json->decode($res->content); | |||||||||
| 25 | 3 | my(@pods)=(); | |||||||||
| 26 | 3 | foreach my $pod (@{ $pod_list->{items}}){ | |||||||||
| 27 | 0 | $pod->{apiVersion} = $pod_list->{apiVersion}; | |||||||||
| 28 | 0 | my(%create_args) = %$pod; | |||||||||
| 29 | 0 | $create_args{api_version} = $pod->{apiVersion}; | |||||||||
| 30 | 0 | ▶ | $create_args{username} = $self->username if($self->username); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | ▶ | $create_args{password} = $self->password if($self->password); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | $create_args{url} = $self->url; | |||||||||
| 33 | 0 | $create_args{base_path} = $pod->{metadata}{selfLink}; | |||||||||
| 34 | 0 | push @pods, Net::Kubernetes::Resource::Pod->new(%create_args); | |||||||||
| 35 | } | ||||||||||
| 36 | 3 | ▶ | return wantarray ? @pods : \@pods; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | }else{ | ||||||||||
| 38 | 0 | Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message); | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 3 | ▶ | sub _build_selector_from_hash { | ||||||||
|
Subroutine
_build_selector_from_hash: called CC=2 SCAR=6.9
| |||||||||||
| 43 | 3 | my($self, $select_hash) = @_; | |||||||||
| 44 | 3 | my(@selectors); | |||||||||
| 45 | 3 | foreach my $label (keys %{ $select_hash }){ | |||||||||
| 46 | 3 | push @selectors, $label.'='.$select_hash->{$label}; | |||||||||
| 47 | } | ||||||||||
| 48 | 3 | return join(",", @selectors); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 4 | return 42; | |||||||||
| 52 | |||||||||||
| 53 | __END__ | ||||||||||