| 1 | package Kubernetes::Comb::Client::Sync; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Synchronous Comb client on Kubernetes::REST, returning done Futures | ||||||||||||||||||||||||||||
| 3 | 19 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 19 | with 'Kubernetes::Comb::Role::Client'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 19 | ▶ | use Types::Standard qw( InstanceOf Str ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 19 | ▶ | use Kubernetes::REST; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 19 | ▶ | use Kubernetes::REST::Kubeconfig; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 19 | ▶ | use Kubernetes::Comb::CRD; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 19 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 19 | has kubeconfig => ( is => 'ro', isa => Str, predicate => 1 ); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 19 | has context => ( is => 'ro', isa => Str, predicate => 1 ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 19 | has rest => ( is => 'lazy', isa => InstanceOf['Kubernetes::REST'] ); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 4 | ▶ | sub _build_rest { | ||||||||||||||||||||||||||
|
Subroutine
_build_rest: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 25 | 4 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 26 | 4 | ▶ | my $api = Kubernetes::REST::Kubeconfig->new( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 27 | ( $self->has_kubeconfig ? ( kubeconfig_path => $self->kubeconfig ) : () ), | ||||||||||||||||||||||||||||
| 28 | ( $self->has_context ? ( context_name => $self->context ) : () ) | ||||||||||||||||||||||||||||
| 29 | )->api; | ||||||||||||||||||||||||||||
| 30 | 2 | return Kubernetes::REST->new( | |||||||||||||||||||||||||||
| 31 | server => $api->server, | ||||||||||||||||||||||||||||
| 32 | credentials => $api->credentials, | ||||||||||||||||||||||||||||
| 33 | with => [ Kubernetes::Comb::CRD->new ] | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 6 | ▶ | sub get { shift->_call( get => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | sub list { shift->_call( list => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub ensure { shift->_call( ensure => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
ensure: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 4 | ▶ | sub delete { shift->_call( delete => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | sub update { shift->_call( update => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
update: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | sub patch { shift->_call( patch => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
patch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub update_status { shift->_call( update_status => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
update_status: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | sub patch_status { shift->_call( patch_status => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
patch_status: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | sub log { shift->_call( log => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
log: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 19 | ▶ | sub _call { | ||||||||||||||||||||||||||
|
Subroutine
_call: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 19 | my ( $self, $method, @args ) = @_; | |||||||||||||||||||||||||||
| 50 | 19 | ▶ | return Future->call( sub { Future->done( scalar $self->rest->$method(@args) ) } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | ▶ | sub server_url { shift->rest->server->endpoint } | ||||||||||||||||||||||||||
|
Subroutine
server_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 12 | ▶ | has _for_context => ( is => 'ro', init_arg => undef, default => sub { {} } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 3 | ▶ | sub for_context { | ||||||||||||||||||||||||||
|
Subroutine
for_context: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 3 | my ( $self, $context ) = @_; | |||||||||||||||||||||||||||
| 61 | 3 | ▶ | return $self->_for_context->{$context} //= ref($self)->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_for_context->{$context} //= ref($self)->new($self->has_kubeconfig ? ("kubeconfig", $self->kubeconfig) : (), "context", $context)
MC/DC0%0/2
$self->_for_context->{$context} //= ref($self)->new($self->has_kubeconfig ? ("kubeconfig", $self->kubeconfig) : (), "context", $context)
$self->_for_context->{$context}
ref($self)->new($self->has_kubeconfig ? ("kubeconfig", $self->kubeconfig) : (), "context", $context)
Truth table66%2/3
A //= B
A= $self->_for_context->{$context}B= ref($self)->new($self->has_kubeconfig ? ("kubeconfig", $self->kubeconfig) : (), "context", $context)
| |||||||||||||||||||||||||||||
| 62 | ( $self->has_kubeconfig ? ( kubeconfig => $self->kubeconfig ) : () ), | ||||||||||||||||||||||||||||
| 63 | context => $context | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 19 | 1; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =pod | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head1 NAME | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | Kubernetes::Comb::Client::Sync - Synchronous Comb client on Kubernetes::REST, returning done Futures | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 VERSION | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | version 0.001 | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | use Kubernetes::Comb::Client::Sync; | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | my $k8s = Kubernetes::Comb::Client::Sync->new; # current context | ||||||||||||||||||||||||||||
| 89 | my $k8s = Kubernetes::Comb::Client::Sync->new(context => 'dev'); | ||||||||||||||||||||||||||||
| 90 | my $k8s = Kubernetes::Comb::Client::Sync->new(rest => $rest); # your own client | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | my $pods = $k8s->list('Pod', namespace => 'platform')->get->items; | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | The default client of a Comb. Every method of L<Kubernetes::Comb::Role::Client> | ||||||||||||||||||||||||||||
| 97 | runs the request right away through L<Kubernetes::REST> and returns an | ||||||||||||||||||||||||||||
| 98 | already-done L<Future> -- or an already-failed one: whatever | ||||||||||||||||||||||||||||
| 99 | L<Kubernetes::REST> croaks with becomes the failure, nothing is thrown. So | ||||||||||||||||||||||||||||
| 100 | C<< ->get >> on a result never waits for an event loop. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head2 kubeconfig | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Path of the kubeconfig to read. Defaults to what L<Kubernetes::REST::Kubeconfig> | ||||||||||||||||||||||||||||
| 105 | finds: C<$KUBECONFIG>, then F<~/.kube/config>, then the in-cluster service | ||||||||||||||||||||||||||||
| 106 | account. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head2 context | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | Kube context to use. Defaults to the kubeconfig's current context. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head2 rest | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | The L<Kubernetes::REST> instance. Built on first use from L</kubeconfig> and | ||||||||||||||||||||||||||||
| 115 | L</context>, with L<Kubernetes::Comb::CRD> registered so the Kind C<Comb> | ||||||||||||||||||||||||||||
| 116 | resolves. A failure building it -- no kubeconfig, an unknown context -- | ||||||||||||||||||||||||||||
| 117 | fails the Future of the request that needed it. Pass your own to control | ||||||||||||||||||||||||||||
| 118 | everything else. | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head2 get | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head2 list | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head2 ensure | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head2 delete | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head2 update | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head2 patch | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head2 update_status | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head2 patch_status | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head2 log | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | The request methods of L<Kubernetes::Comb::Role::Client>, each passing its | ||||||||||||||||||||||||||||
| 139 | arguments to the L<Kubernetes::REST> method of the same name and returning an | ||||||||||||||||||||||||||||
| 140 | already-done or already-failed L<Future>. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head2 server_url | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | The API server URL of L</rest>. | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =head2 for_context | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | my $dev = $k8s->for_context('dev'); | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | The client for another context of the same L</kubeconfig> (the default one | ||||||||||||||||||||||||||||
| 151 | when none was given), made on first use and kept: asking again returns the | ||||||||||||||||||||||||||||
| 152 | same one. Nothing is read until its first request. | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =over | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =item * L<Kubernetes::Comb::Role::Client> | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =item * L<Kubernetes::Comb::Client::Async> | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =back | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head2 Issues | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||||||||
| 169 | L<https://github.com/Getty/p5-kubernetes-comb/issues>. | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head2 IRC | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | Join C<#kubernetes> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>. | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 188 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | =cut | ||||||||||||||||||||||||||||