« blib/lib/Kubernetes/Comb/CRD/CombUpstreamStatus.pm
↑ Summary
blib/lib/Kubernetes/Comb/Role/Upstream.pm »
| 1 | package Kubernetes::Comb::Role::Client; | ||
| 2 | # ABSTRACT: The Kubernetes client surface a Comb works through | ||
| 3 | 26 | our $VERSION = '0.001'; | |
| 4 | |||
| 5 | 26 | ▶ | use Moo::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 26 | requires qw( | |
| 8 | get list ensure delete update patch update_status patch_status log | ||
| 9 | server_url for_context | ||
| 10 | ); | ||
| 11 | |||
| 12 | |||
| 13 | |||
| 14 | 26 | 1; | |
| 15 | |||
| 16 | __END__ | ||
| 17 | |||
| 18 | =pod | ||
| 19 | |||
| 20 | =encoding UTF-8 | ||
| 21 | |||
| 22 | =head1 NAME | ||
| 23 | |||
| 24 | Kubernetes::Comb::Role::Client - The Kubernetes client surface a Comb works through | ||
| 25 | |||
| 26 | =head1 VERSION | ||
| 27 | |||
| 28 | version 0.001 | ||
| 29 | |||
| 30 | =head1 SYNOPSIS | ||
| 31 | |||
| 32 | package My::Client; | ||
| 33 | use Moo; | ||
| 34 | with 'Kubernetes::Comb::Role::Client'; | ||
| 35 | sub get { ... } # and the rest of the surface | ||
| 36 | |||
| 37 | # what a Comb does with any of them | ||
| 38 | $comb->k8s->list('Pod', namespace => 'platform', labelSelector => 'app=nats') | ||
| 39 | ->then(sub { my ( $list ) = @_; ... }); | ||
| 40 | |||
| 41 | =head1 DESCRIPTION | ||
| 42 | |||
| 43 | The one seam between a Comb and Kubernetes. A Comb never talks to | ||
| 44 | L<Kubernetes::REST> or L<Net::Async::Kubernetes> directly; it calls these | ||
| 45 | methods on its C<k8s> client. L<Kubernetes::Comb::Client::Sync> and | ||
| 46 | L<Kubernetes::Comb::Client::Async> implement them, and so does the fake client | ||
| 47 | of the test suite, which is how that fake stays interchangeable with the real | ||
| 48 | ones. | ||
| 49 | |||
| 50 | The role only names the surface. Every request method returns a L<Future> and | ||
| 51 | never throws: a failure, including bad arguments, is a failed Future. Its | ||
| 52 | failure is the message the underlying client produced, for an API error | ||
| 53 | C<Kubernetes API error (E<lt>whatE<gt>): E<lt>statusE<gt> E<lt>bodyE<gt>>. | ||
| 54 | L</server_url> and L</for_context> are plain methods. | ||
| 55 | |||
| 56 | Resource names are what L<Kubernetes::REST> takes: a short Kind (C<'Pod'>), a | ||
| 57 | qualified C<'group/version/Kind'>, or C<'+Full::Class'> -- the last one needs | ||
| 58 | no resource map, which is how a Comb addresses its own CR class. | ||
| 59 | |||
| 60 | =head2 get | ||
| 61 | |||
| 62 | my $f = $client->get('Deployment', 'nats', namespace => 'platform'); | ||
| 63 | |||
| 64 | Future of the object. | ||
| 65 | |||
| 66 | =head2 list | ||
| 67 | |||
| 68 | my $f = $client->list('Pod', namespace => 'platform', labelSelector => 'app=nats'); | ||
| 69 | |||
| 70 | Future of an L<IO::K8s::List>; the objects are in C<< ->items >>. Without | ||
| 71 | C<namespace> it lists across all namespaces. | ||
| 72 | |||
| 73 | =head2 ensure | ||
| 74 | |||
| 75 | my $f = $client->ensure($object_or_hashref); | ||
| 76 | |||
| 77 | Create or update. Future of the object as stored. C<status> is not written | ||
| 78 | this way -- see L</update_status>. | ||
| 79 | |||
| 80 | Two kinds are not updated once they exist, as C<ensure> of | ||
| 81 | L<Kubernetes::REST> and L<Net::Async::Kubernetes> has it: a C<v1> | ||
| 82 | PersistentVolumeClaim is returned as it is, and so is a C<batch/v1> Job that | ||
| 83 | runs or has succeeded (C<status.active>, C<status.succeeded>); any other | ||
| 84 | existing Job is deleted and created anew. A Comb relies on that: what is | ||
| 85 | left as it is never makes L<Kubernetes::Comb/reconcile> deploy by its | ||
| 86 | digest. | ||
| 87 | |||
| 88 | =head2 delete | ||
| 89 | |||
| 90 | my $f = $client->delete('Service', 'nats', namespace => 'platform'); | ||
| 91 | my $f = $client->delete($object); | ||
| 92 | my $f = $client->delete($job, propagationPolicy => 'Background'); | ||
| 93 | |||
| 94 | Future of C<1>. C<propagationPolicy> (C<Background>, C<Foreground> or | ||
| 95 | C<Orphan>) decides what becomes of the objects the deleted one owns; without | ||
| 96 | it the API server orphans the Pods of a Job. Any other option fails the | ||
| 97 | Future. | ||
| 98 | |||
| 99 | =head2 update | ||
| 100 | |||
| 101 | my $f = $client->update($object); | ||
| 102 | |||
| 103 | Full replacement (PUT) of the main resource. Future of the stored object. | ||
| 104 | |||
| 105 | =head2 patch | ||
| 106 | |||
| 107 | my $f = $client->patch('Deployment', 'nats', | ||
| 108 | namespace => 'platform', | ||
| 109 | patch => { spec => { replicas => 0 } }, | ||
| 110 | type => 'strategic', # or merge, json | ||
| 111 | ); | ||
| 112 | my $f = $client->patch($object, patch => { ... }); | ||
| 113 | |||
| 114 | Future of the patched object. | ||
| 115 | |||
| 116 | =head2 update_status | ||
| 117 | |||
| 118 | my $f = $client->update_status($object); | ||
| 119 | |||
| 120 | Replaces C<status> through the status subresource; needs the current | ||
| 121 | C<resourceVersion>. Future of the stored object. | ||
| 122 | |||
| 123 | =head2 patch_status | ||
| 124 | |||
| 125 | my $f = $client->patch_status($object, patch => { status => { phase => 'Running' } }); | ||
| 126 | |||
| 127 | Merge patch (the default type) through the status subresource, no | ||
| 128 | C<resourceVersion> needed. Future of the stored object. | ||
| 129 | |||
| 130 | =head2 log | ||
| 131 | |||
| 132 | my $f = $client->log('Pod', 'nats-0', | ||
| 133 | namespace => 'platform', | ||
| 134 | container => 'nats', | ||
| 135 | previous => 1, | ||
| 136 | tailLines => 100 | ||
| 137 | ); | ||
| 138 | |||
| 139 | Future of the log text. | ||
| 140 | |||
| 141 | =head2 server_url | ||
| 142 | |||
| 143 | my $url = $client->server_url; | ||
| 144 | |||
| 145 | The API server URL of this client's context. Croaks when the context cannot | ||
| 146 | be resolved. Two clients whose URLs are equal talk to the same cluster. | ||
| 147 | |||
| 148 | =head2 for_context | ||
| 149 | |||
| 150 | my $dev = $client->for_context('dev'); | ||
| 151 | |||
| 152 | A client of the same class for another kube context from the same | ||
| 153 | kubeconfig, made once per context and kept -- | ||
| 154 | L<Kubernetes::Comb::Upstream::K8s> asks for it on every step. Resolving the | ||
| 155 | context is deferred: a missing or broken context fails the first request's | ||
| 156 | Future, and makes L</server_url> croak. | ||
| 157 | |||
| 158 | =head1 SEE ALSO | ||
| 159 | |||
| 160 | =over | ||
| 161 | |||
| 162 | =item * L<Kubernetes::Comb::Client::Sync> | ||
| 163 | |||
| 164 | =item * L<Kubernetes::Comb::Client::Async> | ||
| 165 | |||
| 166 | =back | ||
| 167 | |||
| 168 | =head1 SUPPORT | ||
| 169 | |||
| 170 | =head2 Issues | ||
| 171 | |||
| 172 | Please report bugs and feature requests on GitHub at | ||
| 173 | L<https://github.com/Getty/p5-kubernetes-comb/issues>. | ||
| 174 | |||
| 175 | =head2 IRC | ||
| 176 | |||
| 177 | Join C<#kubernetes> on C<irc.perl.org> or message Getty directly. | ||
| 178 | |||
| 179 | =head1 CONTRIBUTING | ||
| 180 | |||
| 181 | Contributions are welcome! Please fork the repository and submit a pull request. | ||
| 182 | |||
| 183 | =head1 AUTHOR | ||
| 184 | |||
| 185 | Torsten Raudssus <getty@cpan.org> | ||
| 186 | |||
| 187 | =head1 COPYRIGHT AND LICENSE | ||
| 188 | |||
| 189 | This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>. | ||
| 190 | |||
| 191 | This is free software; you can redistribute it and/or modify it under | ||
| 192 | the same terms as the Perl 5 programming language system itself. | ||
| 193 | |||
| 194 | =cut | ||