| 1 | package Net::Kubernetes::Resource::Role::HasPods; | ||||||||||
| 2 | # ABSTRACT: Resource role for types that may contain pods | ||||||||||
| 3 | 4 | $Net::Kubernetes::Resource::Role::HasPods::VERSION = '0.19'; | |||||||||
| 4 | 4 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 4 | with 'Net::Kubernetes::Role::APIAccess'; | |||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | sub get_pods { | ||||||||||
| 10 | 4 | ▶ | my($self) = @_; | ||||||||
|
Subroutine
get_pods: called CC=6 SCAR=25.0
Pod
documented
| |||||||||||
| 11 | 4 | my $uri = URI->new_abs("../pods", $self->path); | |||||||||
| 12 | 4 | $uri->query_form(labelSelector=>$self->_build_selector_from_hash($self->spec->{selector})); | |||||||||
| 13 | 4 | my $res = $self->ua->request($self->create_request(GET => $uri)); | |||||||||
| 14 | 4 | ▶ | if ($res->is_success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 4 | my $pod_list = $self->json->decode($res->content); | |||||||||
| 16 | 4 | my(@pods)=(); | |||||||||
| 17 | 4 | foreach my $pod (@{ $pod_list->{items}}){ | |||||||||
| 18 | 0 | $pod->{apiVersion} = $pod_list->{apiVersion}; | |||||||||
| 19 | 0 | my(%create_args) = %$pod; | |||||||||
| 20 | 0 | $create_args{api_version} = $pod->{apiVersion}; | |||||||||
| 21 | 0 | ▶ | $create_args{username} = $self->username if($self->username); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | ▶ | $create_args{password} = $self->password if($self->password); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | $create_args{url} = $self->url; | |||||||||
| 24 | 0 | $create_args{base_path} = $pod->{metadata}{selfLink}; | |||||||||
| 25 | 0 | push @pods, Net::Kubernetes::Resource::Pod->new(%create_args); | |||||||||
| 26 | } | ||||||||||
| 27 | 4 | ▶ | return wantarray ? @pods : \@pods; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | }else{ | ||||||||||
| 29 | 0 | Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message); | |||||||||
| 30 | } | ||||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | sub _build_selector_from_hash { | ||||||||||
| 34 | 4 | ▶ | my($self, $select_hash) = @_; | ||||||||
|
Subroutine
_build_selector_from_hash: called CC=2 SCAR=6.9
| |||||||||||
| 35 | 4 | my(@selectors); | |||||||||
| 36 | 4 | foreach my $label (keys %{ $select_hash }){ | |||||||||
| 37 | 4 | push @selectors, $label.'='.$select_hash->{$label}; | |||||||||
| 38 | } | ||||||||||
| 39 | 4 | return join(",", @selectors); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 4 | return 42; | |||||||||
| 43 | |||||||||||
| 44 | __END__ | ||||||||||
| 45 | |||||||||||
| 46 | =pod | ||||||||||
| 47 | |||||||||||
| 48 | =encoding UTF-8 | ||||||||||
| 49 | |||||||||||
| 50 | =head1 NAME | ||||||||||
| 51 | |||||||||||
| 52 | Net::Kubernetes::Resource::Role::HasPods - Resource role for types that may contain pods | ||||||||||
| 53 | |||||||||||
| 54 | =head1 VERSION | ||||||||||
| 55 | |||||||||||
| 56 | version 0.19 | ||||||||||
| 57 | |||||||||||
| 58 | =head1 METHODS | ||||||||||
| 59 | |||||||||||
| 60 | =head2 get_pods | ||||||||||
| 61 | |||||||||||
| 62 | retreive a list of pods associated with with respource (either ReplicationController or Service) | ||||||||||
| 63 | |||||||||||
| 64 | =head1 AUTHOR | ||||||||||
| 65 | |||||||||||
| 66 | Dave Mueller <dave@perljedi.com> | ||||||||||
| 67 | |||||||||||
| 68 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 69 | |||||||||||
| 70 | This software is Copyright (c) 2015 by Dave Mueller. | ||||||||||
| 71 | |||||||||||
| 72 | This is free software, licensed under: | ||||||||||
| 73 | |||||||||||
| 74 | The MIT (X11) License | ||||||||||
| 75 | |||||||||||
| 76 | =head1 SEE ALSO | ||||||||||
| 77 | |||||||||||
| 78 | Please see those modules/websites for more information related to this module. | ||||||||||
| 79 | |||||||||||
| 80 | =over 4 | ||||||||||
| 81 | |||||||||||
| 82 | =item * | ||||||||||
| 83 | |||||||||||
| 84 | L<Net::Kubernetes|Net::Kubernetes> | ||||||||||
| 85 | |||||||||||
| 86 | =back | ||||||||||
| 87 | |||||||||||
| 88 | =head1 CONSUMES | ||||||||||
| 89 | |||||||||||
| 90 | =over 4 | ||||||||||
| 91 | |||||||||||
| 92 | =item * L<Net::Kubernetes::Role::APIAccess> | ||||||||||
| 93 | |||||||||||
| 94 | =back | ||||||||||
| 95 | |||||||||||
| 96 | =cut | ||||||||||