Kubernetes.pm

filter: Statementstmt 92.4% 73 / 79 Branchbran 77.7% 28 / 36 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 84.0% 111 / 132 CC 23 SCAR 19.3
CC
23
Cov
86%
get_namespace
9.6
list_nodes
7.0
list_service_accounts
7.0
CRAP 6.9
« Kubernetes/Role/ResourceCreator.pm ↑ Summary Kubernetes/Role/APIAccess.pm »
1 package Net::Kubernetes;
2 # ABSTRACT: An object oriented interface to the REST API's provided by kubernetes
3 4 $Net::Kubernetes::VERSION = '1.03';
4 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 require Net::Kubernetes::Namespace;
6 4 require LWP::UserAgent;
7 4 require HTTP::Request;
8 4 require URI;;
9 4 require Throwable::Error;
10 4 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 require Net::Kubernetes::Exception;
12  
13  
14 4 with 'Net::Kubernetes::Role::APIAccess';
15 4 with 'Net::Kubernetes::Role::ResourceLister';
16 4 with 'Net::Kubernetes::Role::ResourceFetcher';
17  
18  
19 4 has 'default_namespace' => (
20 is => 'rw',
21 isa => 'Net::Kubernetes::Namespace',
22 required => 0,
23 lazy => 1,
24 handles => [qw(get_pod get_rc get_replication_controller get_secret get_service create create_from_file build_secret)],
25 builder => '_get_default_namespace',
26 );
27  
28 4 ▶sub get_namespace {
Subroutine get_namespace: called CC=9 SCAR=22.6
29 4 my($self, $namespace) = @_;
30 4 ▶ if (! defined $namespace || ! length $namespace) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $namespace and length $namespace) 1 3 4
Condition66%2/3
defined $namespace and length $namespace
!ll&&!rl&&r
103
MC/DC50%1/2
defined $namespace and length $namespace
defined $namespace length $namespace
Truth table66%2/3
A and B
A= defined $namespaceB= length $namespace
ABresult
0X0
100
111
31 1 Throwable::Error->throw(message=>'$namespace cannot be null');
32 }
33 3 my $res = $self->ua->request($self->create_request(GET => $self->path.'/namespaces/'.$namespace));
34 3 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 2 1 3
35 2 my $ns = $self->json->decode($res->content);
36 2 my(%create_args) = (url => $self->url, base_path=>$ns->{metadata}{selfLink}, api_version=>$self->api_version, namespace=> $namespace, _namespace_data=>$ns);
37 2 ▶ $create_args{username} = $self->username if(defined $self->username);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->username 0 2 2
38 2 ▶ $create_args{password} = $self->password if(defined $self->password);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->password 0 2 2
39 2 ▶ $create_args{ssl_cert_file} = $self->ssl_cert_file if(defined $self->ssl_cert_file);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->ssl_cert_file 0 2 2
40 2 ▶ $create_args{ssl_key_file} = $self->ssl_key_file if(defined $self->ssl_key_file);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->ssl_key_file 0 2 2
41 2 ▶ $create_args{ssl_ca_file} = $self->ssl_ca_file if(defined $self->ssl_ca_file);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->ssl_ca_file 0 2 2
42 2 return Net::Kubernetes::Namespace->new(%create_args);
43 }else{
44 1 Net::Kubernetes::Exception->throw(code=>$res->code, message=>"Error getting namespace $namespace:\n".$res->message);
45 }
46 }
47  
48  
49 5 ▶sub list_nodes {
Subroutine list_nodes: called CC=7 SCAR=19.5
50 5 my $self = shift;
51 5 my(%options);
52 5 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 5 5
53 0 %options = %{ $_[0] };
54 }else{
55 5 %options = @_;
56 }
57  
58 5 my $uri = URI->new($self->path.'/nodes');
59 5 my(%form) = ();
60 5 ▶ $form{labelSelector}=$self->_build_selector_from_hash($options{labels}) if (exists $options{labels});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"labels"} 1 4 5
61 5 ▶ $form{fieldSelector}=$self->_build_selector_from_hash($options{fields}) if (exists $options{fields});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"fields"} 1 4 5
62 5 $uri->query_form(%form);
63  
64 5 my $res = $self->ua->request($self->create_request(GET => $uri));
65 5 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 4 1 5
66 4 my $node_list = $self->json->decode($res->content);
67 4 my(@nodes)=();
68 4 foreach my $node (@{ $node_list->{items}}){
69 1 $node->{apiVersion} = $node_list->{apiVersion};
70 1 push @nodes, $self->create_resource_object($node, 'Node');
71 }
72 4 ▶ return wantarray ? @nodes : \@nodes;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 3 4
73 }else{
74 1 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
75 }
76 }
77  
78 2 ▶sub get_node {
Subroutine get_node: called CC=3 SCAR=12.5
79 2 my($self, $name) = @_;
80 2 ▶ Net::Kubernetes::Exception->throw(message=>"Missing required parameter 'name'") if(! defined $name || ! length $name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 2 2
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
002
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
81 2 return $self->get_resource_by_name($name, 'nodes');
82 }
83  
84  
85 5 ▶sub list_service_accounts {
Subroutine list_service_accounts: called CC=7 SCAR=19.5
86 5 my $self = shift;
87 5 my(%options);
88 5 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 5 5
89 0 %options = %{ $_[0] };
90 }else{
91 5 %options = @_;
92 }
93  
94 5 my $uri = URI->new($self->path.'/serviceaccounts');
95 5 my(%form) = ();
96 5 ▶ $form{labelSelector}=$self->_build_selector_from_hash($options{labels}) if (exists $options{labels});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"labels"} 1 4 5
97 5 ▶ $form{fieldSelector}=$self->_build_selector_from_hash($options{fields}) if (exists $options{fields});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"fields"} 1 4 5
98 5 $uri->query_form(%form);
99  
100 5 my $res = $self->ua->request($self->create_request(GET => $uri));
101 5 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 4 1 5
102 4 my $sa_list = $self->json->decode($res->content);
103 4 my(@saccs)=();
104 4 foreach my $sacc (@{ $sa_list->{items}}){
105 1 $sacc->{apiVersion} = $sa_list->{apiVersion};
106 1 push @saccs, $self->create_resource_object($sacc, 'ServiceAccount');
107 }
108 4 ▶ return wantarray ? @saccs : \@saccs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 3 4
109 }else{
110 1 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
111 }
112 }
113  
114  
115 0 ▶sub _get_default_namespace {
Subroutine _get_default_namespace: not called CC=1 SCAR=6.9
116 0 my($self) = @_;
117 0 return $self->get_namespace('default');
118 }
119  
120 # SEEALSO: Net::Kubernetes::Namespace, Net::Kubernetes::Resource
121  
122 4 return 42;
123  
124 __END__
« Kubernetes/Role/ResourceCreator.pm ↑ Summary Kubernetes/Role/APIAccess.pm »