Kubernetes/Resource/Node.pm

filter: Statementstmt 75.6% 31 / 41 Branchbran 30.0% 3 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 67.8% 38 / 56 CC 8 SCAR 21.9
CC
8
Cov
67%
get_pods
13.1
_build_selector_from_hash
2.0
BEGIN
1.0
CRAP 8.9
« Kubernetes/Resource/ReplicationController.pm ↑ Summary Kubernetes/Resource/Role/HasPods.pm »
1 package Net::Kubernetes::Resource::Node;
2 # ABSTRACT: Object representatioon of a Kubernetes Pod
3 4 $Net::Kubernetes::Resource::Node::VERSION = '0.19';
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 sub get_pods {
12 3 ▶ my($self) = shift;
Subroutine get_pods: called CC=7 SCAR=25.7
Pod undocumented
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
BranchTrueFalseTotal
if ($self->api_version eq 'v1') { } 3 0 3
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
BranchTrueFalseTotal
if ($res->is_success) { } 3 0 3
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
BranchTrueFalseTotal
if $self->username 0 0 0
31 0 ▶ $create_args{password} = $self->password if($self->password);
Branch: 1 branch
BranchTrueFalseTotal
if $self->password 0 0 0
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
BranchTrueFalseTotal
wantarray ? : 0 3 3
37 }else{
38 0 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
39 }
40 }
41  
42 sub _build_selector_from_hash {
43 3 ▶ my($self, $select_hash) = @_;
Subroutine _build_selector_from_hash: called CC=2 SCAR=6.9
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__
54  
55 =pod
56  
57 =encoding UTF-8
58  
59 =head1 NAME
60  
61 Net::Kubernetes::Resource::Node - Object representatioon of a Kubernetes Pod
62  
63 =head1 VERSION
64  
65 version 0.19
66  
67 =head1 AUTHOR
68  
69 Dave Mueller <dave@perljedi.com>
70  
71 =head1 COPYRIGHT AND LICENSE
72  
73 This software is Copyright (c) 2015 by Dave Mueller.
74  
75 This is free software, licensed under:
76  
77 The MIT (X11) License
78  
79 =head1 SEE ALSO
80  
81 Please see those modules/websites for more information related to this module.
82  
83 =over 4
84  
85 =item *
86  
87 L<Net::Kubernetes|Net::Kubernetes>
88  
89 =back
90  
91 =head1 CONSUMES
92  
93 =over 4
94  
95 =item * L<Net::Kubernetes::Resource::Role::Spec>
96  
97 =item * L<Net::Kubernetes::Resource::Role::State>
98  
99 =back
100  
101 =cut
« Kubernetes/Resource/ReplicationController.pm ↑ Summary Kubernetes/Resource/Role/HasPods.pm »