| 1 | package Kubernetes::Comb::Role::Upstream; | ||
| 2 | # ABSTRACT: What a Comb borrows its service from instead of running it | ||
| 3 | 6 | our $VERSION = '0.001'; | |
| 4 | |||
| 5 | 6 | ▶ | use Moo::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 6 | requires qw( status endpoints ); | |
| 8 | |||
| 9 | |||
| 10 | 6 | 1; | |
| 11 | |||
| 12 | __END__ | ||
| 13 | |||
| 14 | =pod | ||
| 15 | |||
| 16 | =encoding UTF-8 | ||
| 17 | |||
| 18 | =head1 NAME | ||
| 19 | |||
| 20 | Kubernetes::Comb::Role::Upstream - What a Comb borrows its service from instead of running it | ||
| 21 | |||
| 22 | =head1 VERSION | ||
| 23 | |||
| 24 | version 0.001 | ||
| 25 | |||
| 26 | =head1 SYNOPSIS | ||
| 27 | |||
| 28 | package MyApp::Upstream::Catalog; | ||
| 29 | use Moo; | ||
| 30 | with 'Kubernetes::Comb::Role::Upstream'; | ||
| 31 | |||
| 32 | has url => ( is => 'ro', required => 1 ); | ||
| 33 | |||
| 34 | sub status { | ||
| 35 | my ( $self, $comb ) = @_; | ||
| 36 | return Future->done( { reachable => 1, phase => 'Running', via => [ 'vendor' ] } ); | ||
| 37 | } | ||
| 38 | |||
| 39 | sub endpoints { | ||
| 40 | my ( $self, $comb ) = @_; | ||
| 41 | return Future->done( [ | ||
| 42 | Kubernetes::Comb::Endpoint->new( name => 'api', port => 443, cluster => 'catalog.example.com:443' ) | ||
| 43 | ] ); | ||
| 44 | } | ||
| 45 | |||
| 46 | # in a Comb class, or returned by the upstream coderef of the controlling code | ||
| 47 | sub upstream { '+MyApp::Upstream::Catalog' => ( url => 'https://catalog.example.com' ) } | ||
| 48 | |||
| 49 | =head1 DESCRIPTION | ||
| 50 | |||
| 51 | An upstream is where a Comb borrows its service from instead of running it | ||
| 52 | itself. L<Kubernetes::Comb/reconcile> accepts as upstream any object doing | ||
| 53 | this role, and builds one from the short forms (C<< K8s => (...) >>, | ||
| 54 | C<< '+Full::Class' => (...) >>) and from C<spec.upstream> of the custom | ||
| 55 | resource -- the arguments go to C<new>, so an upstream class takes the keys | ||
| 56 | the custom resource names as its constructor arguments. | ||
| 57 | |||
| 58 | The Comb is not a constructor argument: every method gets it as its first | ||
| 59 | argument, so the upstream can take the Comb's namespace, name and client from | ||
| 60 | it. | ||
| 61 | |||
| 62 | =head2 status | ||
| 63 | |||
| 64 | my $seen = $upstream->status($comb)->get; | ||
| 65 | |||
| 66 | Future of a hashref: | ||
| 67 | |||
| 68 | =over | ||
| 69 | |||
| 70 | =item reachable | ||
| 71 | |||
| 72 | Whether the upstream can be used at all. False makes the Comb C<Blocked>, | ||
| 73 | with C<message> as the reason. An upstream reports unreachability this way, | ||
| 74 | not by failing: a failed Future makes the Comb C<Error>. | ||
| 75 | |||
| 76 | =item phase | ||
| 77 | |||
| 78 | The phase the upstream reports for itself; the Comb is C<Running> only while | ||
| 79 | it is C<Running>. | ||
| 80 | |||
| 81 | =item via | ||
| 82 | |||
| 83 | Optional arrayref of the layers the service is borrowed through, nearest | ||
| 84 | first -- for a chain C<[ 'dev', 'prod' ]>. | ||
| 85 | |||
| 86 | =item context | ||
| 87 | |||
| 88 | Optional kube context of the upstream, recorded in C<status.upstream>. | ||
| 89 | |||
| 90 | =item message | ||
| 91 | |||
| 92 | Optional, human-readable: why it is unreachable, or what else there is to | ||
| 93 | know. | ||
| 94 | |||
| 95 | =back | ||
| 96 | |||
| 97 | =head2 endpoints | ||
| 98 | |||
| 99 | my $endpoints = $upstream->endpoints($comb)->get; | ||
| 100 | |||
| 101 | Future of an arrayref of L<Kubernetes::Comb::Endpoint>: what the upstream | ||
| 102 | offers under which name. The upstream decides which address is reachable: | ||
| 103 | C<cluster> is the address to use from inside the Comb's cluster (the one the | ||
| 104 | bridge points at), C<external> the one from outside. Without C<cluster> the | ||
| 105 | Comb uses C<external> from inside too. | ||
| 106 | |||
| 107 | =head2 replicate_into | ||
| 108 | |||
| 109 | $upstream->replicate_into($comb)->get; | ||
| 110 | |||
| 111 | Optional. Called with the Comb on every L<Kubernetes::Comb/reconcile> step | ||
| 112 | that borrows from the upstream, before the bridge is deployed, to replicate | ||
| 113 | data into it. May return a Future; a failure makes the Comb C<Error>. | ||
| 114 | |||
| 115 | =head1 SEE ALSO | ||
| 116 | |||
| 117 | =over | ||
| 118 | |||
| 119 | =item * L<Kubernetes::Comb> | ||
| 120 | |||
| 121 | =item * L<Kubernetes::Comb::Upstream::K8s> | ||
| 122 | |||
| 123 | =item * L<Kubernetes::Comb::Upstream::Static> | ||
| 124 | |||
| 125 | =back | ||
| 126 | |||
| 127 | =head1 SUPPORT | ||
| 128 | |||
| 129 | =head2 Issues | ||
| 130 | |||
| 131 | Please report bugs and feature requests on GitHub at | ||
| 132 | L<https://github.com/Getty/p5-kubernetes-comb/issues>. | ||
| 133 | |||
| 134 | =head2 IRC | ||
| 135 | |||
| 136 | Join C<#kubernetes> on C<irc.perl.org> or message Getty directly. | ||
| 137 | |||
| 138 | =head1 CONTRIBUTING | ||
| 139 | |||
| 140 | Contributions are welcome! Please fork the repository and submit a pull request. | ||
| 141 | |||
| 142 | =head1 AUTHOR | ||
| 143 | |||
| 144 | Torsten Raudssus <getty@cpan.org> | ||
| 145 | |||
| 146 | =head1 COPYRIGHT AND LICENSE | ||
| 147 | |||
| 148 | This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>. | ||
| 149 | |||
| 150 | This is free software; you can redistribute it and/or modify it under | ||
| 151 | the same terms as the Perl 5 programming language system itself. | ||
| 152 | |||
| 153 | =cut | ||