| 1 | package App::FargateStack::Builder::Cluster; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use App::FargateStack::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | ######################################################################## | ||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub build_fargate_cluster { | ||||||||||||||||||||||||||
|
Subroutine
build_fargate_cluster: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | ######################################################################## | ||||||||||||||||||||||||||||
| 17 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | my ( $config, $cluster, $dryrun ) = $self->common_args(qw(config cluster dryrun)); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $cluster //= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$cluster //= {}
MC/DC0%0/1
$cluster //= {}
$cluster
Truth table0%0/2
A
A= $cluster
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | my $ecs = $self->fetch_ecs; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my ( $cluster_name, $cluster_arn ) = @{$cluster}{qw(name arn)}; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ( !$cluster_name || !$cluster_arn ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cluster_name and $cluster_arn
MC/DC0%0/2
$cluster_name and $cluster_arn
$cluster_name
$cluster_arn
Truth table0%0/3
A and B
A= $cluster_nameB= $cluster_arn
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $config->{cluster} //= $cluster; | ||||||||||||||||||||||||||
|
Condition0%0/3
$config->{"cluster"} //= $cluster
MC/DC0%0/2
$config->{"cluster"} //= $cluster
$config->{"cluster"}
$cluster
Truth table0%0/3
A //= B
A= $config->{"cluster"}B= $cluster
| |||||||||||||||||||||||||||||
| 29 | 0 | $cluster_name = $self->create_default('cluster-name'); | |||||||||||||||||||||||||||
| 30 | 0 | $cluster->{name} = $cluster_name; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | ## - cluster exists? - | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ( !$cluster_arn || !$self->get_cache ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cluster_arn and $self->get_cache
MC/DC0%0/2
$cluster_arn and $self->get_cache
$cluster_arn
$self->get_cache
Truth table0%0/3
A and B
A= $cluster_arnB= $self->get_cache
| |||||||||||||||||||||||||||||
| 35 | # - validate cluster arn | ||||||||||||||||||||||||||||
| 36 | 0 | $cluster_arn = $ecs->cluster_exists($cluster_name); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ($cluster_arn) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | $self->log_info( sprintf 'cluster: [%s] exists...%s', $cluster_name, $self->get_cache || 'skipping' ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->get_cache || 'skipping'
MC/DC0%0/1
$self->get_cache || 'skipping'
$self->get_cache
Truth table0%0/2
A
A= $self->get_cache
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | $self->inc_existing_resources( cluster => [$cluster_arn] ); | |||||||||||||||||||||||||||
| 43 | 0 | $cluster->{arn} = $cluster_arn; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | return; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | ## - create cluster - | ||||||||||||||||||||||||||||
| 49 | 0 | $self->log_warn( sprintf 'cluster: [%s] will be created...%s', $cluster_name, $dryrun ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | $self->inc_required_resources( | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | cluster => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 53 | 0 | my ($dryrun) = @_; | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | return $dryrun ? "arn:???/$cluster_name" : $config->{cluster}->{arn}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | ); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | return | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if $dryrun; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | my $result = $ecs->create_cluster($cluster_name); | |||||||||||||||||||||||||||
| 62 | 0 | $ecs->check_result( 'ERROR: could not create cluster [%s]', $cluster_name ); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | $self->log_warn( sprintf 'cluster: [%s] created...', $cluster_name ); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | $cluster->{arn} = $result->{cluster}->{clusterArn}; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | return $TRUE; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | ######################################################################## | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub add_ecr_policy { | ||||||||||||||||||||||||||
|
Subroutine
add_ecr_policy: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | ######################################################################## | ||||||||||||||||||||||||||||
| 74 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | my $tasks = $self->get_config->{tasks}; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | my @repos; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | foreach my $task_name ( keys %{$tasks} ) { | |||||||||||||||||||||||||||
| 81 | 0 | my $image = $self->resolve_image_name( $tasks->{$task_name}->{image} ); | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ( $image =~ m{/}xsm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | ($image) = ( split m{/}xsm, $image )[-1]; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | my ( $name, $tag ) = split /:/xsm, $image; | |||||||||||||||||||||||||||
| 87 | 0 | push @repos, sprintf $ECR_ARN_TEMPLATE, $self->get_region, $self->get_account, $name; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | return ( | ||||||||||||||||||||||||||||
| 91 | 0 | { Effect => 'Allow', | |||||||||||||||||||||||||||
| 92 | Action => ['ecr:GetAuthorizationToken'], | ||||||||||||||||||||||||||||
| 93 | Resource => q{*} | ||||||||||||||||||||||||||||
| 94 | }, | ||||||||||||||||||||||||||||
| 95 | { Effect => 'Allow', | ||||||||||||||||||||||||||||
| 96 | Action => [qw(ecr:BatchGetImage ecr:GetDownloadUrlForLayer ecr:BatchCheckLayerAvailability)], | ||||||||||||||||||||||||||||
| 97 | Resource => \@repos, | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 1 | 1; | |||||||||||||||||||||||||||