| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package IO::K8s::Role::Loadbalanced; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Role for traffic distribution (weighted backends, mirroring) |
|
3
|
|
|
|
|
|
|
our $VERSION = '1.008'; |
|
4
|
3
|
|
|
3
|
|
4557
|
use Moo::Role; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
25
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub set_weighted { |
|
7
|
4
|
|
|
4
|
0
|
10622
|
my ($self, $name, $weight) = @_; |
|
8
|
4
|
|
100
|
|
|
68
|
my $spec = $self->spec // {}; |
|
9
|
4
|
|
100
|
|
|
35
|
my $weighted = $spec->{weighted} //= { services => [] }; |
|
10
|
4
|
|
|
|
|
7
|
my $services = $weighted->{services}; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Update existing or add new |
|
13
|
4
|
|
|
|
|
6
|
my $found = 0; |
|
14
|
4
|
|
|
|
|
7
|
for my $svc (@$services) { |
|
15
|
2
|
100
|
|
|
|
9
|
if ($svc->{name} eq $name) { |
|
16
|
1
|
|
|
|
|
4
|
$svc->{weight} = $weight; |
|
17
|
1
|
|
|
|
|
2
|
$found = 1; |
|
18
|
1
|
|
|
|
|
2
|
last; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
} |
|
21
|
4
|
100
|
|
|
|
12
|
push @$services, { name => $name, weight => $weight } unless $found; |
|
22
|
4
|
|
|
|
|
59
|
$self->spec($spec); |
|
23
|
4
|
|
|
|
|
94
|
return $self; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub mirror_to { |
|
27
|
1
|
|
|
1
|
0
|
3509
|
my ($self, $name, %opts) = @_; |
|
28
|
1
|
|
50
|
|
|
14
|
my $spec = $self->spec // {}; |
|
29
|
1
|
|
50
|
|
|
12
|
my $mirroring = $spec->{mirroring} //= {}; |
|
30
|
1
|
|
50
|
|
|
4
|
my $mirrors = $mirroring->{mirrors} //= []; |
|
31
|
|
|
|
|
|
|
push @$mirrors, { |
|
32
|
|
|
|
|
|
|
name => $name, |
|
33
|
1
|
50
|
|
|
|
5
|
$opts{percent} ? (percent => $opts{percent}) : (), |
|
34
|
|
|
|
|
|
|
}; |
|
35
|
1
|
|
|
|
|
62
|
$self->spec($spec); |
|
36
|
1
|
|
|
|
|
22
|
return $self; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__END__ |