Kubernetes/Watcher.pm

filter: Statementstmt 99.1% 224 / 226 Branchbran 90.9% 131 / 144 Conditioncond 89.1% 74 / 83 MC/DCmcdc 80.8% 38 / 47 Subroutinesub 100% 41 / 41 Podpod 100% 21 / 21 totaltotal 94.1% 529 / 562 CC 107 SCAR 24.6
CC
107
Cov
95%
_dispatch_event
28.0
configure
20.0
__ANON__
11.0
CRAP 11.7
↑ Summary Kubernetes.pm »
1 package Net::Async::Kubernetes::Watcher;
2 # ABSTRACT: Auto-reconnecting Kubernetes watch as IO::Async::Notifier
3 54 our $VERSION = '0.011';
4 54 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 54 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 54 ▶use parent 'IO::Async::Notifier';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 54 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 54 ▶use Scalar::Util qw(blessed looks_like_number weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 54 ▶use Kubernetes::REST::HTTPResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 122 ▶sub configure {
Subroutine configure: called CC=20 SCAR=30.0
Pod documented
13 122 my ($self, %params) = @_;
14  
15 122 ▶ if (exists $params{kube}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{"kube"}) 104 18 122
16 104 $self->{kube} = delete $params{kube};
17 104 weaken($self->{kube});
18 }
19 # Checked here: anything else (a Controller-style arrayref of delays, a
20 # word) numifies to a delay nobody asked for and the retries go quiet.
21 122 for my $key (qw(reconnect_delay max_reconnect_delay min_watch_duration)) {
22 361 ▶ next unless exists $params{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{$key} 344 17 361
23 17 my $value = delete $params{$key};
24 17 ▶ croak "$key must be a non-negative number of seconds"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value and &looks_like_number($value) and $value >= 0 7 10 17
Condition100%9/9
defined $value and not ref $value and &looks_like_number($value) and $value >= 0
!ll&&!rl&&r
5210
defined $value and not ref $value and &looks_like_number($value)
!ll&&!rl&&r
3212
defined $value and not ref $value
!ll&&!rl&&r
1214
MC/DC100%4/4
defined $value and not ref $value and &looks_like_number($value) and $value >= 0
defined $value not ref $value &looks_like_number($value) $value >= 0
Truth table100%5/5
A and not(B) and C and D
A= defined $valueB= not ref $valueC= &looks_like_number($value)D= $value >= 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
25 unless defined $value && !ref $value && looks_like_number($value) && $value >= 0;
26 10 $self->{$key} = $value;
27 }
28 115 ▶ if (exists $params{reconnect_jitter}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{"reconnect_jitter"}) 36 79 115
29 36 my $value = delete $params{reconnect_jitter};
30 36 ▶ croak "reconnect_jitter must be a number from 0 to 1"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value and &looks_like_number($value) and $value >= 0 and $value <= 1 5 31 36
Condition100%12/12
defined $value and not ref $value and &looks_like_number($value) and $value >= 0 and $value <= 1
!ll&&!rl&&r
4131
defined $value and not ref $value and &looks_like_number($value) and $value >= 0
!ll&&!rl&&r
3132
defined $value and not ref $value and &looks_like_number($value)
!ll&&!rl&&r
2133
defined $value and not ref $value
!ll&&!rl&&r
1134
MC/DC100%5/5
defined $value and not ref $value and &looks_like_number($value) and $value >= 0 and $value <= 1
defined $value not ref $value &looks_like_number($value) $value >= 0 $value <= 1
Truth table100%6/6
A and not(B) and C and D and E
A= defined $valueB= not ref $valueC= &looks_like_number($value)D= $value >= 0E= $value <= 1
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
31 unless defined $value && !ref $value && looks_like_number($value)
32 && $value >= 0 && $value <= 1;
33 31 $self->{reconnect_jitter} = $value;
34 }
35 110 ▶ if (exists $params{max_retries}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{"max_retries"}) 6 104 110
36 6 my $value = delete $params{max_retries};
37 6 ▶ croak "max_retries must be a non-negative integer, or undef for no limit"
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and ref $value || !($value =~ /\A[0-9]+\z/) 2 4 6
Condition66%4/6
defined $value and ref $value || !($value =~ /\A[0-9]+\z/)
!ll&&!rl&&r
042
ref $value or not $value =~ /\A[0-9]+\z/
l!l&&r!l&&!r
024
MC/DC33%1/3
defined $value and ref $value || !($value =~ /\A[0-9]+\z/)
defined $value ref $value not $value =~ /\A[0-9]+\z/
Truth table50%2/4
A and B or not(C)
A= defined $valueB= ref $valueC= not $value =~ /\A[0-9]+\z/
ABCresult
0XX0
1000
11X1
1011
38 if defined $value && (ref $value || $value !~ /\A[0-9]+\z/);
39 4 $self->{max_retries} = $value;
40 }
41 108 for my $key (qw(resource namespace timeout label_selector field_selector
42 names event_types
43 on_added on_modified on_deleted on_error on_event)) {
44 1296 ▶ if (exists $params{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{$key}) 416 880 1296
45 416 $self->{$key} = delete $params{$key};
46 }
47 }
48  
49 108 $self->SUPER::configure(%params);
50 }
51  
52  
53 # Accessors
54 948 ▶sub kube { $_[0]->{kube} }
Subroutine kube: called CC=1 SCAR=0.0
Pod documented
55  
56  
57 580 ▶sub resource { $_[0]->{resource} }
Subroutine resource: called CC=1 SCAR=0.0
Pod documented
58  
59  
60 365 ▶sub namespace { $_[0]->{namespace} }
Subroutine namespace: called CC=1 SCAR=0.0
Pod documented
61  
62  
63 186 ▶sub timeout { $_[0]->{timeout} // 300 }
Subroutine timeout: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[0]{"timeout"} // 300
l!l
3183
MC/DC100%1/1
$_[0]{"timeout"} // 300
$_[0]{"timeout"}
Truth table100%2/2
A
A= $_[0]{"timeout"}
Aresult
11
00
64  
65  
66 92 ▶sub reconnect_delay { $_[0]->{reconnect_delay} // 1 }
Subroutine reconnect_delay: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[0]{"reconnect_delay"} // 1
l!l
785
MC/DC100%1/1
$_[0]{"reconnect_delay"} // 1
$_[0]{"reconnect_delay"}
Truth table100%2/2
A
A= $_[0]{"reconnect_delay"}
Aresult
11
00
67  
68  
69 118 ▶sub max_reconnect_delay { $_[0]->{max_reconnect_delay} // 30 }
Subroutine max_reconnect_delay: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[0]{"max_reconnect_delay"} // 30
l!l
8110
MC/DC100%1/1
$_[0]{"max_reconnect_delay"} // 30
$_[0]{"max_reconnect_delay"}
Truth table100%2/2
A
A= $_[0]{"max_reconnect_delay"}
Aresult
11
00
70  
71  
72 93 ▶sub reconnect_jitter { $_[0]->{reconnect_jitter} // 0.2 }
Subroutine reconnect_jitter: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[0]{"reconnect_jitter"} // "0.2"
l!l
858
MC/DC100%1/1
$_[0]{"reconnect_jitter"} // "0.2"
$_[0]{"reconnect_jitter"}
Truth table100%2/2
A
A= $_[0]{"reconnect_jitter"}
Aresult
11
00
73  
74  
75 95 ▶sub max_retries { $_[0]->{max_retries} }
Subroutine max_retries: called CC=1 SCAR=0.0
Pod documented
76  
77  
78 17 ▶sub min_watch_duration { $_[0]->{min_watch_duration} // 1 }
Subroutine min_watch_duration: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[0]{"min_watch_duration"} // 1
l!l
710
MC/DC100%1/1
$_[0]{"min_watch_duration"} // 1
$_[0]{"min_watch_duration"}
Truth table100%2/2
A
A= $_[0]{"min_watch_duration"}
Aresult
11
00
79  
80  
81 187 ▶sub label_selector { $_[0]->{label_selector} }
Subroutine label_selector: called CC=1 SCAR=0.0
Pod documented
82  
83  
84 187 ▶sub field_selector { $_[0]->{field_selector} }
Subroutine field_selector: called CC=1 SCAR=0.0
Pod documented
85  
86  
87 129 ▶sub names { $_[0]->{names} }
Subroutine names: called CC=1 SCAR=0.0
Pod documented
88  
89  
90 147 ▶sub event_types { $_[0]->{event_types} }
Subroutine event_types: called CC=1 SCAR=0.0
Pod documented
91  
92  
93 324 ▶sub on_added { $_[0]->{on_added} }
Subroutine on_added: called CC=1 SCAR=0.0
Pod documented
94  
95  
96 115 ▶sub on_modified { $_[0]->{on_modified} }
Subroutine on_modified: called CC=1 SCAR=0.0
Pod documented
97  
98  
99 115 ▶sub on_deleted { $_[0]->{on_deleted} }
Subroutine on_deleted: called CC=1 SCAR=0.0
Pod documented
100  
101  
102 220 ▶sub on_error { $_[0]->{on_error} }
Subroutine on_error: called CC=1 SCAR=0.0
Pod documented
103  
104  
105 272 ▶sub on_event { $_[0]->{on_event} }
Subroutine on_event: called CC=1 SCAR=0.0
Pod documented
106  
107  
108 104 ▶sub _add_to_loop {
Subroutine _add_to_loop: called CC=3 SCAR=11.0
109 104 my ($self, $loop) = @_;
110 104 ▶ croak "kube is required" unless $self->{kube};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"kube"} 1 103 104
111 103 ▶ croak "resource is required" unless $self->{resource};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"resource"} 1 102 103
112 102 $self->start;
113 }
114  
115 24 ▶sub _remove_from_loop {
Subroutine _remove_from_loop: called CC=1 SCAR=0.0
116 24 my ($self, $loop) = @_;
117 24 $self->stop;
118 }
119  
120 104 ▶sub start {
Subroutine start: called CC=3 SCAR=11.0
Pod documented
121 104 my ($self) = @_;
122 # Waiting out a reconnect delay is running too: starting now as well
123 # would leave two watches once the pending reconnect fires.
124 104 ▶ return if $self->{_watching} || $self->{_retry_future};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_watching"} or $self->{"_retry_future"} 1 103 104
Condition66%2/3
$self->{"_watching"} or $self->{"_retry_future"}
l!l&&r!l&&!r
01103
MC/DC50%1/2
$self->{"_watching"} or $self->{"_retry_future"}
$self->{"_watching"} $self->{"_retry_future"}
Truth table66%2/3
A or B
A= $self->{"_watching"}B= $self->{"_retry_future"}
ABresult
1X1
011
000
125 103 $self->{_stopped} = 0;
126 103 $self->{_failures} = 0;
127 103 $self->_start_watch;
128 }
129  
130  
131 127 ▶sub stop {
Subroutine stop: called CC=5 SCAR=16.1
Pod documented
132 127 my ($self) = @_;
133 127 $self->{_stopped} = 1;
134 127 $self->{_watching} = 0;
135 127 ▶ if (my $retry = delete $self->{_retry_future}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $retry = delete $self->{"_retry_future"}) 25 102 127
136 25 $retry->cancel;
137 }
138 127 ▶ if (my $f = delete $self->{_watch_future}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = delete $self->{"_watch_future"}) 88 39 127
139 88 ▶ return if $f->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_ready 28 60 88
140 # Defer cancel to next loop iteration to avoid closing the HTTP
141 # connection from within its own on_read handler, which triggers
142 # Net::Async::HTTP's "Spurious on_read of connection while idle".
143 60 ▶ if (my $loop = $self->loop) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $loop = $self->loop) { } 60 0 60
144 50 ▶ $loop->later(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
145 50 ▶ $f->cancel if !$f->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if not $f->is_ready 39 11 50
146 60 });
147 } else {
148 0 $f->cancel;
149 }
150 }
151 }
152  
153  
154 197 ▶sub _start_watch {
Subroutine _start_watch: called CC=9 SCAR=22.0
155 197 my ($self) = @_;
156 197 ▶ return if $self->{_stopped};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_stopped"} 0 197 197
157 197 ▶ return unless $self->{kube};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"kube"} 0 197 197
158  
159 197 $self->{_watching} = 1;
160 197 $self->{_buffer} = '';
161  
162 197 my $rest = $self->kube->_rest;
163 197 my ($class, $error) = $self->kube->_resolve_class($self->resource);
164 197 ▶ croak $error unless defined $class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class 11 186 197
165 186 ▶ (my $path, $error) = $self->kube->_request_path($class, $self->resource,
Branch: 1 branch
BranchTrueFalseTotal
$self->namespace ? : 177 9 186
166 ($self->namespace ? (namespace => $self->namespace) : ()),
167 );
168 186 ▶ croak $error unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 2 184 186
169  
170 184 my %params = (
171 watch => 'true',
172 timeoutSeconds => $self->timeout,
173 # Without it the only resourceVersion a quiet watch ever holds is
174 # that of the last initial ADDED event, older than the state the
175 # server started the watch from, and the reconnect replays history
176 # from there (k73). With it the server sends BOOKMARK events (one
177 # after the initial events, then periodically) carrying the current
178 # one.
179 allowWatchBookmarks => 'true',
180 );
181 $params{resourceVersion} = $self->{_resource_version}
182 184 ▶ if defined $self->{_resource_version};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_resource_version"} 20 164 184
183 184 ▶ $params{labelSelector} = $self->label_selector
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->label_selector 2 182 184
184 if defined $self->label_selector;
185 184 ▶ $params{fieldSelector} = $self->field_selector
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->field_selector 2 182 184
186 if defined $self->field_selector;
187  
188 184 my $req = $rest->prepare_request('GET', $path, parameters => \%params);
189 # The resolved class, handed over exactly (see the client's _exact_class).
190 184 my $exact_class = $self->kube->_exact_class($class);
191  
192 # What tells a watch cycle that ran its course from a failed attempt
193 # when this stream ends: when it started, whether any event came, and
194 # the ERROR event it would end on.
195 184 $self->{_stream_started} = $self->_now;
196 184 $self->{_stream_events} = 0;
197 184 $self->{_stream_error} = undef;
198  
199 184 weaken(my $weak_self = $self);
200  
201 164 ▶ my $f = $self->kube->_do_streaming_request($req, sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
202 164 my ($chunk) = @_;
203 164 ▶ return unless $weak_self;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self 8 156 164
204  
205 156 my $buffer = $weak_self->{_buffer};
206 156 for my $result ($rest->process_watch_chunk($exact_class, \$buffer, $chunk)) {
207 156 $weak_self->{_buffer} = $buffer;
208  
209 156 ▶ if ($result->{resourceVersion}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{"resourceVersion"}) 140 16 156
210 140 $weak_self->{_resource_version} = $result->{resourceVersion};
211 }
212  
213 156 my $event = $result->{event};
214 156 $weak_self->{_stream_events}++;
215  
216 # A BOOKMARK only carries the resourceVersion (taken above). It
217 # is an event for the attempt (a stream that got one ran its
218 # course) but not one for the consumer: not dispatched, to
219 # on_event neither, and no name filter or event_types decides.
220 156 ▶ if ($event->type eq 'BOOKMARK') {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->type eq "BOOKMARK") 6 150 156
221 6 $weak_self->{_failures} = 0;
222 6 $weak_self->{_stream_error} = undef;
223 6 next;
224 }
225  
226 150 ▶ if ($result->{is_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{'is_error'}) { } 14 136 150
227 14 ▶ if ($result->{error_code} == 410) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{"error_code"} == 410) 3 11 14
228 3 $weak_self->{_resource_version} = undef;
229 3 $weak_self->{_stream_error} = undef;
230 3 return;
231 }
232 # Not reset by an ERROR event: a server that sends one and
233 # closes, again and again, must meet a growing backoff.
234 11 $weak_self->{_stream_error} = $event->object;
235 } else {
236 # An event: this attempt got through, so a failure after it
237 # starts the backoff over.
238 136 $weak_self->{_failures} = 0;
239 136 $weak_self->{_stream_error} = undef;
240 }
241  
242 147 $weak_self->_dispatch_event($event);
243 }
244 153 $weak_self->{_buffer} = $buffer;
245 184 });
246  
247 56 ▶ $f->on_done(sub {
Subroutine __ANON__: called CC=11 SCAR=24.0
248 56 my ($response) = @_;
249 56 ▶ return unless $weak_self;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self 3 53 56
250 53 ▶ return if $weak_self->{_stopped};
Branch: 1 branch
BranchTrueFalseTotal
if $weak_self->{"_stopped"} 6 47 53
251 47 $weak_self->{_watching} = 0;
252 # A rejected request (401, 403, 5xx) resolves like any response. It
253 # is a failed attempt, not a watch cycle that ran its course.
254 47 ▶ if ($response->status >= 400) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->status >= 400) 9 38 47
255 # 410 Gone on the request itself (aggregated API servers,
256 # proxies) is the same expired resourceVersion as the ERROR
257 # event: forget it and start over at once, silently (k78). Only
258 # when there was a version to forget: a 410 to a request without
259 # one is a failed attempt like any other and meets the backoff
260 # instead of a tight loop. The failure count is kept - this
261 # restart is no success.
262 9 ▶ if ($response->status == 410 && defined $weak_self->{_resource_version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->status == 410 and defined $weak_self->{"_resource_version"}) 2 7 9
Condition100%3/3
$response->status == 410 and defined $weak_self->{"_resource_version"}
!ll&&!rl&&r
612
MC/DC100%2/2
$response->status == 410 and defined $weak_self->{"_resource_version"}
$response->status == 410 defined $weak_self->{"_resource_version"}
Truth table100%3/3
A and B
A= $response->status == 410B= defined $weak_self->{"_resource_version"}
ABresult
0X0
100
111
263 2 $weak_self->{_resource_version} = undef;
264 2 return $weak_self->_start_watch;
265 }
266 7 ▶ my $cause = eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $rest->check_response($response, 'watch ' . $weak_self->resource); 1 } } ? : 0 7 7
267 7 $rest->check_response($response, 'watch ' . $weak_self->resource);
268 0 1;
269 } ? 'HTTP ' . $response->status : $@;
270 7 return $weak_self->_watch_failed($cause, $response->status);
271 }
272 # So is a stream that ends on an ERROR event (other than 410 Gone,
273 # which lets the reconnect start over), or at once without any.
274 # Reconnecting at once would be a tight loop against the API server.
275 38 ▶ if (my $error = $weak_self->{_stream_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $weak_self->{"_stream_error"}) 3 35 38
276 return $weak_self->_watch_failed($weak_self->_error_event_cause($error),
277 3 ▶ ref $error eq 'HASH' ? $error->{code} : undef);
Branch: 1 branch
BranchTrueFalseTotal
ref $error eq 'HASH' ? : 3 0 3
278 }
279 35 my $elapsed = $weak_self->_now - $weak_self->{_stream_started};
280 35 ▶ if (!$weak_self->{_stream_events} && $elapsed < $weak_self->min_watch_duration) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $weak_self->{"_stream_events"} and $elapsed < $weak_self->min_watch_duration) 9 26 35
Condition100%3/3
not $weak_self->{"_stream_events"} and $elapsed < $weak_self->min_watch_duration
!ll&&!rl&&r
2069
MC/DC100%2/2
not $weak_self->{"_stream_events"} and $elapsed < $weak_self->min_watch_duration
not $weak_self->{"_stream_events"} $elapsed < $weak_self->min_watch_duration
Truth table100%3/3
not(A) and B
A= not $weak_self->{"_stream_events"}B= $elapsed < $weak_self->min_watch_duration
ABresult
0X0
100
111
281 9 return $weak_self->_watch_failed(
282 sprintf('stream closed after %.1fs without an event', $elapsed));
283 }
284 26 $weak_self->{_failures} = 0;
285 26 $weak_self->_start_watch;
286 184 });
287  
288 77 ▶ $f->on_fail(sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
289 77 my ($error) = @_;
290 77 ▶ return unless $weak_self;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self 0 77 77
291 77 ▶ return if $weak_self->{_stopped};
Branch: 1 branch
BranchTrueFalseTotal
if $weak_self->{"_stopped"} 2 75 77
292 75 $weak_self->{_watching} = 0;
293 75 $weak_self->_watch_failed($error);
294 184 });
295  
296 184 $self->{_watch_future} = $f;
297 }
298  
299 # The clock min_watch_duration is measured with: the loop's, which its
300 # timers use too. Tests replace it.
301 168 ▶sub _now { $_[0]->loop->time }
Subroutine _now: called CC=1 SCAR=0.0
302  
303 # The random share of reconnect_jitter a delay is shortened by, from 0 up to
304 # (not including) 1. Tests replace it.
305 27 ▶sub _random_fraction { rand() }
Subroutine _random_fraction: called CC=1 SCAR=0.0
306  
307 # The cause of a failure for a stream that ended on the ERROR event $error,
308 # the raw Status hashref: its code, reason and message.
309 3 ▶sub _error_event_cause {
Subroutine _error_event_cause: called CC=5 SCAR=17.8
310 3 my ($self, $error) = @_;
311 3 ▶ return 'stream closed after an ERROR event' unless ref $error eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $error eq "HASH" 0 3 3
312 3 ▶ my $what = join ' ', grep { defined && length } @{$error}{qw(code reason)};
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
006
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
313 return 'stream closed after an ERROR event'
314 . (length $what ? " ($what)" : '')
315 3 ▶ . (defined $error->{message} ? ': ' . $error->{message} : '');
Branch: 2 branches
BranchTrueFalseTotal
length $what ? : 3 0 3
defined $error->{'message'} ? : 3 0 3
316 }
317  
318 # The cause of a failed watch attempt as its report words it, for humans: a
319 # Kubernetes::REST::APIError as "HTTP <code> <reason>: <message>" from its
320 # accessors (the body when it holds no Status), anything else as its text
321 # without the Perl location a croak or die ends in.
322 94 ▶sub _cause_text {
Subroutine _cause_text: called CC=7 SCAR=19.6
323 94 my ($self, $cause) = @_;
324 94 ▶ return 'unknown error' unless defined $cause;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cause 0 94 94
325 94 ▶ if (blessed $cause && $cause->isa('Kubernetes::REST::APIError')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($cause) and $cause->isa("Kubernetes::REST::APIError")) 7 87 94
Condition66%2/3
builtin::blessed($cause) and $cause->isa("Kubernetes::REST::APIError")
!ll&&!rl&&r
8707
MC/DC50%1/2
builtin::blessed($cause) and $cause->isa("Kubernetes::REST::APIError")
builtin::blessed($cause) $cause->isa("Kubernetes::REST::APIError")
Truth table66%2/3
A and B
A= builtin::blessed($cause)B= $cause->isa("Kubernetes::REST::APIError")
ABresult
0X0
100
111
326 7 ▶ my $text = join ' ', 'HTTP', $cause->code, grep { defined && length } $cause->reason;
Condition66%2/3
defined $_ && length $_
!ll&&!rl&&r
502
MC/DC50%1/2
defined $_ && length $_
defined $_ length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
327 7 ▶ my $detail = $cause->message // $cause->body;
Condition100%3/3
$cause->message // $cause->body
l!l&&r!l&&!r
511
MC/DC100%2/2
$cause->message // $cause->body
$cause->message $cause->body
Truth table100%3/3
A // B
A= $cause->messageB= $cause->body
ABresult
1X1
011
000
328 7 $detail =~ s/\s+\z//;
329 7 ▶ return length $detail ? $text . ': ' . $detail : $text;
Branch: 1 branch
BranchTrueFalseTotal
length $detail ? : 6 1 7
330 }
331 87 my $text = "$cause";
332 87 $text =~ s/\s+\z//;
333 87 $text =~ s/ at \S+ line \d+\.\z//;
334 87 return $text;
335 }
336  
337 # A failed watch attempt: a request that failed outright, was rejected with
338 # HTTP status $code, or opened a stream that ended badly ($code then the
339 # ERROR event's, if any). Schedules the next attempt with exponential
340 # backoff - or, once max_retries consecutive failures have been retried,
341 # stops the watcher - and reports the failure either way: to on_error, else
342 # as a warning.
343 94 ▶sub _watch_failed {
Subroutine _watch_failed: called CC=10 SCAR=23.0
344 94 my ($self, $cause, $code) = @_;
345 94 my $failures = ++$self->{_failures};
346 94 my $max_retries = $self->max_retries;
347 94 $cause = $self->_cause_text($cause);
348  
349 94 my ($delay, $next);
350 94 ▶ if (defined $max_retries && $failures > $max_retries) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max_retries and $failures > $max_retries) { } 3 91 94
Condition100%3/3
defined $max_retries and $failures > $max_retries
!ll&&!rl&&r
8653
MC/DC100%2/2
defined $max_retries and $failures > $max_retries
defined $max_retries $failures > $max_retries
Truth table100%3/3
A and B
A= defined $max_retriesB= $failures > $max_retries
ABresult
0X0
100
111
351 # Stopped before the report, so an on_error that restarts the watcher
352 # is not undone right after.
353 3 $self->stop;
354 3 ▶ $next = sprintf('giving up after %d %s',
Branch: 1 branch
BranchTrueFalseTotal
$max_retries == 1 ? : 1 2 3
355 $max_retries, $max_retries == 1 ? 'retry' : 'retries');
356 } else {
357 # The exponent is bounded so a long outage cannot overflow it to inf,
358 # which reconnect_delay => 0 would turn into a NaN delay.
359 91 my $exponent = $failures - 1;
360 91 ▶ $exponent = 64 if $exponent > 64;
Branch: 1 branch
BranchTrueFalseTotal
if $exponent > 64 0 91 91
361 91 $delay = $self->reconnect_delay * 2 ** $exponent;
362 91 ▶ $delay = $self->max_reconnect_delay if $delay > $self->max_reconnect_delay;
Branch: 1 branch
BranchTrueFalseTotal
if $delay > $self->max_reconnect_delay 26 65 91
363 # Shortened, never lengthened, so both delays stay upper bounds.
364 91 ▶ if (my $jitter = $self->reconnect_jitter) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $jitter = $self->reconnect_jitter) 48 43 91
365 48 $delay -= $delay * $jitter * $self->_random_fraction;
366 48 $delay = int($delay * 1000 + 0.5) / 1000;
367 }
368  
369 # Scheduled before the report, so an on_error that stops the watcher
370 # cancels it.
371 91 weaken(my $weak_self = $self);
372 66 ▶ $self->{_retry_future} = $self->loop->delay_future(after => $delay)->on_done(sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
373 66 ▶ return unless $weak_self;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self 0 66 66
374 66 delete $weak_self->{_retry_future};
375 66 $weak_self->_start_watch;
376 91 });
377 91 $next = 'retrying in ' . $delay . 's';
378 }
379  
380 94 ▶ my $status = {
Branch: 1 branch
BranchTrueFalseTotal
defined $delay ? : 91 3 94
Condition100%2/2
$code // 0
l!l
1084
MC/DC100%1/1
$code // 0
$code
Truth table100%2/2
A
A= $code
Aresult
11
00
381 kind => 'Status',
382 apiVersion => 'v1',
383 status => 'Failure',
384 reason => 'WatchFailed',
385 code => $code // 0,
386 message => 'watch ' . $self->resource . ' failed, ' . $next . ': ' . $cause,
387 details => {
388 kind => $self->resource,
389 (defined $delay ? (retryAfterSeconds => $delay) : ()),
390 },
391 };
392  
393 94 ▶ if (my $cb = $self->on_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $self->on_error) { } 88 6 94
394 88 $cb->($status);
395 } else {
396 6 warn $status->{message} . "\n";
397 }
398 }
399  
400 147 ▶sub _dispatch_event {
Subroutine _dispatch_event: called CC=28 SCAR=33.3
401 147 my ($self, $event) = @_;
402 147 my $type = $event->type;
403  
404 # Client-side event type filter
405 # Explicit event_types wins; otherwise auto-derive from callbacks
406 # (on_event is catch-all, so if set, all types pass)
407 147 ▶ if (my $types = $self->event_types) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $types = $self->event_types) { } 12 135 147
elsif (not $self->on_event) { } 104 31 135
408 12 my %allowed = map { uc($_) => 1 } @$types;
409 12 ▶ return unless $allowed{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless $allowed{$type} 4 8 12
410 } elsif (!$self->on_event) {
411 104 my %has;
412 104 ▶ $has{ADDED} = 1 if $self->on_added;
Branch: 1 branch
BranchTrueFalseTotal
if $self->on_added 104 0 104
413 104 ▶ $has{MODIFIED} = 1 if $self->on_modified;
Branch: 1 branch
BranchTrueFalseTotal
if $self->on_modified 66 38 104
414 104 ▶ $has{DELETED} = 1 if $self->on_deleted;
Branch: 1 branch
BranchTrueFalseTotal
if $self->on_deleted 69 35 104
415 104 ▶ $has{ERROR} = 1 if $self->on_error;
Branch: 1 branch
BranchTrueFalseTotal
if $self->on_error 25 79 104
416 104 ▶ return unless !%has || $has{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless not %has or $has{$type} 3 101 104
Condition66%2/3
not %has or $has{$type}
l!l&&r!l&&!r
01013
MC/DC50%1/2
not %has or $has{$type}
not %has $has{$type}
Truth table66%2/3
not(A) or B
A= not %hasB= $has{$type}
ABresult
1X1
011
000
417 }
418  
419 # Client-side name filter (skip for ERROR events which have no metadata)
420 140 ▶ if ($type ne 'ERROR' && (my $names = $self->names)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "ERROR" and my $names = $self->names) 11 129 140
Condition100%3/3
$type ne "ERROR" and my $names = $self->names
!ll&&!rl&&r
1111811
MC/DC100%2/2
$type ne "ERROR" and my $names = $self->names
$type ne "ERROR" my $names = $self->names
Truth table100%3/3
A and B
A= $type ne "ERROR"B= my $names = $self->names
ABresult
0X0
100
111
421 11 ▶ my $obj_name = eval { $event->object->metadata->name } // '';
Condition50%1/2
eval { // ""
l!l
110
MC/DC0%0/1
eval { do { $event->object->metadata->name } } // ""
eval { do { $event->object->metadata->name } }
Truth table50%1/2
A
A= eval { do { $event->object->metadata->name } }
Aresult
11
00
422 11 ▶ my @patterns = ref $names eq 'ARRAY' ? @$names : ($names);
Branch: 1 branch
BranchTrueFalseTotal
ref $names eq 'ARRAY' ? : 3 8 11
423 11 my $matched = 0;
424 11 for my $pat (@patterns) {
425 13 ▶ if (ref $pat eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pat eq 'Regexp') { } 11 2 13
426 11 ▶ $matched = 1, last if $obj_name =~ $pat;
Branch: 1 branch
BranchTrueFalseTotal
if $obj_name =~ /$pat/ 6 5 11
427 } else {
428 2 ▶ $matched = 1, last if $obj_name eq $pat;
Branch: 1 branch
BranchTrueFalseTotal
if $obj_name eq $pat 1 1 2
429 }
430 }
431 11 ▶ return unless $matched;
Branch: 1 branch
BranchTrueFalseTotal
unless $matched 4 7 11
432 }
433  
434 136 ▶ if (my $cb = $self->on_event) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $self->on_event) 37 99 136
435 37 $cb->($event);
436 }
437  
438 136 ▶ if ($type eq 'ADDED' && $self->on_added) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'ADDED' and $self->on_added) { } 105 31 136
elsif ($type eq 'MODIFIED' and $self->on_modified) { } 4 27 31
elsif ($type eq 'DELETED' and $self->on_deleted) { } 4 23 27
elsif ($type eq 'ERROR' and $self->on_error) { } 10 25 35
Condition100%3/3
$type eq "ADDED" and $self->on_added
!ll&&!rl&&r
229105
MC/DC100%2/2
$type eq "ADDED" and $self->on_added
$type eq "ADDED" $self->on_added
Truth table100%3/3
A and B
A= $type eq "ADDED"B= $self->on_added
ABresult
0X0
100
111
439 105 $self->on_added->($event->object);
440 ▶ } elsif ($type eq 'MODIFIED' && $self->on_modified) {
Condition100%3/3
$type eq "MODIFIED" and $self->on_modified
!ll&&!rl&&r
2614
MC/DC100%2/2
$type eq "MODIFIED" and $self->on_modified
$type eq "MODIFIED" $self->on_modified
Truth table100%3/3
A and B
A= $type eq "MODIFIED"B= $self->on_modified
ABresult
0X0
100
111
441 4 $self->on_modified->($event->object);
442 ▶ } elsif ($type eq 'DELETED' && $self->on_deleted) {
Condition100%3/3
$type eq "DELETED" and $self->on_deleted
!ll&&!rl&&r
2124
MC/DC100%2/2
$type eq "DELETED" and $self->on_deleted
$type eq "DELETED" $self->on_deleted
Truth table100%3/3
A and B
A= $type eq "DELETED"B= $self->on_deleted
ABresult
0X0
100
111
443 4 $self->on_deleted->($event->object);
444 ▶ } elsif ($type eq 'ERROR' && $self->on_error) {
Condition100%3/3
$type eq "ERROR" and $self->on_error
!ll&&!rl&&r
12110
MC/DC100%2/2
$type eq "ERROR" and $self->on_error
$type eq "ERROR" $self->on_error
Truth table100%3/3
A and B
A= $type eq "ERROR"B= $self->on_error
ABresult
0X0
100
111
445 10 $self->on_error->($event->object);
446 }
447 }
448  
449 54 1;
450  
451 __END__
452  
453 =pod
454  
455 =encoding UTF-8
456  
457 =head1 NAME
458  
459 Net::Async::Kubernetes::Watcher - Auto-reconnecting Kubernetes watch as IO::Async::Notifier
460  
461 =head1 VERSION
462  
463 version 0.011
464  
465 =head1 SYNOPSIS
466  
467 my $watcher = $kube->watcher('Pod',
468 namespace => 'default',
469 label_selector => 'app=web',
470 on_added => sub { my ($pod) = @_; say "Added: " . $pod->metadata->name },
471 on_modified => sub { my ($pod) = @_; say "Modified: " . $pod->metadata->name },
472 on_deleted => sub { my ($pod) = @_; say "Deleted: " . $pod->metadata->name },
473 on_error => sub { my ($status) = @_; warn "Error: $status->{message}" },
474 );
475  
476 # Client-side filtering by name and event type
477 $kube->watcher('Pod',
478 namespace => 'default',
479 names => [qr/^nginx/, qr/^redis/], # only matching names
480 event_types => ['ADDED', 'DELETED'], # skip MODIFIED
481 on_added => sub { ... },
482 on_deleted => sub { ... },
483 );
484  
485 # Watch multiple resources concurrently
486 $kube->watcher('Deployment', namespace => 'production', on_modified => sub { ... });
487 $kube->watcher('Service', namespace => 'production', on_added => sub { ... });
488  
489 # Stop watching
490 $watcher->stop;
491  
492 # Restart
493 $watcher->start;
494  
495 =head1 DESCRIPTION
496  
497 An L<IO::Async::Notifier> that watches a Kubernetes resource for changes.
498 Created via L<Net::Async::Kubernetes/watcher>.
499  
500 The watcher automatically:
501  
502 =over 4
503  
504 =item * Reconnects when the server-side timeout expires
505  
506 =item * Resumes from the last C<resourceVersion> to avoid missing events. It
507 asks the server for C<BOOKMARK> events (C<allowWatchBookmarks>) and takes only
508 their C<resourceVersion>: they are never passed to a callback, C<on_event>
509 included. That keeps a reconnect of a quiet watch started without a
510 C<resourceVersion> from resuming at the version of the last initial C<ADDED>
511 event, which would replay history. A server that sends no bookmark after the
512 initial events (older ones) still leaves that window open.
513  
514 =item * Handles 410 Gone, as an C<ERROR> event on the stream or as the HTTP
515 status of the watch request, by clearing the C<resourceVersion> and restarting
516 at once. A request answered 410 although it carried no C<resourceVersion> is
517 a failed attempt like any other, with backoff.
518  
519 =item * Retries a failed watch attempt -- a transport error, a rejection
520 such as C<401> or C<403>, or a stream that closes at once without an event
521 or right after an C<ERROR> event -- with an exponential backoff (1s, 2s, 4s,
522 ... up to 30s by default, see L</reconnect_delay>, each shortened at random
523 by up to a fifth, see L</reconnect_jitter>), reports every such
524 failure to L</on_error> or as a warning, and gives up after L</max_retries>
525 consecutive failures when a limit is set
526  
527 =item * Filters events client-side by name patterns (C<names>) and event types (C<event_types>)
528  
529 =back
530  
531 =head2 configure
532  
533 Internal L<IO::Async::Notifier> configuration method. Handles initialization
534 of C<kube>, C<resource>, C<namespace>, C<timeout>, C<label_selector>,
535 C<field_selector>, C<names>, C<event_types>, C<reconnect_delay>,
536 C<max_reconnect_delay>, C<reconnect_jitter>, C<max_retries>,
537 C<min_watch_duration>, and all event callbacks (C<on_added>, C<on_modified>,
538 C<on_deleted>, C<on_error>, C<on_event>). Croaks on a C<reconnect_delay>,
539 C<max_reconnect_delay> or C<min_watch_duration> that is not a non-negative
540 number, on a C<reconnect_jitter> that is not a number from 0 to 1, and on a
541 C<max_retries> that is neither a non-negative integer nor C<undef>.
542  
543 =head2 kube
544  
545 Returns the parent L<Net::Async::Kubernetes> instance.
546  
547 =head2 resource
548  
549 Required. The Kubernetes resource kind to watch (e.g., C<'Pod'>,
550 C<'Deployment'>), or a qualified C<'group/version/Kind'> name to watch a
551 specific API version -- see L<Net::Async::Kubernetes/expand_class>.
552  
553 =head2 namespace
554  
555 Optional. Namespace to watch. Omit for cluster-scoped resources or to
556 watch all namespaces.
557  
558 =head2 timeout
559  
560 Server-side timeout per watch cycle in seconds. Default: 300.
561  
562 =head2 reconnect_delay
563  
564 Seconds to wait before reconnecting after a failed watch attempt (see
565 L</on_error> for what counts as one). Default: 1. Each further consecutive
566 failure doubles the delay, up to L</max_reconnect_delay>, and every delay is
567 shortened at random by up to L</reconnect_jitter>. A reconnect that
568 gets through -- an event arrives on the stream (an C<ERROR> event does not
569 count), or the watch cycle ends cleanly -- starts the next failure at
570 C<reconnect_delay> again. A watch cycle that ends cleanly (the server-side
571 L</timeout>) is not a failure and reconnects at once; one that closes within
572 L</min_watch_duration> without an event, or right after an C<ERROR> event,
573 did not end cleanly.
574  
575 =head2 max_reconnect_delay
576  
577 Upper bound in seconds for the reconnect delay. Default: 30, the same cap
578 client-go's reflector puts on its watch backoff: a cluster that comes back is
579 noticed within half a minute, and one that stays away costs one request and
580 one report per half minute.
581  
582 =head2 reconnect_jitter
583  
584 The share, from 0 to 1, by which each reconnect delay is shortened at random.
585 Default: 0.2 -- a delay of 4 seconds becomes one between 3.2 and 4 seconds,
586 rounded to the millisecond. Without it, watchers that fail together (every
587 watch of a process, or of a fleet, on an API server that restarts) would
588 send their reconnects together again on every step of the backoff.
589  
590 The delay is only ever shortened: L</reconnect_delay> and
591 L</max_reconnect_delay> stay upper bounds, and C<retryAfterSeconds> in the
592 report (see L</on_error>) is the delay the watcher actually waits. With the
593 default each step of the backoff still lies above the one before it
594 (0.8 times double the delay is more than the delay). C<0> turns jitter off,
595 for delays that are exactly the documented ones.
596  
597 =head2 max_retries
598  
599 How many consecutive failed watch requests are retried before the watcher
600 gives up. Default: C<undef>, retry for as long as the watcher runs. When the
601 limit is exceeded the watcher stops and reports that it gave up (see
602 L</on_error>); C<start()> begins again with the full count. C<0> gives up on
603 the first failure.
604  
605 =head2 min_watch_duration
606  
607 Seconds a watch stream has to stay open before it may end without an event.
608 Default: 1. A stream that closes sooner without delivering a single event is
609 no watch cycle that ran its course but a failed attempt (see L</on_error>):
610 reconnecting at once would send the API server one watch request after
611 another in a tight loop -- a proxy or API server that accepts the watch and
612 closes it straight away. The default is the threshold client-go's reflector
613 uses for the same case (a "very short watch"): a real watch cycle runs until
614 the server-side L</timeout>, minutes, so one second tells the two apart with
615 room for a slow connection. C<0> turns the check off.
616  
617 =head2 label_selector
618  
619 Optional label selector (e.g., C<'app=web,env=prod'>).
620  
621 =head2 field_selector
622  
623 Optional field selector (e.g., C<'status.phase=Running'>).
624  
625 =head2 names
626  
627 Optional client-side filter for resource names. Accepts a single regex,
628 a string (exact match), or an arrayref of regexes/strings. Events whose
629 resource name does not match any of the patterns are silently dropped
630 before callbacks fire.
631  
632 # Single regex
633 names => qr/^nginx/
634  
635 # Multiple patterns (any match passes)
636 names => [qr/^nginx/, qr/^redis/]
637  
638 # Exact string match
639 names => 'my-pod'
640  
641 =head2 event_types
642  
643 Optional client-side filter for event types. Accepts an arrayref of
644 type strings (C<ADDED>, C<MODIFIED>, C<DELETED>, C<ERROR>). Events
645 whose type is not in the list are silently dropped.
646  
647 # Only ADDED and DELETED events
648 event_types => ['ADDED', 'DELETED']
649  
650 When not set, event types are automatically derived from which callbacks
651 are registered. If only C<on_added> is set, only C<ADDED> events are
652 dispatched. If C<on_event> is set (catch-all), all types pass through.
653  
654 =head2 on_added
655  
656 Callback for ADDED events. Receives the inflated IO::K8s object.
657  
658 =head2 on_modified
659  
660 Callback for MODIFIED events. Receives the inflated IO::K8s object.
661  
662 =head2 on_deleted
663  
664 Callback for DELETED events. Receives the inflated IO::K8s object.
665  
666 =head2 on_error
667  
668 Callback for errors of the watch. Receives a hashref shaped like a Kubernetes
669 C<Status>, in two cases:
670  
671 =over 4
672  
673 =item * An C<ERROR> event on the stream, for example a C<403> arriving
674 mid-stream: the raw C<Status> hashref the API server sent. C<410 Gone> is
675 handled internally and never reaches it.
676  
677 =item * A failed watch attempt: the request fails outright (TLS support
678 missing, a TLS or connection error, an unreachable API server), the API
679 server rejects it with an HTTP error status (C<401>, C<403>, C<5xx>), or the
680 stream it opens ends badly -- within L</min_watch_duration> without a single
681 event, or right after an C<ERROR> event other than C<410 Gone> (that event
682 is reported first, as above). The watcher builds this C<Status> itself.
683 C<reason> is C<WatchFailed>, C<code> the HTTP status of a rejected request,
684 the C<code> of the C<ERROR> event the stream ended on, or C<0> when neither
685 is there (no response arrived, or the stream closed without an event),
686 C<message> names the resource, what the watcher does next and the cause (for
687 a rejected request its HTTP status, reason and message, as in C<HTTP 403
688 Forbidden: pods is forbidden: ...>), and C<details> carries C<kind> (the watched resource) and, while the watcher
689 retries, C<retryAfterSeconds>:
690  
691 {
692 kind => 'Status',
693 apiVersion => 'v1',
694 status => 'Failure',
695 reason => 'WatchFailed',
696 code => 0,
697 message => 'watch Pod failed, retrying in 4s: Connection refused',
698 details => { kind => 'Pod', retryAfterSeconds => 4 },
699 }
700  
701 Once L</max_retries> is exceeded, the message says C<giving up after N
702 retries> instead and C<retryAfterSeconds> is absent; the watcher has
703 stopped by then.
704  
705 =back
706  
707 A failed watch attempt is reported whatever L</event_types> says. Without an
708 C<on_error> it is passed to C<warn> instead, so a watch that cannot reach its
709 cluster never fails silently. C<ERROR> events without an C<on_error> are
710 dropped, as before. The callback may call C<stop()>, which also cancels the
711 reconnect just announced.
712  
713 =head2 on_event
714  
715 Catch-all callback. Receives the L<Kubernetes::REST::WatchEvent> object.
716 Called in addition to the type-specific callbacks.
717  
718 =head2 start
719  
720 Start (or restart) the watch stream. Called automatically when the watcher
721 is added to the event loop. Safe to call multiple times (idempotent): a
722 watcher waiting to reconnect after a failed request is already running. After
723 C<stop()>, or after giving up on L</max_retries>, it starts over with the full
724 retry count.
725  
726 =head2 stop
727  
728 Stop the watch stream and cancel the current HTTP request, or a reconnect
729 that is waiting out its delay. The watcher will not automatically reconnect
730 until C<start()> is called again.
731  
732 =head1 SEE ALSO
733  
734 L<Net::Async::Kubernetes>, L<Kubernetes::REST::WatchEvent>,
735 L<IO::Async::Notifier>
736  
737 =head1 SUPPORT
738  
739 =head2 Issues
740  
741 Please report bugs and feature requests on GitHub at
742 L<https://github.com/Getty/p5-net-async-kubernetes/issues>.
743  
744 =head2 IRC
745  
746 Join C<#kubernetes> on C<irc.perl.org> or message Getty directly.
747  
748 =head1 CONTRIBUTING
749  
750 Contributions are welcome! Please fork the repository and submit a pull request.
751  
752 =head1 AUTHOR
753  
754 Torsten Raudssus <torsten@raudssus.de>
755  
756 =head1 COPYRIGHT AND LICENSE
757  
758 This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>.
759  
760 This is free software; you can redistribute it and/or modify it under
761 the same terms as the Perl 5 programming language system itself.
762  
763 =cut
↑ Summary Kubernetes.pm »