| 1 | # ABSTRACT: What RKE2 and K3s differ in, and the host steps they share | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package Rex::Rancher::Distribution; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 63 | our $VERSION = '0.004'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | 63 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 63 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 63 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 63 | ▶ | use Rex::Commands::File (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 63 | ▶ | use Rex::Commands::Run (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 63 | ▶ | use Rex::Logger (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 63 | ▶ | use Rex::Rancher::Checksum; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 63 | ▶ | use Rex::Rancher::Options; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 63 | ▶ | use YAML::PP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 63 | ▶ | use YAML::PP::Common qw( PRESERVE_ORDER ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 63 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | # No `use utf8` here, on purpose: the die messages carry UTF-8 em dashes as | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # byte strings, exactly as Rex::Rancher::Server always emitted them. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | has role => ( | ||||||||||||||||||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 23 | default => 'server', | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 1596 | ▶ | isa => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1596 | ▶ | die "role must be 'server' or 'agent'\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $_[0] and $_[0] eq "server" || $_[0] eq "agent"
$_[0] eq "server" or $_[0] eq "agent"
MC/DC66%2/3
defined $_[0] and $_[0] eq "server" || $_[0] eq "agent"
defined $_[0]
$_[0] eq "server"
$_[0] eq "agent"
Truth table75%3/4
A and B or C
A= defined $_[0]B= $_[0] eq "server"C= $_[0] eq "agent"
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | unless defined $_[0] && ( $_[0] eq 'server' || $_[0] eq 'agent' ); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 63 | ); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1776 | ▶ | sub is_agent { $_[0]->role eq 'agent' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_agent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1833 | ▶ | sub distribution_classes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
distribution_classes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 1833 | rke2 => 'Rex::Rancher::Distribution::RKE2', | |||||||||||||||||||||||||||||||||||||||||
| 37 | k3s => 'Rex::Rancher::Distribution::K3s', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # use_module, not a `use` at the top: the classes extend this one, which has | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # to be complete (its attributes declared) before they load. Which one is | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # needed is known only from the caller's distribution option, and only a | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # name from distribution_classes is ever loaded. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 1495 | ▶ | sub new_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_for: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1495 | my ( $class, $name, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 1495 | ▶ | $name //= $class->default_distribution; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$name //= $class->default_distribution
MC/DC0%0/2
$name //= $class->default_distribution
$name
$class->default_distribution
Truth table66%2/3
A //= B
A= $nameB= $class->default_distribution
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1495 | ▶ | my $impl = $class->distribution_classes->{$name} | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$class->distribution_classes->{$name} // die($class->unknown_distribution($name) . "\n")
MC/DC100%1/1
$class->distribution_classes->{$name} // die($class->unknown_distribution($name) . "\n")
$class->distribution_classes->{$name}
Truth table100%2/2
A
A= $class->distribution_classes->{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | // die $class->unknown_distribution($name) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 1486 | return use_module($impl)->new(%args); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 353 | ▶ | sub default_distribution { 'rke2' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_distribution: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 19 | ▶ | sub unknown_distribution { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unknown_distribution: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 19 | my ( $class, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 19 | my $default = $class->default_distribution; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 19 | my @names = ( $default, sort grep { $_ ne $default } keys %{ $class->distribution_classes } ); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 19 | my $last = pop @names; | |||||||||||||||||||||||||||||||||||||||||
| 63 | return "Unknown distribution: $name (expected " | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 19 | ▶ | . join( ', ', map { "'$_'" } @names ) . ( @names ? ' or ' : '' ) . "'$last')"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1489 | ▶ | sub service { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
service: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1489 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 1489 | ▶ | return $self->is_agent ? $self->agent_service : $self->server_service; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 389 | ▶ | sub config_file { $_[0]->config_dir.'/config.yaml' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 82 | ▶ | sub registries_file { $_[0]->config_dir.'/registries.yaml' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
registries_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 179 | ▶ | sub cni_bin_dir { '/opt/cni/bin' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cni_bin_dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 179 | ▶ | sub cni_conf_dir { '/etc/cni/net.d' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cni_conf_dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 10 | ▶ | sub restart_services_cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restart_services_cmd: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 10 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 10 | return 'systemctl restart '.$self->server_service.'.service 2>/dev/null || systemctl restart ' | |||||||||||||||||||||||||||||||||||||||||
| 86 | .$self->agent_service.' 2>/dev/null'; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # Option checks (pure -- they die before anything touches the host) | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 9 | ▶ | sub resolve_install_method { shift; Rex::Rancher::Options->resolve_install_method(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve_install_method: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 14 | ▶ | sub check_cluster_cidr { shift; Rex::Rancher::Options->check_cluster_cidr(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_cluster_cidr: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | # | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # Release artifacts (install_method => 'artifact') | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 12 | ▶ | sub goarch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
goarch: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 12 | my ( $self, $uname ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 12 | ▶ | $uname //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$uname //= ""
MC/DC100%1/1
$uname //= ""
$uname
Truth table100%2/2
A
A= $uname
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 12 | $uname =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 12 | my %goarch = ( | |||||||||||||||||||||||||||||||||||||||||
| 107 | x86_64 => 'amd64', | ||||||||||||||||||||||||||||||||||||||||||
| 108 | amd64 => 'amd64', | ||||||||||||||||||||||||||||||||||||||||||
| 109 | aarch64 => 'arm64', | ||||||||||||||||||||||||||||||||||||||||||
| 110 | arm64 => 'arm64', | ||||||||||||||||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 12 | ▶ | return $goarch{$uname} | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$goarch{$uname} // die("Unsupported node architecture '${uname}' for install_method 'artifact'" . " (amd64 and arm64 only)\n")
MC/DC100%1/1
$goarch{$uname} // die("Unsupported node architecture '${uname}' for install_method 'artifact'" . " (amd64 and arm64 only)\n")
$goarch{$uname}
Truth table100%2/2
A
A= $goarch{$uname}
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | // die "Unsupported node architecture '$uname' for install_method 'artifact'" | ||||||||||||||||||||||||||||||||||||||||||
| 114 | . " (amd64 and arm64 only)\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 15 | ▶ | sub artifact_spec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
artifact_spec: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 15 | my ( $self, $arch, $version ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 15 | ▶ | die "install_method 'artifact' requires a version\n" unless $version; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 14 | ▶ | die "Invalid version '$version'\n" unless $version =~ /\A[A-Za-z0-9._+-]+\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 13 | (my $url_version = $version) =~ s/\+/%2B/g; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 13 | my $base = $self->release_url . '/' . $url_version; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 13 | my $dir = $self->artifact_dir; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 13 | my $asset = $self->asset_name($arch); | |||||||||||||||||||||||||||||||||||||||||
| 128 | 13 | my $sums = "sha256sum-$arch.txt"; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 13 | dir => $dir, | |||||||||||||||||||||||||||||||||||||||||
| 132 | script => "$dir/install.sh", | ||||||||||||||||||||||||||||||||||||||||||
| 133 | script_url => $self->install_url, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | asset => $asset, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | asset_url => "$base/$asset", | ||||||||||||||||||||||||||||||||||||||||||
| 136 | sums => $sums, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | sums_url => "$base/$sums", | ||||||||||||||||||||||||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 12 | ▶ | sub expected_sha256 { shift; Rex::Rancher::Checksum->expected_sha256(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expected_sha256: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | ▶ | sub sha256_of { shift; Rex::Rancher::Checksum->sha256_of(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sha256_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 10 | ▶ | sub verify_sha256 { shift; Rex::Rancher::Checksum->verify_sha256(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_sha256: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 12 | ▶ | sub download_cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
download_cmd: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 12 | my ( $self, $url, $dest, $progress ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 149 | # --progress-bar keeps output flowing during the ~60 MB tarball download, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | # so a long silent curl does not look like a hung channel. | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 12 | ▶ | my $flags = $progress ? '-fL --progress-bar' : '-fsSL'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 12 | return "curl $flags -o '$dest' '$url' 2>&1"; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 5 | ▶ | sub fetch_artifacts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_artifacts: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 5 | my ( $self, $version ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 5 | my $distribution = $self->name; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | my $arch = $self->goarch(Rex::Commands::Run::run("uname -m", auto_die => 1)); | |||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | my $spec = $self->artifact_spec($arch, $version); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | my $dir = $spec->{dir}; | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 4 | Rex::Logger::info("Downloading $distribution $version artifacts for $arch to $dir"); | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 4 | Rex::Commands::Run::run("rm -rf '$dir' && mkdir -p '$dir'", auto_die => 1); | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | for my $dl ( | |||||||||||||||||||||||||||||||||||||||||
| 169 | [ $spec->{script_url}, $spec->{script}, 0 ], | ||||||||||||||||||||||||||||||||||||||||||
| 170 | [ $spec->{sums_url}, "$dir/$spec->{sums}", 0 ], | ||||||||||||||||||||||||||||||||||||||||||
| 171 | [ $spec->{asset_url}, "$dir/$spec->{asset}", 1 ], | ||||||||||||||||||||||||||||||||||||||||||
| 172 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 12 | my ($url, $dest, $progress) = @{$dl}; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 12 | my $out = Rex::Commands::Run::run($self->download_cmd($url, $dest, $progress), auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 12 | ▶ | die "Download failed: $url\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$out // ""
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | . ($progress ? "If this 404s, $distribution $version publishes no build for '$arch'.\n" : '') | ||||||||||||||||||||||||||||||||||||||||||
| 177 | . ($out // '') . "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 178 | unless $? == 0; | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | my $sums = Rex::Commands::Run::run("cat '$dir/$spec->{sums}'", auto_die => 1); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | my $actual = Rex::Commands::Run::run("sha256sum '$dir/$spec->{asset}'", auto_die => 1); | |||||||||||||||||||||||||||||||||||||||||
| 183 | # scalar(): both return empty on no match; in this list they must stay undef. | ||||||||||||||||||||||||||||||||||||||||||
| 184 | $self->verify_sha256(scalar($self->expected_sha256($sums, $spec->{asset})), | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | scalar($self->sha256_of($actual)), $spec->{asset}); | |||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | Rex::Logger::info(" $spec->{asset}: sha256 verified"); | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | return $spec; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | # | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # Server install step: artifact or script, then whatever the distribution | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # needs to confirm it. | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 75 | ▶ | sub install_server_package { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
install_server_package: called CC=4 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 75 | my ( $self, $server, $version, $method ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 75 | ▶ | if (($method // 'script') eq 'artifact') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$method // "script"
MC/DC0%0/1
$method // "script"
$method
Truth table50%1/2
A
A= $method
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $spec = $self->fetch_artifacts($version); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | Rex::Logger::info("Installing " . $self->label . " from verified artifact $spec->{asset}..."); | |||||||||||||||||||||||||||||||||||||||||
| 203 | # auto_die => 1: with an artifact path RKE2's script takes its tarball | ||||||||||||||||||||||||||||||||||||||||||
| 204 | # method, which has no GPG key import (the Rocky 10 noise that | ||||||||||||||||||||||||||||||||||||||||||
| 205 | # Rex::Rancher::Distribution::RKE2 swallows is the RPM method's), so a | ||||||||||||||||||||||||||||||||||||||||||
| 206 | # non-zero exit here is a real failure. | ||||||||||||||||||||||||||||||||||||||||||
| 207 | Rex::Commands::Run::run($_, auto_die => 1) | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | for $self->artifact_install_cmds($spec, $server, $version); | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 75 | Rex::Logger::info("Installing " . $self->label . " via install script..."); | |||||||||||||||||||||||||||||||||||||||||
| 212 | 75 | $self->run_server_install_script($server, $version); | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | # | ||||||||||||||||||||||||||||||||||||||||||
| 217 | # Installed version | ||||||||||||||||||||||||||||||||||||||||||
| 218 | # | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | # "rke2 version v1.30.4+rke2r1 (abc)" / "k3s version v1.30.4+k3s1 (abc)"; | ||||||||||||||||||||||||||||||||||||||||||
| 222 | # the first word is argv[0]'s basename, so through /proc/PID/exe it is | ||||||||||||||||||||||||||||||||||||||||||
| 223 | # "exe version v1.36.4+rke2r1 (7479a59c)" (k68). Not "go version go1.26.7". | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 625 | ▶ | sub parse_version_output { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_version_output: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 625 | my ( $self, $out ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 625 | ▶ | return $1 if ($out // '') =~ /^(?!go )\S+ version (\S+)/m; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$out // ""
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 140 | return; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 252 | ▶ | sub same_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
same_version: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 252 | my ( $self, $want, $got ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 252 | ▶ | return 0 unless defined $want && defined $got; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $want and defined $got
MC/DC0%0/2
defined $want and defined $got
defined $want
defined $got
Truth table33%1/3
A and B
A= defined $wantB= defined $got
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 252 | my ($w, $g) = ($want, $got); | |||||||||||||||||||||||||||||||||||||||||
| 235 | 252 | s/\Av// for $w, $g; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 252 | ▶ | return $w eq $g ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 137 | ▶ | sub verify_installed_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_installed_version: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 137 | my ( $self, $version ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 137 | ▶ | return 1 unless $version; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 54 | my $distribution = $self->name; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 54 | my $binary = $self->binary; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 54 | my $out = Rex::Commands::Run::run("$binary --version 2>&1", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 247 | 54 | my $got = $self->parse_version_output($out); | |||||||||||||||||||||||||||||||||||||||||
| 248 | 54 | ▶ | die "Could not determine installed $distribution version ($binary --version):\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$out // ""
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | . ($out // '') . "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 250 | unless defined $got; | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 52 | ▶ | die "Installed $distribution version is $got, expected $version — the " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | . "install or upgrade did not take effect\n" | ||||||||||||||||||||||||||||||||||||||||||
| 253 | unless $self->same_version($version, $got); | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 50 | Rex::Logger::info(" $distribution $got installed"); | |||||||||||||||||||||||||||||||||||||||||
| 255 | 50 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | # | ||||||||||||||||||||||||||||||||||||||||||
| 259 | # Version skew: what may be installed over a running service, and when it | ||||||||||||||||||||||||||||||||||||||||||
| 260 | # may be restarted onto it. Kubernetes' version skew policy: a control plane | ||||||||||||||||||||||||||||||||||||||||||
| 261 | # moves one minor version at a time and never back, servers before agents, | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # and a kubelet is never newer than the API server. | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 781 | ▶ | sub parse_release { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_release: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 781 | my ( $self, $version ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 781 | ▶ | return unless defined $version | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $version and $version =~ /\Av?(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?(?:\+(?:rke2r|k3s)(\d+))?\z/u
MC/DC100%2/2
defined $version and $version =~ /\Av?(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?(?:\+(?:rke2r|k3s)(\d+))?\z/u
defined $version
$version =~ /\Av?(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?(?:\+(?:rke2r|k3s)(\d+))?\z/u
Truth table100%3/3
A and B
A= defined $versionB= $version =~ /\Av?(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?(?:\+(?:rke2r|k3s)(\d+))?\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | && $version =~ /\Av?(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?(?:\+(?:rke2r|k3s)(\d+))?\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 772 | ▶ | return ( $1, $2, $3, $4 // 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$4 // 0
MC/DC100%1/1
$4 // 0
$4
Truth table100%2/2
A
A= $4
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 165 | ▶ | sub compare_versions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compare_versions: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 165 | my ( $self, $x, $y ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 165 | my @a = $self->parse_release($x); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 165 | my @b = $self->parse_release($y); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 165 | ▶ | return unless @a && @b; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@a and @b
MC/DC100%2/2
@a and @b
@a
@b
Truth table100%3/3
A and B
A= @aB= @b
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 163 | for my $i (0 .. 3) { | |||||||||||||||||||||||||||||||||||||||||
| 280 | 552 | my $cmp = $a[$i] <=> $b[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 552 | ▶ | return $cmp if $cmp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 105 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 160 | ▶ | sub version_skew { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version_skew: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 160 | my ( $self, $from, $to ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 160 | my $cmp = $self->compare_versions($to, $from); | |||||||||||||||||||||||||||||||||||||||||
| 290 | 160 | ▶ | return unless defined $cmp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 159 | ▶ | return 'downgrade' if $cmp < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 147 | my @f = $self->parse_release($from); | |||||||||||||||||||||||||||||||||||||||||
| 293 | 147 | my @t = $self->parse_release($to); | |||||||||||||||||||||||||||||||||||||||||
| 294 | 147 | ▶ | if ( $t[0] == $f[0] && $t[1] == $f[1] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$t[0] == $f[0] and $t[1] == $f[1]
MC/DC100%2/2
$t[0] == $f[0] and $t[1] == $f[1]
$t[0] == $f[0]
$t[1] == $f[1]
Truth table100%3/3
A and B
A= $t[0] == $f[0]B= $t[1] == $f[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 114 | ▶ | return $self->same_version($from, $to) ? 'same' : 'patch'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 33 | ▶ | return ( $t[0] == $f[0] && $t[1] == $f[1] + 1 ) ? 'minor' : 'jump'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$t[0] == $f[0] and $t[1] == $f[1] + 1
MC/DC100%2/2
$t[0] == $f[0] and $t[1] == $f[1] + 1
$t[0] == $f[0]
$t[1] == $f[1] + 1
Truth table100%3/3
A and B
A= $t[0] == $f[0]B= $t[1] == $f[1] + 1
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 13 | ▶ | sub parse_channel_redirect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_channel_redirect: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 13 | my ( $self, $url ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 13 | ▶ | return unless ($url // '') =~ m{/releases/tag/([^/\s]+)\s*\z}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$url // ""
MC/DC100%1/1
$url // ""
$url
Truth table100%2/2
A
A= $url
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 11 | (my $version = $1) =~ s/%2B/+/gi; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 11 | my @parts = $self->parse_release($version); | |||||||||||||||||||||||||||||||||||||||||
| 306 | 11 | ▶ | return @parts ? $version : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 43 | ▶ | sub channel_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
channel_version: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 43 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 43 | my $out = Rex::Commands::Run::run("curl -fsSL -o /dev/null -w '%{url_effective}' '" | |||||||||||||||||||||||||||||||||||||||||
| 313 | . $self->channel_url . "' 2>/dev/null", auto_die => 0); | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 43 | ▶ | return unless $? == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 9 | return $self->parse_channel_redirect($out); | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 455 | ▶ | sub main_pid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
main_pid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 455 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 455 | return $self->parse_main_pid(Rex::Commands::Run::run( | |||||||||||||||||||||||||||||||||||||||||
| 322 | "systemctl show -p MainPID " . $self->service . " 2>/dev/null", auto_die => 0)); | ||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 287 | ▶ | sub running_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
running_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 287 | my ( $self, $pid ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 287 | return $self->parse_version_output( | |||||||||||||||||||||||||||||||||||||||||
| 329 | Rex::Commands::Run::run("/proc/$pid/exe --version 2>&1", auto_die => 0)); | ||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 276 | ▶ | sub installed_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
installed_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 276 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 276 | return $self->parse_version_output( | |||||||||||||||||||||||||||||||||||||||||
| 335 | Rex::Commands::Run::run($self->binary . " --version 2>&1", auto_die => 0)); | ||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 66 | ▶ | sub held_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
held_version: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 66 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 66 | my $pinned = $args{version}; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 66 | my $service = $self->service; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 66 | my $binary = $self->binary; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 66 | ▶ | my $release = sub { defined $_[0] && $self->parse_release($_[0]) ? $_[0] : undef }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
Condition100%3/3
defined $_[0] and $self->parse_release($_[0])
MC/DC100%2/2
defined $_[0] and $self->parse_release($_[0])
defined $_[0]
$self->parse_release($_[0])
Truth table100%3/3
A and B
A= defined $_[0]B= $self->parse_release($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 66 | my $pid = $self->main_pid; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 66 | my ( $held, $from ); | |||||||||||||||||||||||||||||||||||||||||
| 348 | 66 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 52 | $held = $release->($self->running_version($pid)); | |||||||||||||||||||||||||||||||||||||||||
| 350 | 52 | ▶ | $from = "$service runs $held" if defined $held; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 66 | ▶ | unless (defined $held) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 23 | $held = $release->($self->installed_version); | |||||||||||||||||||||||||||||||||||||||||
| 354 | 23 | ▶ | $from = ( $pid ? '' : "$service is not running, " ) . "the installed $binary is $held" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | if defined $held; | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 23 | ▶ | Rex::Logger::info("Could not ask the running $service (/proc/$pid/exe --version) for " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pid and defined $held
MC/DC100%2/2
$pid and defined $held
$pid
defined $held
Truth table100%3/3
A and B
A= $pidB= defined $held
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | . "its version: hold_running holds the installed $binary $held instead", 'warn') | ||||||||||||||||||||||||||||||||||||||||||
| 358 | if $pid && defined $held; | ||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 66 | ▶ | unless (defined $held) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 13 | ▶ | my $applies = defined $pinned && length $pinned | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $pinned and length $pinned
MC/DC50%1/2
defined $pinned and length $pinned
defined $pinned
length $pinned
Truth table66%2/3
A and B
A= defined $pinnedB= length $pinned
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | ? "version $pinned applies" | ||||||||||||||||||||||||||||||||||||||||||
| 364 | : "version is not pinned, the stable channel's applies"; | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 13 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 4 | Rex::Logger::info("Could not ask the running $service (/proc/$pid/exe --version) for " | |||||||||||||||||||||||||||||||||||||||||
| 367 | . "its version, and no installed $binary reports a version: hold_running holds " | ||||||||||||||||||||||||||||||||||||||||||
| 368 | . "nothing, $applies", 'warn'); | ||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 9 | Rex::Logger::info("hold_running: $service is not running and no installed $binary " | |||||||||||||||||||||||||||||||||||||||||
| 372 | . "reports a version: $applies"); | ||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 13 | return $pinned; | |||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 53 | ▶ | if (defined $pinned && length $pinned && !$self->same_version($pinned, $held)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $pinned and length $pinned and not $self->same_version($pinned, $held)
defined $pinned and length $pinned
MC/DC66%2/3
defined $pinned and length $pinned and not $self->same_version($pinned, $held)
defined $pinned
length $pinned
not $self->same_version($pinned, $held)
Truth table75%3/4
A and B and not(C)
A= defined $pinnedB= length $pinnedC= not $self->same_version($pinned, $held)
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 27 | Rex::Logger::info("hold_running: $from; that is the version for this run, not " | |||||||||||||||||||||||||||||||||||||||||
| 379 | . "version => '$pinned'", 'warn'); | ||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 26 | Rex::Logger::info("hold_running: $from; that is the version for this run"); | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 53 | return $held; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 210 | ▶ | sub check_version_skew { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_version_skew: called CC=19 SCAR=29.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 210 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 210 | my $pinned = $args{version}; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 210 | my $server = $args{server_version}; | |||||||||||||||||||||||||||||||||||||||||
| 392 | 210 | my $service = $self->service; | |||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 210 | my $pid = $self->main_pid; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 210 | ▶ | my $running = $pid ? $self->running_version($pid) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 210 | ▶ | Rex::Logger::info("Could not ask the running $service (/proc/$pid/exe --version) " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pid and not defined $running
MC/DC100%2/2
$pid and not defined $running
$pid
not defined $running
Truth table100%3/3
A and not(B)
A= $pidB= not defined $running
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | . "for its version: the version skew is checked only after the install, " | ||||||||||||||||||||||||||||||||||||||||||
| 398 | . "before $service is restarted", 'warn') | ||||||||||||||||||||||||||||||||||||||||||
| 399 | if $pid && !defined $running; | ||||||||||||||||||||||||||||||||||||||||||
| 400 | # Not running (stopped, crashed, never started): the binary on disk is what | ||||||||||||||||||||||||||||||||||||||||||
| 401 | # the node last ran, and start_verb has nothing to hold back once the | ||||||||||||||||||||||||||||||||||||||||||
| 402 | # installer replaced it. No binary: a fresh install, nothing to check. | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 210 | ▶ | my $installed = $pid ? undef : $self->installed_version; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 210 | ▶ | return unless defined $running || defined $installed || defined $server; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $running or defined $installed or defined $server
defined $running or defined $installed
MC/DC100%3/3
defined $running or defined $installed or defined $server
defined $running
defined $installed
defined $server
Truth table100%4/4
A or B or C
A= defined $runningB= defined $installedC= defined $server
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 119 | my $target = $pinned; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 119 | ▶ | unless (defined $target && length $target) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $target and length $target
MC/DC50%1/2
defined $target and length $target
defined $target
length $target
Truth table66%2/3
A and B
A= defined $targetB= length $target
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 41 | $target = $self->channel_version; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 41 | ▶ | unless (defined $target) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 33 | ▶ | Rex::Logger::info("Could not resolve the version " . $self->channel_url | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | . " would install: " | ||||||||||||||||||||||||||||||||||||||||||
| 412 | . ( defined $installed | ||||||||||||||||||||||||||||||||||||||||||
| 413 | ? "the version skew against the installed " . $self->binary . " $installed " | ||||||||||||||||||||||||||||||||||||||||||
| 414 | . "is not checked, and $service, which is not running, starts on " | ||||||||||||||||||||||||||||||||||||||||||
| 415 | . "whatever the install brings" | ||||||||||||||||||||||||||||||||||||||||||
| 416 | : "the version skew is checked only after the install, before $service " | ||||||||||||||||||||||||||||||||||||||||||
| 417 | . "is (re)started" ), 'warn'); | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 33 | return; | |||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 8 | Rex::Logger::info("version not pinned: the stable channel installs $target"); | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 86 | ▶ | if (defined $running) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 60 | ▶ | my $skew = $self->version_skew($running, $target) // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->version_skew($running, $target) // ""
MC/DC0%0/1
$self->version_skew($running, $target) // ""
$self->version_skew($running, $target)
Truth table50%1/2
A
A= $self->version_skew($running, $target)
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 60 | ▶ | die "Refusing to install " . $self->name . " $target" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$skew eq "jump" or $skew eq "downgrade"
MC/DC100%2/2
$skew eq "jump" or $skew eq "downgrade"
$skew eq "jump"
$skew eq "downgrade"
Truth table100%3/3
A or B
A= $skew eq "jump"B= $skew eq "downgrade"
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | . ( $pinned ? '' : " (the stable channel's version; version is not pinned)" ) | ||||||||||||||||||||||||||||||||||||||||||
| 427 | . ": $service runs $running, and " . $self->_skew_rule($skew, $running) | ||||||||||||||||||||||||||||||||||||||||||
| 428 | . " Nothing was installed; $service keeps running $running.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 429 | if $skew eq 'jump' || $skew eq 'downgrade'; | ||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | elsif (defined $installed) { | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 22 | $self->_check_installed_skew($installed, $target, $pinned); | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 64 | ▶ | $self->check_agent_version($target, $server) if defined $server; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 56 | return $target; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | # The service is not running: against the binary it would have started on. | ||||||||||||||||||||||||||||||||||||||||||
| 440 | 22 | ▶ | sub _check_installed_skew { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_installed_skew: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 22 | my ( $self, $installed, $target, $pinned ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 22 | my $service = $self->service; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 22 | my $binary = $self->binary; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 22 | ▶ | my $skew = $self->version_skew($installed, $target) // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->version_skew($installed, $target) // ""
MC/DC0%0/1
$self->version_skew($installed, $target) // ""
$self->version_skew($installed, $target)
Truth table50%1/2
A
A= $self->version_skew($installed, $target)
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 22 | ▶ | die "Refusing to install " . $self->name . " $target" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$skew eq "jump" or $skew eq "downgrade"
MC/DC100%2/2
$skew eq "jump" or $skew eq "downgrade"
$skew eq "jump"
$skew eq "downgrade"
Truth table100%3/3
A or B
A= $skew eq "jump"B= $skew eq "downgrade"
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | . ( $pinned ? '' : " (the stable channel's version; version is not pinned)" ) | ||||||||||||||||||||||||||||||||||||||||||
| 447 | . ": $service is not running, and the installed $binary is $installed; " | ||||||||||||||||||||||||||||||||||||||||||
| 448 | . $self->_skew_rule($skew, $installed) | ||||||||||||||||||||||||||||||||||||||||||
| 449 | . " Nothing was installed; $binary $installed stays in place.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 450 | if $skew eq 'jump' || $skew eq 'downgrade'; | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 14 | ▶ | Rex::Logger::info("$service is not running, and the installed $binary is " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$skew eq "minor" and not $pinned
MC/DC100%2/2
$skew eq "minor" and not $pinned
$skew eq "minor"
not $pinned
Truth table100%3/3
A and not(B)
A= $skew eq "minor"B= not $pinned
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | . "$installed: the stable channel's $target, a new minor version, is " | ||||||||||||||||||||||||||||||||||||||||||
| 453 | . "installed since version is not pinned, and $service starts on it. Pin " | ||||||||||||||||||||||||||||||||||||||||||
| 454 | . "version => '$installed' to stay on it", 'warn') | ||||||||||||||||||||||||||||||||||||||||||
| 455 | if $skew eq 'minor' && !$pinned; | ||||||||||||||||||||||||||||||||||||||||||
| 456 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 25 | ▶ | sub _skew_rule { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_skew_rule: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | 25 | my ( $self, $skew, $running ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 461 | 25 | my @r = $self->parse_release($running); | |||||||||||||||||||||||||||||||||||||||||
| 462 | 25 | ▶ | return $skew eq 'downgrade' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | ? "that is a downgrade, which Kubernetes' version skew policy does not " | ||||||||||||||||||||||||||||||||||||||||||
| 464 | . "allow. Pin version to $running or newer." | ||||||||||||||||||||||||||||||||||||||||||
| 465 | : "that skips a minor version: Kubernetes' version skew policy moves a " | ||||||||||||||||||||||||||||||||||||||||||
| 466 | . "node one minor version at a time. Upgrade to a v$r[0]." . ($r[1] + 1) | ||||||||||||||||||||||||||||||||||||||||||
| 467 | . " release first (pin version)."; | ||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 20 | ▶ | sub check_agent_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_agent_version: called CC=8 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 20 | my ( $self, $agent, $server, $installed ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 20 | my @a = $self->parse_release($agent); | |||||||||||||||||||||||||||||||||||||||||
| 474 | 20 | my @s = $self->parse_release($server); | |||||||||||||||||||||||||||||||||||||||||
| 475 | 20 | ▶ | unless (@a && @s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@a and @s
MC/DC0%0/2
@a and @s
@a
@s
Truth table33%1/3
A and B
A= @aB= @s
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | Rex::Logger::info("Could not compare " . $self->name . " $agent with the control " | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$server // "unknown"
MC/DC0%0/1
$server // "unknown"
$server
Truth table0%0/2
A
A= $server
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | . "plane's " . ( $server // 'unknown' ) . ": the agent is not checked against it", | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 'warn'); | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 20 | ▶ | return 1 if $a[0] < $s[0] || ( $a[0] == $s[0] && $a[1] <= $s[1] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$a[0] < $s[0] or $a[0] == $s[0] and $a[1] <= $s[1]
$a[0] == $s[0] and $a[1] <= $s[1]
MC/DC33%1/3
$a[0] < $s[0] or $a[0] == $s[0] and $a[1] <= $s[1]
$a[0] < $s[0]
$a[0] == $s[0]
$a[1] <= $s[1]
Truth table50%2/4
A or B and C
A= $a[0] < $s[0]B= $a[0] == $s[0]C= $a[1] <= $s[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 11 | ▶ | die "Refusing the " . $self->name . " agent $agent: the control plane runs $server, " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | . "and a kubelet must never be of a newer minor version than the API server " | ||||||||||||||||||||||||||||||||||||||||||
| 484 | . "(Kubernetes' version skew policy: servers first, then agents). " | ||||||||||||||||||||||||||||||||||||||||||
| 485 | . ( $installed | ||||||||||||||||||||||||||||||||||||||||||
| 486 | ? $self->binary . " $agent is installed, but " . $self->service . " was not (re)started." | ||||||||||||||||||||||||||||||||||||||||||
| 487 | : "Nothing was installed." ) | ||||||||||||||||||||||||||||||||||||||||||
| 488 | . " Upgrade the servers first, or pin version to a v$s[0].$s[1] release.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | # | ||||||||||||||||||||||||||||||||||||||||||
| 492 | # Cluster CIDR: a server that is set up keeps the pod network it was set up | ||||||||||||||||||||||||||||||||||||||||||
| 493 | # with. Another cluster-cidr in config.yaml restarts it onto that range while | ||||||||||||||||||||||||||||||||||||||||||
| 494 | # its pods keep their addresses and the node podCIDRs and Cilium's pool stay | ||||||||||||||||||||||||||||||||||||||||||
| 495 | # on the old one (k67). | ||||||||||||||||||||||||||||||||||||||||||
| 496 | # | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 208 | ▶ | sub builtin_cluster_cidr { '10.42.0.0/16' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
builtin_cluster_cidr: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 119 | ▶ | sub is_established { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_established: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 119 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 119 | Rex::Commands::Run::run('systemctl is-active --quiet '.$self->server_service, auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 505 | 119 | ▶ | return 1 if $? == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | # Written once the control plane has bootstrapped its datastore. | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 29 | Rex::Commands::Run::run('test -e '.$self->_shell_quote($self->server_token), auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 508 | 29 | ▶ | return $? == 0 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 118 | ▶ | sub established_cluster_cidr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
established_cluster_cidr: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 118 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 514 | 118 | ▶ | return unless $self->is_established; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | 94 | my ( @cidr, $from ); | |||||||||||||||||||||||||||||||||||||||||
| 516 | 94 | for my $file ($self->_server_config_files) { | |||||||||||||||||||||||||||||||||||||||||
| 517 | 84 | my $config = $self->_read_server_config($file); | |||||||||||||||||||||||||||||||||||||||||
| 518 | # In the order of the file, as the distributions read it. | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 78 | for my $key (keys %{$config}) { | |||||||||||||||||||||||||||||||||||||||||
| 520 | 57 | ▶ | next unless $key =~ /\Acluster-cidr(\+?)\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 36 | my $append = $1; | |||||||||||||||||||||||||||||||||||||||||
| 522 | 36 | ▶ | my @value = ref $config->{$key} eq 'ARRAY' ? @{ $config->{$key} } : ( $config->{$key} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | die $self->_cluster_cidr_unknown( | ||||||||||||||||||||||||||||||||||||||||||
| 524 | "$file: cluster-cidr is neither a string nor a list of strings") | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 36 | ▶ | if grep { !defined || ref } @value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
!defined($_) || ref $_
MC/DC50%1/2
!defined($_) || ref $_
!defined($_)
ref $_
Truth table66%2/3
not(A) || B
A= !defined($_)B= ref $_
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | 34 | ▶ | @cidr = ( ( $append ? @cidr : () ), @value ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | 34 | $from = $file; | |||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 84 | ▶ | my $cidr = @cidr ? join(',', @cidr) : $self->builtin_cluster_cidr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 84 | ▶ | $from = undef unless @cidr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | 84 | ▶ | return wantarray ? ( $cidr, $from ) : $cidr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 109 | ▶ | sub check_established_cluster_cidr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_established_cluster_cidr: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 109 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 538 | 109 | my ( $running, $from ) = $self->established_cluster_cidr; | |||||||||||||||||||||||||||||||||||||||||
| 539 | 99 | ▶ | return unless defined $running; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 76 | my $given = $args{cluster_cidr}; | |||||||||||||||||||||||||||||||||||||||||
| 542 | 76 | ▶ | my $want = $given // ( $args{cilium} ? $self->cilium_config->{'cluster-cidr'} : undef ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
($given // ($args{"cilium"} ? $self->cilium_config->{"cluster-cidr"} : undef)) // $self->builtin_cluster_cidr
$given // ($args{"cilium"} ? $self->cilium_config->{"cluster-cidr"} : undef)
MC/DC0%0/3
($given // ($args{"cilium"} ? $self->cilium_config->{"cluster-cidr"} : undef)) // $self->builtin_cluster_cidr
$given
($args{"cilium"} ? $self->cilium_config->{"cluster-cidr"} : undef)
$self->builtin_cluster_cidr
Truth table75%3/4
A // B // C
A= $givenB= ($args{"cilium"} ? $self->cilium_config->{"cluster-cidr"} : undef)C= $self->builtin_cluster_cidr
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | // $self->builtin_cluster_cidr; | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 76 | s/\A\s+//, s/\s+\z// for $running, $want; | |||||||||||||||||||||||||||||||||||||||||
| 545 | 76 | ▶ | return $running if $running eq $want; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 22 | my $name = $self->name; | |||||||||||||||||||||||||||||||||||||||||
| 548 | 22 | my $config = $self->config_file; | |||||||||||||||||||||||||||||||||||||||||
| 549 | 22 | ▶ | die "Refusing to install $name with cluster-cidr $want" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | . ( defined $given ? ' (cluster_cidr)' : ' (cluster_cidr not given: the default)' ) | ||||||||||||||||||||||||||||||||||||||||||
| 551 | . ": the $name server on this host was set up with $running (" | ||||||||||||||||||||||||||||||||||||||||||
| 552 | . ( defined $from | ||||||||||||||||||||||||||||||||||||||||||
| 553 | ? "from $from" | ||||||||||||||||||||||||||||||||||||||||||
| 554 | : "${name}'s built-in default: no cluster-cidr in $config or $config.d" ) | ||||||||||||||||||||||||||||||||||||||||||
| 555 | . "), and the cluster-cidr of a running cluster cannot be changed. Pass " | ||||||||||||||||||||||||||||||||||||||||||
| 556 | . "cluster_cidr => '$running'. config.yaml is unchanged and nothing was installed.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | # config.yaml if there, then the drop-ins k3s' configfilearg (RKE2 uses it | ||||||||||||||||||||||||||||||||||||||||||
| 560 | # too) takes: no directories, .yaml/.yml in any case, in os.ReadDir order. | ||||||||||||||||||||||||||||||||||||||||||
| 561 | 94 | ▶ | sub _server_config_files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_server_config_files: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 94 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 563 | 94 | my $config = $self->config_file; | |||||||||||||||||||||||||||||||||||||||||
| 564 | 94 | my $dropins = $config.'.d'; | |||||||||||||||||||||||||||||||||||||||||
| 565 | 94 | my @files; | |||||||||||||||||||||||||||||||||||||||||
| 566 | 94 | Rex::Commands::Run::run('test -e '.$self->_shell_quote($config), auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 567 | 94 | ▶ | push @files, $config if $? == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 94 | Rex::Commands::Run::run('test -d '.$self->_shell_quote($dropins), auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 569 | 94 | ▶ | return @files unless $? == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | 57 | my $out = Rex::Commands::Run::run('find '.$self->_shell_quote($dropins) | |||||||||||||||||||||||||||||||||||||||||
| 571 | .' -mindepth 1 -maxdepth 1 ! -type d', auto_die => 0); | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 57 | ▶ | die $self->_cluster_cidr_unknown("Could not list $dropins (find exited ".($? >> 8).")") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | unless $? == 0; | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 55 | ▶ | push @files, sort grep { /\.ya?ml\z/i } split /\n/, $out // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$out // ""
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | 55 | return @files; | |||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | 84 | ▶ | sub _read_server_config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_server_config: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||
| 579 | 84 | my ( $self, $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 580 | 84 | my $content = Rex::Commands::Run::run('cat '.$self->_shell_quote($file), auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 581 | 84 | ▶ | die $self->_cluster_cidr_unknown("Could not read $file (cat exited ".($? >> 8).")") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 582 | unless $? == 0; | ||||||||||||||||||||||||||||||||||||||||||
| 583 | # Repeated keys are allowed, the last one wins, as in the distributions. | ||||||||||||||||||||||||||||||||||||||||||
| 584 | # Never the parser's message: it quotes the line, which may be the token's. | ||||||||||||||||||||||||||||||||||||||||||
| 585 | 82 | my @docs; | |||||||||||||||||||||||||||||||||||||||||
| 586 | 82 | ▶ | unless (eval { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 82 | ▶ | @docs = YAML::PP->new(duplicate_keys => 1, preserve => PRESERVE_ORDER) | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$content // ""
MC/DC0%0/1
$content // ""
$content
Truth table50%1/2
A
A= $content
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | ->load_string($content // ''); | ||||||||||||||||||||||||||||||||||||||||||
| 589 | 80 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 590 | }) { | ||||||||||||||||||||||||||||||||||||||||||
| 591 | 2 | ▶ | my ($line) = ($@ // '') =~ /^Line\s*:\s*(\d+)/m; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$@ // ""
MC/DC0%0/1
$@ // ""
$@
Truth table50%1/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 2 | ▶ | die $self->_cluster_cidr_unknown("Could not parse $file as YAML" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | . ( defined $line ? " (line $line)" : '' )); | ||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||
| 595 | 80 | ▶ | my $config = $docs[0] // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$docs[0] // {}
MC/DC100%1/1
$docs[0] // {}
$docs[0]
Truth table100%2/2
A
A= $docs[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 80 | ▶ | die $self->_cluster_cidr_unknown("$file is not a YAML mapping") unless ref $config eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 78 | return $config; | |||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | 10 | ▶ | sub _cluster_cidr_unknown { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cluster_cidr_unknown: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | 10 | my ( $self, $what ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 602 | 10 | return "$what, so the cluster-cidr the ".$self->name." server on this host was set up " | |||||||||||||||||||||||||||||||||||||||||
| 603 | . "with is unknown. config.yaml is unchanged and nothing was installed.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | # One shell word, whatever the name: the drop-in names come from the host. | ||||||||||||||||||||||||||||||||||||||||||
| 607 | 450 | ▶ | sub _shell_quote { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_shell_quote: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 608 | 450 | my ( $self, $word ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 450 | $word =~ s/'/'\\''/g; | |||||||||||||||||||||||||||||||||||||||||
| 610 | 450 | return "'$word'"; | |||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | # | ||||||||||||||||||||||||||||||||||||||||||
| 614 | # Service start and wait | ||||||||||||||||||||||||||||||||||||||||||
| 615 | # | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | 172 | ▶ | sub start_verb { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_verb: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | 172 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 620 | 172 | my $pid = $self->main_pid; | |||||||||||||||||||||||||||||||||||||||||
| 621 | 172 | ▶ | return 'start' if $pid && $self->_hold_new_binary($pid, $args{pinned}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pid and $self->_hold_new_binary($pid, $args{"pinned"})
MC/DC100%2/2
$pid and $self->_hold_new_binary($pid, $args{"pinned"})
$pid
$self->_hold_new_binary($pid, $args{"pinned"})
Truth table100%3/3
A and B
A= $pidB= $self->_hold_new_binary($pid, $args{"pinned"})
| |||||||||||||||||||||||||||||||||||||||||||
| 622 | 165 | ▶ | return 'restart' if $self->_stale_containerd_restart; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | # k3s restarts anyway, unless held. A `start` of a running service is a | ||||||||||||||||||||||||||||||||||||||||||
| 625 | # no-op, so it is turned into a restart exactly when the service runs on | ||||||||||||||||||||||||||||||||||||||||||
| 626 | # something older than what is on disk now. | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 150 | ▶ | my $default = $args{hold} ? 'start' : $self->default_start_verb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | 150 | ▶ | return $default unless $default eq 'start' && $pid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$default eq "start" and $pid
MC/DC100%2/2
$default eq "start" and $pid
$default eq "start"
$pid
Truth table100%3/3
A and B
A= $default eq "start"B= $pid
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | 56 | my @reasons = ( $self->_restart_reasons_for($pid), $self->_unit_rewritten($args{unit_digest}) ); | |||||||||||||||||||||||||||||||||||||||||
| 630 | 56 | ▶ | return $default unless @reasons; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 631 | 15 | Rex::Logger::info("Restarting " . $self->service . ", which reads these only when " | |||||||||||||||||||||||||||||||||||||||||
| 632 | . "it starts: " . join('; ', @reasons)); | ||||||||||||||||||||||||||||||||||||||||||
| 633 | 15 | return 'restart'; | |||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | 69 | ▶ | sub installer_unit_digest { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
installer_unit_digest: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 69 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 639 | 69 | ▶ | my @files = $self->installer_unit_files or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 640 | 46 | ▶ | return Rex::Commands::Run::run('sha256sum ' . join(' ', map { $self->_shell_quote($_) } @files) | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
Rex::Commands::Run::run('sha256sum ' . join(" ", map({$self->_shell_quote($_);} @files)) . ' 2>&1', "auto_die", 0) // ""
MC/DC0%0/1
Rex::Commands::Run::run('sha256sum ' . join(" ", map({$self->_shell_quote($_);} @files)) . ' 2>&1', "auto_die", 0) // ""
Rex::Commands::Run::run('sha256sum ' . join(" ", map({$self->_shell_quote($_);} @files)) . ' 2>&1', "auto_die", 0)
Truth table50%1/2
A
A= Rex::Commands::Run::run('sha256sum ' . join(" ", map({$self->_shell_quote($_);} @files)) . ' 2>&1', "auto_die", 0)
| |||||||||||||||||||||||||||||||||||||||||||
| 641 | . ' 2>&1', auto_die => 0) // ''; | ||||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | # The installer rewrote the unit or its env file with other content than | ||||||||||||||||||||||||||||||||||||||||||
| 645 | # before it ran: the service's arguments or environment (K3S_URL, proxies) | ||||||||||||||||||||||||||||||||||||||||||
| 646 | # changed, which it takes only when it starts. | ||||||||||||||||||||||||||||||||||||||||||
| 647 | 56 | ▶ | sub _unit_rewritten { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unit_rewritten: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 648 | 56 | my ( $self, $before ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 649 | 56 | ▶ | return unless defined $before; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 650 | 20 | ▶ | my $after = $self->installer_unit_digest // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->installer_unit_digest // ""
MC/DC0%0/1
$self->installer_unit_digest // ""
$self->installer_unit_digest
Truth table50%1/2
A
A= $self->installer_unit_digest
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 20 | ▶ | return if $after eq $before; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 652 | 2 | return "rewritten by the installer with other content: " | |||||||||||||||||||||||||||||||||||||||||
| 653 | . join(', ', $self->installer_unit_files); | ||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | # A restart onto the installed binary, checked against the running one. | ||||||||||||||||||||||||||||||||||||||||||
| 657 | # Rejected upgrades die here too: check_version_skew could not see them | ||||||||||||||||||||||||||||||||||||||||||
| 658 | # before the install when the channel did not resolve or moved in between. | ||||||||||||||||||||||||||||||||||||||||||
| 659 | # An unpinned new minor stays installed but not running (maintainer | ||||||||||||||||||||||||||||||||||||||||||
| 660 | # decision, k56): an unpinned re-run must not silently upgrade a running | ||||||||||||||||||||||||||||||||||||||||||
| 661 | # control plane. KillMode=process keeps pods up across a restart either way. | ||||||||||||||||||||||||||||||||||||||||||
| 662 | 75 | ▶ | sub _hold_new_binary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hold_new_binary: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 663 | 75 | my ( $self, $pid, $pinned ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 664 | 75 | my $running = $self->running_version($pid); | |||||||||||||||||||||||||||||||||||||||||
| 665 | 75 | my $installed = $self->installed_version; | |||||||||||||||||||||||||||||||||||||||||
| 666 | 75 | ▶ | return 0 unless defined $running && defined $installed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $running and defined $installed
MC/DC50%1/2
defined $running and defined $installed
defined $running
defined $installed
Truth table66%2/3
A and B
A= defined $runningB= defined $installed
| |||||||||||||||||||||||||||||||||||||||||||
| 667 | 66 | ▶ | my $skew = $self->version_skew($running, $installed) // return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->version_skew($running, $installed) // (return 0)
MC/DC0%0/1
$self->version_skew($running, $installed) // (return 0)
$self->version_skew($running, $installed)
Truth table50%1/2
A
A= $self->version_skew($running, $installed)
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | 66 | my $service = $self->service; | |||||||||||||||||||||||||||||||||||||||||
| 669 | 66 | my $binary = $self->binary; | |||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | 66 | ▶ | die "$binary $installed is installed, but $service runs $running, and " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$skew eq "jump" or $skew eq "downgrade"
MC/DC100%2/2
$skew eq "jump" or $skew eq "downgrade"
$skew eq "jump"
$skew eq "downgrade"
Truth table100%3/3
A or B
A= $skew eq "jump"B= $skew eq "downgrade"
| |||||||||||||||||||||||||||||||||||||||||||
| 672 | . $self->_skew_rule($skew, $running) . " $service was not restarted and " | ||||||||||||||||||||||||||||||||||||||||||
| 673 | . "keeps running $running; its next start (a reboot) runs $installed. " | ||||||||||||||||||||||||||||||||||||||||||
| 674 | . "Install $running again (pin version) or a release the policy allows.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 675 | if $skew eq 'jump' || $skew eq 'downgrade'; | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 63 | ▶ | return 0 unless $skew eq 'minor' && !$pinned; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$skew eq "minor" and not $pinned
MC/DC100%2/2
$skew eq "minor" and not $pinned
$skew eq "minor"
not $pinned
Truth table100%3/3
A and not(B)
A= $skew eq "minor"B= not $pinned
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||
| 678 | 4 | Rex::Logger::info("$service was NOT restarted: it runs $running, and $installed " | |||||||||||||||||||||||||||||||||||||||||
| 679 | . "is now installed, a new minor version from the stable channel since " | ||||||||||||||||||||||||||||||||||||||||||
| 680 | . "version is not pinned. It keeps running $running, and anything else " | ||||||||||||||||||||||||||||||||||||||||||
| 681 | . "changed for it waits too, until its next start (a reboot starts " | ||||||||||||||||||||||||||||||||||||||||||
| 682 | . "$installed). Pin version => '$installed' to have it restarted, or run: " | ||||||||||||||||||||||||||||||||||||||||||
| 683 | . "systemctl restart $service", 'warn'); | ||||||||||||||||||||||||||||||||||||||||||
| 684 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | # Rex::GPU 0.001 wrote agent/etc/containerd/config.toml.tmpl as a bare | ||||||||||||||||||||||||||||||||||||||||||
| 688 | # `imports = [...]` + `version = 2`. rke2 renders a template instead of its | ||||||||||||||||||||||||||||||||||||||||||
| 689 | # own config, so config.toml became exactly that: no SystemdCgroup, sandbox | ||||||||||||||||||||||||||||||||||||||||||
| 690 | # image or registry mirrors. remove_bare_containerd_template (which | ||||||||||||||||||||||||||||||||||||||||||
| 691 | # install_server and install_agent run before this) and Rex::GPU 0.002's | ||||||||||||||||||||||||||||||||||||||||||
| 692 | # gpu_setup remove the template, but restart nothing, and config.toml is | ||||||||||||||||||||||||||||||||||||||||||
| 693 | # rewritten only when the service starts. So: config.toml still in that | ||||||||||||||||||||||||||||||||||||||||||
| 694 | # shape and the template gone, or replaced by another one since -> restart a | ||||||||||||||||||||||||||||||||||||||||||
| 695 | # running service once; the rendered config no longer matches, so the next | ||||||||||||||||||||||||||||||||||||||||||
| 696 | # re-run starts (a no-op) again. The bare template still there (start_verb | ||||||||||||||||||||||||||||||||||||||||||
| 697 | # asked without removing it first) -> a restart would render the same file: | ||||||||||||||||||||||||||||||||||||||||||
| 698 | # warn with what to do. | ||||||||||||||||||||||||||||||||||||||||||
| 699 | 173 | ▶ | sub _stale_containerd_restart { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stale_containerd_restart: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | 173 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 701 | 173 | my $distribution = $self->name; | |||||||||||||||||||||||||||||||||||||||||
| 702 | 173 | my $service = $self->service; | |||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | 173 | my $dir = $self->containerd_dir; | |||||||||||||||||||||||||||||||||||||||||
| 705 | 173 | my $config = Rex::Commands::Run::run("cat $dir/config.toml 2>/dev/null", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 706 | 173 | ▶ | return 0 unless $self->is_bare_template_output($config); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||
| 708 | 29 | my $tmpl = Rex::Commands::Run::run("cat $dir/config.toml.tmpl 2>/dev/null", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 709 | 29 | my $has_tmpl = $? == 0; | |||||||||||||||||||||||||||||||||||||||||
| 710 | 29 | ▶ | if ($has_tmpl && $self->is_bare_template_output($tmpl)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$has_tmpl and $self->is_bare_template_output($tmpl)
MC/DC100%2/2
$has_tmpl and $self->is_bare_template_output($tmpl)
$has_tmpl
$self->is_bare_template_output($tmpl)
Truth table100%3/3
A and B
A= $has_tmplB= $self->is_bare_template_output($tmpl)
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | 2 | Rex::Logger::info("$dir/config.toml.tmpl holds only imports and version = 2 (as " | |||||||||||||||||||||||||||||||||||||||||
| 712 | . "Rex::GPU 0.001 wrote it) and replaces ${distribution}'s own containerd config: " | ||||||||||||||||||||||||||||||||||||||||||
| 713 | . "no SystemdCgroup, sandbox image or registry mirrors. Remove it " | ||||||||||||||||||||||||||||||||||||||||||
| 714 | . "(remove_bare_containerd_template, as install_server and install_agent do) " | ||||||||||||||||||||||||||||||||||||||||||
| 715 | . "and run: systemctl restart $service", 'warn'); | ||||||||||||||||||||||||||||||||||||||||||
| 716 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||
| 719 | 27 | Rex::Commands::Run::run("systemctl is-active --quiet $service", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 720 | 27 | my $prefix = ''; | |||||||||||||||||||||||||||||||||||||||||
| 721 | 27 | ▶ | unless ($? == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | # containerd 2.x exits on that bare config.toml, so the service never gets | ||||||||||||||||||||||||||||||||||||||||||
| 723 | # to active: it hangs in activating (its Restart= loop) or ends failed | ||||||||||||||||||||||||||||||||||||||||||
| 724 | # (k91). Either one wants to run and is restarted once. Stopped on purpose | ||||||||||||||||||||||||||||||||||||||||||
| 725 | # (inactive): its next start renders a fresh config.toml anyway. | ||||||||||||||||||||||||||||||||||||||||||
| 726 | 13 | ▶ | my $state = Rex::Commands::Run::run("systemctl is-active $service 2>/dev/null", auto_die => 0) // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
Rex::Commands::Run::run("systemctl is-active $service 2>/dev/null", "auto_die", 0) // ""
MC/DC0%0/1
Rex::Commands::Run::run("systemctl is-active $service 2>/dev/null", "auto_die", 0) // ""
Rex::Commands::Run::run("systemctl is-active $service 2>/dev/null", "auto_die", 0)
Truth table50%1/2
A
A= Rex::Commands::Run::run("systemctl is-active $service 2>/dev/null", "auto_die", 0)
| |||||||||||||||||||||||||||||||||||||||||||
| 727 | 13 | $state =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||
| 728 | 13 | ▶ | return 0 unless $state eq 'activating' || $state eq 'failed'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$state eq "activating" or $state eq "failed"
MC/DC100%2/2
$state eq "activating" or $state eq "failed"
$state eq "activating"
$state eq "failed"
Truth table100%3/3
A or B
A= $state eq "activating"B= $state eq "failed"
| |||||||||||||||||||||||||||||||||||||||||||
| 729 | 6 | $prefix = "$service is $state (containerd exits on its bare config); "; | |||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 20 | ▶ | Rex::Logger::info( $prefix . ( $has_tmpl | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 732 | ? "$dir/config.toml was rendered from Rex::GPU 0.001's bare config.toml.tmpl, " | ||||||||||||||||||||||||||||||||||||||||||
| 733 | . "which another template has replaced since; restarting $service so it " | ||||||||||||||||||||||||||||||||||||||||||
| 734 | . "renders that one" | ||||||||||||||||||||||||||||||||||||||||||
| 735 | : "$dir/config.toml was rendered from a config.toml.tmpl that is gone " | ||||||||||||||||||||||||||||||||||||||||||
| 736 | . "(Rex::GPU 0.001's); restarting $service so it regenerates its " | ||||||||||||||||||||||||||||||||||||||||||
| 737 | . "containerd config" ), 'warn'); | ||||||||||||||||||||||||||||||||||||||||||
| 738 | 20 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||
| 742 | # kubernetes-ocp before its k23 wrote the same two lines (its | ||||||||||||||||||||||||||||||||||||||||||
| 743 | # cleanup_legacy_containerd_template). Same narrow match as Rex::GPU 0.002's | ||||||||||||||||||||||||||||||||||||||||||
| 744 | # heal on gpu_setup; this covers a node re-run without Rex::GPU, or set up by | ||||||||||||||||||||||||||||||||||||||||||
| 745 | # kubernetes-ocp. `{{ template "base" . }}` or any further line keeps it. | ||||||||||||||||||||||||||||||||||||||||||
| 746 | 151 | ▶ | sub remove_bare_containerd_template { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_bare_containerd_template: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 747 | 151 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 748 | 151 | my $tmpl = $self->containerd_dir.'/config.toml.tmpl'; | |||||||||||||||||||||||||||||||||||||||||
| 749 | 151 | my $content = Rex::Commands::Run::run("cat $tmpl 2>/dev/null", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 750 | # No template: nothing to do. | ||||||||||||||||||||||||||||||||||||||||||
| 751 | 151 | ▶ | return 0 unless $? == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||
| 753 | 107 | ▶ | unless ($self->is_bare_template_output($content)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | 82 | Rex::Logger::info("Keeping $tmpl: it is not Rex::GPU 0.001's bare template " | |||||||||||||||||||||||||||||||||||||||||
| 755 | . "(only imports and version = 2) but somebody's containerd configuration"); | ||||||||||||||||||||||||||||||||||||||||||
| 756 | 82 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | 25 | my $label = $self->label; | |||||||||||||||||||||||||||||||||||||||||
| 760 | 25 | my $service = $self->service; | |||||||||||||||||||||||||||||||||||||||||
| 761 | 25 | Rex::Logger::info("Removing $tmpl: it holds only imports and version = 2 (Rex::GPU " | |||||||||||||||||||||||||||||||||||||||||
| 762 | . "0.001's bare template), which $label renders instead of its own containerd " | ||||||||||||||||||||||||||||||||||||||||||
| 763 | . "config: no SystemdCgroup, sandbox image or registry mirrors", 'warn'); | ||||||||||||||||||||||||||||||||||||||||||
| 764 | # auto_die => 0 only to die naming the file: a template left in place would | ||||||||||||||||||||||||||||||||||||||||||
| 765 | # be rendered again by the start that follows. | ||||||||||||||||||||||||||||||||||||||||||
| 766 | 25 | my $out = Rex::Commands::Run::run("rm -f $tmpl 2>&1", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 767 | 25 | ▶ | die "Could not remove $tmpl, the bare containerd template that replaces " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$out // ""
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | . "${label}'s own containerd config: " . ( ( $out // '' ) =~ s/\s+\z//r ) . "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 769 | unless $? == 0; | ||||||||||||||||||||||||||||||||||||||||||
| 770 | 19 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||
| 773 | # remove_bare_containerd_template right before a (re)start of the service | ||||||||||||||||||||||||||||||||||||||||||
| 774 | # (install_server, install_agent, update_registries): a failure there also | ||||||||||||||||||||||||||||||||||||||||||
| 775 | # means that start did not happen, which the error says. Outside a start | ||||||||||||||||||||||||||||||||||||||||||
| 776 | # (heal_bare_containerd_template) the sentence would mislead (k83). | ||||||||||||||||||||||||||||||||||||||||||
| 777 | 140 | ▶ | sub _remove_bare_template_before_start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_bare_template_before_start: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 778 | 140 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 779 | 140 | my $removed = eval { $self->remove_bare_containerd_template }; | |||||||||||||||||||||||||||||||||||||||||
| 780 | 140 | ▶ | die $@ . $self->service . " was not (re)started.\n" unless defined $removed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 781 | 134 | return $removed; | |||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | 8 | ▶ | sub heal_bare_containerd_template { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
heal_bare_containerd_template: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 786 | 8 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 787 | 8 | my $removed = $self->remove_bare_containerd_template; | |||||||||||||||||||||||||||||||||||||||||
| 788 | 8 | ▶ | return { removed => $removed, restarted => 0 } unless $self->_stale_containerd_restart; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | 5 | my $service = $self->service; | |||||||||||||||||||||||||||||||||||||||||
| 791 | 5 | my $out = Rex::Commands::Run::run("systemctl restart $service 2>&1", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 792 | 5 | ▶ | die "Could not restart $service after removing the bare containerd template: " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$out // ""
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
| |||||||||||||||||||||||||||||||||||||||||||
| 793 | . ( ( $out // '' ) =~ s/\s+\z//r ) . "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 794 | unless $? == 0; | ||||||||||||||||||||||||||||||||||||||||||
| 795 | 4 | return { removed => $removed, restarted => 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | 66 | ▶ | sub restart_watch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restart_watch: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 800 | 66 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 801 | 66 | my $containerd = $self->containerd_dir; | |||||||||||||||||||||||||||||||||||||||||
| 802 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 803 | 66 | ▶ | $self->config_file, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 804 | $self->config_dir.'/config.yaml.d', | ||||||||||||||||||||||||||||||||||||||||||
| 805 | $self->registries_file, | ||||||||||||||||||||||||||||||||||||||||||
| 806 | ( defined $self->env_file ? ( $self->env_file ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 807 | "$containerd/config.toml.tmpl", | ||||||||||||||||||||||||||||||||||||||||||
| 808 | "$containerd/config-v3.toml.tmpl", | ||||||||||||||||||||||||||||||||||||||||||
| 809 | "$containerd/config-v3.toml.d", | ||||||||||||||||||||||||||||||||||||||||||
| 810 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||
| 814 | 7 | ▶ | sub restart_reasons { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restart_reasons: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 815 | 7 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 816 | 7 | my $pid = $self->main_pid; | |||||||||||||||||||||||||||||||||||||||||
| 817 | 7 | ▶ | return unless $pid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 818 | 6 | return $self->_restart_reasons_for($pid); | |||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | 62 | ▶ | sub _restart_reasons_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_restart_reasons_for: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 822 | 62 | my ( $self, $pid ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 823 | 62 | my $service = $self->service; | |||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||
| 825 | 62 | my @reasons; | |||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||
| 827 | # Epoch seconds, both on the host's clock. Only files written after that | ||||||||||||||||||||||||||||||||||||||||||
| 828 | # second count, so one written in the second the process started is missed; | ||||||||||||||||||||||||||||||||||||||||||
| 829 | # everything here is written before the start, minutes earlier. | ||||||||||||||||||||||||||||||||||||||||||
| 830 | 62 | my $since = Rex::Commands::Run::run( | |||||||||||||||||||||||||||||||||||||||||
| 831 | "echo \$(( \$(date +%s) - \$(ps -o etimes= -p $pid) ))", auto_die => 0); | ||||||||||||||||||||||||||||||||||||||||||
| 832 | 62 | ▶ | if (($since // '') =~ /\A\s*(\d+)\s*\z/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$since // ""
MC/DC0%0/1
$since // ""
$since
Truth table50%1/2
A
A= $since
| |||||||||||||||||||||||||||||||||||||||||||
| 833 | 56 | $since = $1; | |||||||||||||||||||||||||||||||||||||||||
| 834 | 56 | my $paths = join(' ', map { "'$_'" } $self->restart_watch); | |||||||||||||||||||||||||||||||||||||||||
| 835 | 56 | my $changed = Rex::Commands::Run::run("find $paths -newermt \@$since 2>/dev/null", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 836 | 56 | ▶ | my @changed = grep { length } split /\n/, $changed // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$changed // ""
MC/DC0%0/1
$changed // ""
$changed
Truth table50%1/2
A
A= $changed
| |||||||||||||||||||||||||||||||||||||||||||
| 837 | 56 | ▶ | push @reasons, "changed since it started: " . join(', ', @changed) if @changed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||
| 839 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 840 | 6 | Rex::Logger::info("Could not tell when $service started (ps -o etimes= -p $pid): " | |||||||||||||||||||||||||||||||||||||||||
| 841 | . "changes to " . join(', ', $self->restart_watch) . " are not detected; " | ||||||||||||||||||||||||||||||||||||||||||
| 842 | . "restart $service yourself if one of them changed", 'warn'); | ||||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||
| 845 | # /proc/PID/exe still runs a binary the installer replaced (unlinked). | ||||||||||||||||||||||||||||||||||||||||||
| 846 | 62 | my $running = $self->running_version($pid); | |||||||||||||||||||||||||||||||||||||||||
| 847 | 62 | my $installed = $self->installed_version; | |||||||||||||||||||||||||||||||||||||||||
| 848 | 62 | ▶ | if (defined $running && defined $installed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $running and defined $installed
MC/DC50%1/2
defined $running and defined $installed
defined $running
defined $installed
Truth table66%2/3
A and B
A= defined $runningB= defined $installed
| |||||||||||||||||||||||||||||||||||||||||||
| 849 | 53 | ▶ | push @reasons, "it runs $running, $installed is installed" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 850 | unless $self->same_version($running, $installed); | ||||||||||||||||||||||||||||||||||||||||||
| 851 | } | ||||||||||||||||||||||||||||||||||||||||||
| 852 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 853 | 9 | Rex::Logger::info("Could not compare the running $service (/proc/$pid/exe " | |||||||||||||||||||||||||||||||||||||||||
| 854 | . "--version) with the installed " . $self->binary . " --version: a new binary " | ||||||||||||||||||||||||||||||||||||||||||
| 855 | . "is not detected; restart $service yourself after an upgrade", 'warn'); | ||||||||||||||||||||||||||||||||||||||||||
| 856 | } | ||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | 62 | return @reasons; | |||||||||||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | 460 | ▶ | sub parse_main_pid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_main_pid: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 863 | 460 | my ( $self, $out ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 864 | 460 | ▶ | return $1 if ($out // '') =~ /^MainPID=([1-9]\d*)\s*$/m; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$out // ""
MC/DC100%1/1
$out // ""
$out
Truth table100%2/2
A
A= $out
| |||||||||||||||||||||||||||||||||||||||||||
| 865 | 227 | return; | |||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||
| 869 | # Same narrow match as Rex::GPU 0.002's _is_rke2_clobber_tmpl. | ||||||||||||||||||||||||||||||||||||||||||
| 870 | 296 | ▶ | sub is_bare_template_output { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_bare_template_output: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 871 | 296 | my ( $self, $content ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 872 | 296 | ▶ | return 0 unless defined $content && length $content; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $content and length $content
MC/DC100%2/2
defined $content and length $content
defined $content
length $content
Truth table100%3/3
A and B
A= defined $contentB= length $content
| |||||||||||||||||||||||||||||||||||||||||||
| 873 | 100 | ▶ | my @lines = grep { /\S/ && !/^\s*#/ } split /\n/, $content; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
/\S/u && !/^\s*#/u
MC/DC100%2/2
/\S/u && !/^\s*#/u
/\S/u
!/^\s*#/u
Truth table100%3/3
A && not(B)
A= /\S/uB= !/^\s*#/u
| |||||||||||||||||||||||||||||||||||||||||||
| 874 | 100 | ▶ | return 0 unless @lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 875 | 100 | my ($imports, $version2) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 876 | 100 | for my $l (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 877 | 168 | ▶ | if ($l =~ /^\s*imports\s*=/) { $imports = 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 878 | 64 | elsif ($l =~ /^\s*version\s*=\s*2\s*$/) { $version2 = 1 } | |||||||||||||||||||||||||||||||||||||||||
| 879 | 40 | else { return 0 } | |||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||
| 881 | 60 | ▶ | return ($imports && $version2) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$imports and $version2
MC/DC100%2/2
$imports and $version2
$imports
$version2
Truth table100%3/3
A and B
A= $importsB= $version2
| |||||||||||||||||||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||
| 885 | 133 | ▶ | sub wait_for_service { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wait_for_service: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 886 | 133 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 887 | 133 | my $service = $self->service; | |||||||||||||||||||||||||||||||||||||||||
| 888 | 133 | ▶ | my $attempts = $args{attempts} // 60; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"attempts"} // 60
MC/DC100%1/1
$args{"attempts"} // 60
$args{"attempts"}
Truth table100%2/2
A
A= $args{"attempts"}
| |||||||||||||||||||||||||||||||||||||||||||
| 889 | 133 | ▶ | my $interval = $args{interval} // 10; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"interval"} // 10
MC/DC100%1/1
$args{"interval"} // 10
$args{"interval"}
Truth table100%2/2
A
A= $args{"interval"}
| |||||||||||||||||||||||||||||||||||||||||||
| 890 | 133 | my $hint = $args{hint}; | |||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||
| 892 | 133 | Rex::Logger::info("Waiting for $service to become active..."); | |||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||
| 894 | 133 | my $state = ''; | |||||||||||||||||||||||||||||||||||||||||
| 895 | 133 | for my $i (1 .. $attempts) { | |||||||||||||||||||||||||||||||||||||||||
| 896 | 138 | $state = Rex::Commands::Run::run("systemctl is-active $service", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 897 | 138 | ▶ | $state = '' unless defined $state; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 898 | 138 | $state =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 899 | 138 | ▶ | if ($state eq 'active') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 900 | 126 | Rex::Logger::info(" $service is active"); | |||||||||||||||||||||||||||||||||||||||||
| 901 | 126 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 902 | } | ||||||||||||||||||||||||||||||||||||||||||
| 903 | 12 | ▶ | die $self->_service_failure("is failed", $hint) if $state eq 'failed'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 904 | 7 | ▶ | Rex::Logger::info(" $service is " . ($state || 'unknown') . " ($i/$attempts)"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$state || 'unknown'
MC/DC0%0/1
$state || 'unknown'
$state
Truth table50%1/2
A
A= $state
| |||||||||||||||||||||||||||||||||||||||||||
| 905 | 7 | ▶ | sleep $interval if $i < $attempts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | 2 | ▶ | die $self->_service_failure( | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$state || 'unknown'
MC/DC0%0/1
$state || 'unknown'
$state
Truth table50%1/2
A
A= $state
| |||||||||||||||||||||||||||||||||||||||||||
| 909 | "did not become active within " . ($attempts * $interval) . "s (last state: " | ||||||||||||||||||||||||||||||||||||||||||
| 910 | . ($state || 'unknown') . ")", $hint); | ||||||||||||||||||||||||||||||||||||||||||
| 911 | } | ||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||
| 913 | 7 | ▶ | sub _service_failure { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_service_failure: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 914 | 7 | my ( $self, $reason, $hint ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 915 | 7 | my $service = $self->service; | |||||||||||||||||||||||||||||||||||||||||
| 916 | 7 | my $journal = Rex::Commands::Run::run("journalctl -u $service -n 50 --no-pager 2>&1", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 917 | 7 | ▶ | $journal = '' unless defined $journal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 918 | 7 | $journal =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 919 | 7 | ▶ | return "$service $reason\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 920 | . ( defined $hint ? "$hint\n" : '' ) | ||||||||||||||||||||||||||||||||||||||||||
| 921 | . "--- journalctl -u $service -n 50 ---\n" | ||||||||||||||||||||||||||||||||||||||||||
| 922 | . ($journal eq '' ? '(no journal output)' : $journal) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||
| 925 | # | ||||||||||||||||||||||||||||||||||||||||||
| 926 | # NVIDIA runtime lookup: a PATH for the rke2 units. | ||||||||||||||||||||||||||||||||||||||||||
| 927 | # | ||||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||
| 930 | 44 | ▶ | sub runtime_path_line { 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
runtime_path_line: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||
| 933 | 17 | ▶ | sub env_with_runtime_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
env_with_runtime_path: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 934 | 17 | my ( $self, $current ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 935 | 17 | ▶ | $current //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$current //= ""
MC/DC100%1/1
$current //= ""
$current
Truth table100%2/2
A
A= $current
| |||||||||||||||||||||||||||||||||||||||||||
| 936 | 17 | my @keep = grep { !/^\s*PATH=/ } split /\n/, $current; | |||||||||||||||||||||||||||||||||||||||||
| 937 | 17 | my $content = join('', map { $_."\n" } @keep, $self->runtime_path_line); | |||||||||||||||||||||||||||||||||||||||||
| 938 | 17 | ▶ | return $content eq $current ? undef : $content; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||||||||||||||
| 942 | # rke2-server/-agent.service carry no Environment= and read | ||||||||||||||||||||||||||||||||||||||||||
| 943 | # EnvironmentFile=-/etc/default/%N; rke2 scans PATH for nvidia-container-runtime | ||||||||||||||||||||||||||||||||||||||||||
| 944 | # at service start only, and the RKE2 GPU docs say to set PATH there. The rke2 | ||||||||||||||||||||||||||||||||||||||||||
| 945 | # install script does not touch /etc/default, so this survives the install. | ||||||||||||||||||||||||||||||||||||||||||
| 946 | # k3s has no env_file: its agent code does the same scan and wired a host | ||||||||||||||||||||||||||||||||||||||||||
| 947 | # toolkit plus the nvidia RuntimeClass on a DGX without help (kubernetes-ocp, | ||||||||||||||||||||||||||||||||||||||||||
| 948 | # _configure_nvidia_runtime_path). | ||||||||||||||||||||||||||||||||||||||||||
| 949 | 8 | ▶ | sub ensure_nvidia_runtime_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ensure_nvidia_runtime_path: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 950 | 8 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 951 | 8 | ▶ | my $env_file = $self->env_file or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||
| 953 | 6 | ▶ | unless (Rex::Commands::Run::can_run('nvidia-container-runtime')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 954 | 1 | Rex::Logger::info("nvidia-container-runtime not on PATH, $env_file left alone " | |||||||||||||||||||||||||||||||||||||||||
| 955 | . "(the GPU Operator's toolkit is found without it)"); | ||||||||||||||||||||||||||||||||||||||||||
| 956 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||
| 959 | 5 | my $current = Rex::Commands::Run::run("cat $env_file 2>/dev/null", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 960 | 5 | ▶ | my $content = $self->env_with_runtime_path($? == 0 ? $current : ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 961 | 5 | ▶ | unless (defined $content) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 962 | 1 | Rex::Logger::info("$env_file already carries the PATH for the NVIDIA runtime"); | |||||||||||||||||||||||||||||||||||||||||
| 963 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||
| 966 | 4 | Rex::Logger::info("Writing PATH to $env_file for the NVIDIA runtime lookup"); | |||||||||||||||||||||||||||||||||||||||||
| 967 | 4 | Rex::Commands::Run::run("mkdir -p /etc/default", auto_die => 1); | |||||||||||||||||||||||||||||||||||||||||
| 968 | # No secret in here: the file keeps its mode, a new one gets root's umask. | ||||||||||||||||||||||||||||||||||||||||||
| 969 | 4 | Rex::Commands::File::file($env_file, content => $content); | |||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||
| 971 | # Only on a re-run: the service reads the file when it starts. | ||||||||||||||||||||||||||||||||||||||||||
| 972 | 4 | my $service = $self->service; | |||||||||||||||||||||||||||||||||||||||||
| 973 | 4 | Rex::Commands::Run::run("systemctl is-active --quiet $service", auto_die => 0); | |||||||||||||||||||||||||||||||||||||||||
| 974 | 4 | ▶ | Rex::Logger::info("$service is running: it takes the new PATH at its next start " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 975 | . "(install_server and install_agent restart it for that)") | ||||||||||||||||||||||||||||||||||||||||||
| 976 | if $? == 0; | ||||||||||||||||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||
| 980 | 55 | ▶ | sub env_files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
env_files: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 981 | 55 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 982 | 55 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 983 | 55 | return grep { defined } map { $class->new( role => $_ )->env_file } qw( server agent ); | |||||||||||||||||||||||||||||||||||||||||
| 984 | } | ||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||
| 986 | # | ||||||||||||||||||||||||||||||||||||||||||
| 987 | # Secret files: config.yaml, registries.yaml | ||||||||||||||||||||||||||||||||||||||||||
| 988 | # | ||||||||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||
| 991 | # config.yaml carries the join token and registries.yaml may carry registry | ||||||||||||||||||||||||||||||||||||||||||
| 992 | # passwords, so both end up 0600 root:root. Rex's `file` writes content to a | ||||||||||||||||||||||||||||||||||||||||||
| 993 | # ".rex.tmp.<name>" sibling (LibSSH: `cat >` over an exec channel, no SFTP), | ||||||||||||||||||||||||||||||||||||||||||
| 994 | # renames it over the target and only then chmods -- the tmp file would be | ||||||||||||||||||||||||||||||||||||||||||
| 995 | # umask-mode (0644) in between. Pre-creating that tmp name at 0600 closes the | ||||||||||||||||||||||||||||||||||||||||||
| 996 | # window: `cat >` and SFTP open-truncate both keep an existing inode's mode, | ||||||||||||||||||||||||||||||||||||||||||
| 997 | # and the rename carries it to the target. The explicit chmod afterwards is | ||||||||||||||||||||||||||||||||||||||||||
| 998 | # what fixes an existing 0644 file whose content is unchanged (Rex then drops | ||||||||||||||||||||||||||||||||||||||||||
| 999 | # the tmp file and never touches the target), and fails loudly. | ||||||||||||||||||||||||||||||||||||||||||
| 1000 | 137 | ▶ | sub write_secret_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_secret_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1001 | 137 | my ( $self, $path, $content ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||||||||||||||||
| 1003 | 137 | my $tmp = Rex::Commands::File::get_tmp_file_name($path); | |||||||||||||||||||||||||||||||||||||||||
| 1004 | 137 | Rex::Commands::Run::run("install -m 600 -o root -g root /dev/null $tmp", auto_die => 1); | |||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||
| 1006 | 137 | Rex::Commands::File::file($path, content => $content); | |||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||
| 1008 | 137 | Rex::Commands::Run::run("chown root:root $path && chmod 600 $path", auto_die => 1); | |||||||||||||||||||||||||||||||||||||||||
| 1009 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||
| 1012 | 12 | ▶ | sub write_registries { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_registries: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1013 | 12 | my ( $self, $registries ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||
| 1015 | 12 | my $registries_file = $self->registries_file; | |||||||||||||||||||||||||||||||||||||||||
| 1016 | 12 | Rex::Logger::info("Writing registries config to $registries_file"); | |||||||||||||||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||||||||||||||||
| 1018 | 12 | $self->write_secret_file($registries_file, | |||||||||||||||||||||||||||||||||||||||||
| 1019 | YAML::PP->new(boolean => 'JSON::PP')->dump_string($registries)); | ||||||||||||||||||||||||||||||||||||||||||
| 1020 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||
| 1022 | 63 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||||
| 1024 | __END__ | ||||||||||||||||||||||||||||||||||||||||||