| 1 | package Kubernetes::Comb::Upstream::Static; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: An upstream with fixed endpoints and no cluster behind it | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | with 'Kubernetes::Comb::Role::Upstream'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Future; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Types::Standard qw( ArrayRef Bool InstanceOf Str ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Kubernetes::Comb::Endpoint; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | has _given => ( | ||||||||||||||||||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | init_arg => 'endpoints', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | has _offered => ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | isa => ArrayRef[ InstanceOf['Kubernetes::Comb::Endpoint'] ], | ||||||||||||||||||||||||||||||||||||||||||
| 26 | init_arg => undef | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 51 | ▶ | sub _build__offered { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__offered: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 51 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | return [ map { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 47 | ▶ | blessed $_ && $_->isa('Kubernetes::Comb::Endpoint') ? $_ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition60%3/5
builtin::blessed($_) and $_->isa("Kubernetes::Comb::Endpoint")
ref $_ || 'a plain scalar'
MC/DC50%1/2
builtin::blessed($_) and $_->isa("Kubernetes::Comb::Endpoint")
builtin::blessed($_)
$_->isa("Kubernetes::Comb::Endpoint")
MC/DC0%0/1
ref $_ || 'a plain scalar'
ref $_
Truth table66%2/3
A and B
A= builtin::blessed($_)B= $_->isa("Kubernetes::Comb::Endpoint")
Truth table50%1/2
A
A= ref $_
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | : ref $_ eq 'HASH' ? $self->endpoint_class->new(%$_) | ||||||||||||||||||||||||||||||||||||||||||
| 34 | : croak ref($self).': an endpoint is a hashref or a Kubernetes::Comb::Endpoint, got ' | ||||||||||||||||||||||||||||||||||||||||||
| 35 | .( ref $_ || 'a plain scalar' ); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 51 | } @{ $self->_given } ]; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | has phase => ( is => 'ro', isa => Str, default => 'Running' ); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 18 | ▶ | has via => ( is => 'ro', isa => ArrayRef[Str], default => sub { [] } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | has reachable => ( is => 'ro', isa => Bool, coerce => 1, default => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | has message => ( is => 'ro', isa => Str, predicate => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 51 | ▶ | sub BUILD { $_[0]->_offered } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 45 | ▶ | sub endpoint_class { 'Kubernetes::Comb::Endpoint' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
endpoint_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 44 | ▶ | sub status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 44 | my ( $self, $comb ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | return Future->done( { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | reachable => $self->reachable ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | phase => $self->phase, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 44 | ▶ | via => [ @{ $self->via } ], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | ( $self->has_message ? ( message => $self->message ) : () ) | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 41 | ▶ | sub endpoints { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
endpoints: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 41 | my ( $self, $comb ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 41 | return Future->done( [ @{ $self->_offered } ] ); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | Kubernetes::Comb::Upstream::Static - An upstream with fixed endpoints and no cluster behind it | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | version 0.001 | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # a vendor service, from the controlling code or a class upstream method | ||||||||||||||||||||||||||||||||||||||||||
| 93 | upstream => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | Static => ( | ||||||||||||||||||||||||||||||||||||||||||
| 95 | endpoints => [ { name => 'api', port => 443, cluster => 'geoip.vendor.example:443' } ], | ||||||||||||||||||||||||||||||||||||||||||
| 96 | via => [ 'vendor' ] | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | # the same in the custom resource | ||||||||||||||||||||||||||||||||||||||||||
| 101 | upstream: | ||||||||||||||||||||||||||||||||||||||||||
| 102 | class: Kubernetes::Comb::Upstream::Static | ||||||||||||||||||||||||||||||||||||||||||
| 103 | endpoints: | ||||||||||||||||||||||||||||||||||||||||||
| 104 | - { name: api, port: 443, cluster: geoip.vendor.example:443 } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | via: [ vendor ] | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | An upstream whose endpoints are given, with nothing to ask: a vendor service, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | a process or a Docker container running next to the cluster, or the upper | ||||||||||||||||||||||||||||||||||||||||||
| 111 | layers of a chain in a test. Its L</status> is whatever it was built with. | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | =head2 endpoints | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | Constructor argument: arrayref of what the upstream offers, each a | ||||||||||||||||||||||||||||||||||||||||||
| 116 | L<Kubernetes::Comb::Endpoint> or a hashref of its attributes (C<name>, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | C<port>, C<protocol>, C<cluster>, C<external>). C<cluster> is the address to | ||||||||||||||||||||||||||||||||||||||||||
| 118 | use from inside the Comb's cluster; without it the Comb uses C<external>. | ||||||||||||||||||||||||||||||||||||||||||
| 119 | Default: none. Construction dies on an endpoint that is not one. | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | =head2 phase | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | The phase L</status> reports, default C<Running>. | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | =head2 via | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | Arrayref of the layers L</status> reports, default none. | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | =head2 reachable | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | Whether L</status> reports the upstream reachable, default true. | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | =head2 message | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | Optional message L</status> reports. | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | =head2 endpoint_class | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | The class hashrefs in L</endpoints> become, L<Kubernetes::Comb::Endpoint>. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | =head2 status | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | Future of C<< { reachable, phase, via, message } >> as built. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =head2 endpoints | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | Future of the arrayref of the L</endpoints> as L<Kubernetes::Comb::Endpoint>. | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =item * L<Kubernetes::Comb::Role::Upstream> | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =item * L<Kubernetes::Comb::Upstream::K8s> | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | =head2 Issues | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||||||||||||||||||||||
| 164 | L<https://github.com/Getty/p5-kubernetes-comb/issues>. | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | =head2 IRC | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | Join C<#kubernetes> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>. | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 183 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||||||||||||||||||||||||