eg/lan.Rexfile

filter: Statementstmt 67.3% 99 / 147 Branchbran 61.8% 47 / 76 Conditioncond 25.4% 14 / 55 MC/DCmcdc 10.0% 3 / 30 Subroutinesub 80.9% 17 / 21 Podpod n/a totaltotal 54.7% 180 / 329 CC 57 SCAR 39.6
CC
57
Cov
58%
__ANON__
159.4
__ANON__
42.0
cilium_release
39.6
CRAP 52.3
« blib/lib/Rex/Rancher.pm ↑ Summary lib/Rex/Rancher/K8s.pm »
1 # LAN test node -> single-node RKE2 or K3s cluster, GPU optional,
2 # optionally a second host joining it as agent.
3 #
4 # Meant as a live rig for a machine on the local network: every run goes
5 # through the public API of Rex::Rancher only, and the `check` task prints
6 # the control points after each step. Nothing here is Hetzner-specific.
7 #
8 # Usage (192.0.2.10 / .11 are placeholders -- use your LAN addresses):
9 #
10 # rex -f eg/lan.Rexfile -T # list tasks
11 # rex -f eg/lan.Rexfile -H 192.0.2.10 deploy # rke2, no GPU
12 # LAN_DIST=k3s rex -f eg/lan.Rexfile -H 192.0.2.10 deploy # k3s
13 # LAN_GPU=1 rex -f eg/lan.Rexfile -H 192.0.2.10 deploy # + GPU (reboots once)
14 # rex -f eg/lan.Rexfile -H 192.0.2.10 rerun # idempotency run
15 # rex -f eg/lan.Rexfile -H 192.0.2.10 check # control points
16 # LAN_CILIUM_UPGRADE_TO=1.20.2 \
17 # rex -f eg/lan.Rexfile -H 192.0.2.10 cilium_upgrade # upgrade w/ kubeconfig
18 # LAN_SERVER=192.0.2.10 rex -f eg/lan.Rexfile -H 192.0.2.11 join_agent # agent join
19 #
20 # Every run of one test series needs the SAME environment (LAN_DIST, LAN_GPU,
21 # ...): `rerun` and `check` read them to know what they are looking at.
22 #
23 # Environment (all optional unless noted):
24 #
25 # LAN_DIST rke2 (default) or k3s
26 # LAN_GPU 1 = gpu => 1 on the server (Rex::GPU needed), default 0
27 # LAN_REBOOT reboot after a driver install; default: LAN_GPU
28 # LAN_SERVER the server's LAN address; default: the -H host.
29 # Used as tls_san (so as kubeconfig server address and,
30 # on K3s, Cilium's k8s_service_host). REQUIRED for `join_agent`.
31 # LAN_KUBECONFIG local kubeconfig; default ~/.kube/lan-<dist>.yaml
32 # LAN_TOKEN cluster token; default: none, the server generates
33 # one and reuses it on every re-run, `join_agent` reads it
34 # from the server
35 # LAN_VERSION pinned rke2/k3s version (e.g. v1.33.4+rke2r1)
36 # LAN_CILIUM_VERSION Cilium version for deploy/rerun (library default 1.20.0)
37 # LAN_CILIUM_CLI_VERSION Cilium CLI version (for a newer Cilium)
38 # LAN_CILIUM_UPGRADE_TO Cilium version for `cilium_upgrade` (REQUIRED there)
39 # LAN_CLUSTER_CIDR cluster_cidr (pod network), e.g. 10.44.0.0/16
40 # LAN_HOSTNAME / LAN_DOMAIN / LAN_TIMEZONE passed to prepare_node when set
41 # LAN_AGENT_GPU 1 = gpu => 1 on the joining agent, default 0
42 # LAN_AGENT_HOSTNAME hostname for the agent (when set)
43 # LAN_JOIN_URL override the agent's join URL, e.g. a wrong address
44 # to see the join hint of install_agent (karr k44)
45 # LAN_USER / LAN_KEY SSH user (root) and private key (~/.ssh/id_ed25519)
46 #
47 # Prerequisites on the machine(s): fresh Debian/Ubuntu/Rocky, root SSH login
48 # with your key. The LibSSH backend needs no SFTP subsystem -- to rehearse an
49 # SFTP-less host, comment out `Subsystem sftp` in /etc/ssh/sshd_config and
50 # restart sshd; `check` shows what sshd has configured.
51 #
52 # For development (both repos checked out):
53 # PERL5LIB=lib:../rex-gpu/lib:$PERL5LIB rex -f eg/lan.Rexfile -H <IP> deploy
54 #
55 # The checklist for the live run of this rig stands in eg/lan.RUNBOOK.md.
56  
57 26 ▶use Rex -feature => ['1.4'];
Subroutine BEGIN: called CC=1 SCAR=0.0
58 26 ▶use Rex::LibSSH;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 26 ▶use Rex::Rancher;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 26 ▶use Rex::Rancher::Server; # get_token
Subroutine BEGIN: called CC=1 SCAR=0.0
61 26 ▶use Rex::Rancher::Cilium; # upgrade_cilium
Subroutine BEGIN: called CC=1 SCAR=0.0
62 26 ▶use Kubernetes::REST::Kubeconfig;
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 # --- Configuration ---
65  
66 23 ▶my $DIST = $ENV{LAN_DIST} || 'rke2';
Condition100%2/2
$ENV{'LAN_DIST'} || 'rke2'
l!l
617
MC/DC100%1/1
$ENV{'LAN_DIST'} || 'rke2'
$ENV{'LAN_DIST'}
Truth table100%2/2
A
A= $ENV{'LAN_DIST'}
Aresult
11
00
67 23 ▶die "LAN_DIST must be rke2 or k3s, not '$DIST'\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $DIST eq "rke2" or $DIST eq "k3s" 0 23 23
Condition66%2/3
$DIST eq "rke2" or $DIST eq "k3s"
l!l&&r!l&&!r
1850
MC/DC0%0/2
$DIST eq "rke2" or $DIST eq "k3s"
$DIST eq "rke2" $DIST eq "k3s"
Truth table66%2/3
A or B
A= $DIST eq "rke2"B= $DIST eq "k3s"
ABresult
1X1
011
000
68 unless $DIST eq 'rke2' || $DIST eq 'k3s';
69  
70 23 ▶my $GPU = $ENV{LAN_GPU} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'LAN_GPU'} ? : 2 21 23
71 23 ▶my $REBOOT = defined $ENV{LAN_REBOOT} ? ( $ENV{LAN_REBOOT} ? 1 : 0 ) : $GPU;
Branch: 2 branches
BranchTrueFalseTotal
defined $ENV{'LAN_REBOOT'} ? : 1 22 23
$ENV{'LAN_REBOOT'} ? : 0 1 1
72 23 ▶my $KUBECONFIG = $ENV{LAN_KUBECONFIG} || $ENV{HOME}.'/.kube/lan-'.$DIST.'.yaml';
Condition100%2/2
$ENV{'LAN_KUBECONFIG'} || $ENV{'HOME'} . '/.kube/lan-' . $DIST . '.yaml'
l!l
1211
MC/DC100%1/1
$ENV{'LAN_KUBECONFIG'} || $ENV{'HOME'} . '/.kube/lan-' . $DIST . '.yaml'
$ENV{'LAN_KUBECONFIG'}
Truth table100%2/2
A
A= $ENV{'LAN_KUBECONFIG'}
Aresult
11
00
73  
74 # What differs between the two distributions, as far as this Rexfile has to
75 # look at the host itself. The library keeps its own table; this one is only
76 # for the `check` and `rerun` output.
77 23 my %HOST = (
78 rke2 => {
79 server_service => 'rke2-server',
80 agent_service => 'rke2-agent',
81 binary => 'rke2',
82 data_dir => '/var/lib/rancher/rke2',
83 config_dir => '/etc/rancher/rke2',
84 join_port => 9345
85 },
86 k3s => {
87 server_service => 'k3s',
88 agent_service => 'k3s-agent',
89 binary => 'k3s',
90 data_dir => '/var/lib/rancher/k3s',
91 config_dir => '/etc/rancher/k3s',
92 join_port => 6443
93 }
94 );
95 23 my $D = $HOST{$DIST};
96  
97 # --- Connection ---
98  
99 23 set connection => 'LibSSH';
100 23 ▶set user => ( $ENV{LAN_USER} || 'root' );
Condition50%1/2
$ENV{'LAN_USER'} || 'root'
l!l
023
MC/DC0%0/1
$ENV{'LAN_USER'} || 'root'
$ENV{'LAN_USER'}
Truth table50%1/2
A
A= $ENV{'LAN_USER'}
Aresult
11
00
101 23 ▶set private_key => ( $ENV{LAN_KEY} || $ENV{HOME}.'/.ssh/id_ed25519' );
Condition50%1/2
$ENV{'LAN_KEY'} || $ENV{'HOME'} . '/.ssh/id_ed25519'
l!l
023
MC/DC0%0/1
$ENV{'LAN_KEY'} || $ENV{'HOME'} . '/.ssh/id_ed25519'
$ENV{'LAN_KEY'}
Truth table50%1/2
A
A= $ENV{'LAN_KEY'}
Aresult
11
00
102 23 ▶set public_key => ( $ENV{LAN_KEY} ? $ENV{LAN_KEY}.'.pub' : $ENV{HOME}.'/.ssh/id_ed25519.pub' );
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'LAN_KEY'} ? : 0 23 23
103 23 set auth => 'key';
104  
105 # ============================================================
106 # Option builders
107 # ============================================================
108  
109 7 ▶sub server_address { $ENV{LAN_SERVER} || connection->server }
Subroutine server_address: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"LAN_SERVER"} or connection()->server 6 1 7
110  
111 11 ▶sub node_opts {
Subroutine node_opts: called CC=4 SCAR=13.9
112 11 my ( $prefix ) = @_;
113 return (
114 $ENV{$prefix.'HOSTNAME'} ? ( hostname => $ENV{$prefix.'HOSTNAME'} ) : (),
115 $ENV{LAN_DOMAIN} ? ( domain => $ENV{LAN_DOMAIN} ) : (),
116 11 ▶ $ENV{LAN_TIMEZONE} ? ( timezone => $ENV{LAN_TIMEZONE} ) : ()
Branch: 3 branches
BranchTrueFalseTotal
$ENV{$prefix . 'HOSTNAME'} ? : 2 9 11
$ENV{'LAN_DOMAIN'} ? : 1 10 11
$ENV{'LAN_TIMEZONE'} ? : 1 10 11
117 );
118 }
119  
120 6 ▶sub server_opts {
Subroutine server_opts: called CC=6 SCAR=17.9
121 return (
122 distribution => $DIST,
123 gpu => $GPU,
124 reboot => $REBOOT,
125 tls_san => server_address(),
126 kubeconfig_file => $KUBECONFIG,
127 node_opts('LAN_'),
128 $ENV{LAN_TOKEN} ? ( token => $ENV{LAN_TOKEN} ) : (),
129 $ENV{LAN_VERSION} ? ( version => $ENV{LAN_VERSION} ) : (),
130 $ENV{LAN_CLUSTER_CIDR} ? ( cluster_cidr => $ENV{LAN_CLUSTER_CIDR} ) : (),
131 $ENV{LAN_CILIUM_VERSION} ? ( cilium_version => $ENV{LAN_CILIUM_VERSION} ) : (),
132 6 ▶ $ENV{LAN_CILIUM_CLI_VERSION} ? ( cilium_cli_version => $ENV{LAN_CILIUM_CLI_VERSION} ) : ()
Branch: 5 branches
BranchTrueFalseTotal
$ENV{'LAN_TOKEN'} ? : 1 5 6
$ENV{'LAN_VERSION'} ? : 1 5 6
$ENV{'LAN_CLUSTER_CIDR'} ? : 1 5 6
$ENV{'LAN_CILIUM_VERSION'} ? : 1 5 6
$ENV{'LAN_CILIUM_CLI_VERSION'} ? : 1 5 6
133 );
134 }
135  
136 6 ▶sub deploy_server {
Subroutine deploy_server: called CC=1 SCAR=0.0
137 6 rancher_deploy_server( server_opts() );
138 6 untaint_node( kubeconfig => $KUBECONFIG );
139 }
140  
141 # ============================================================
142 # Test plan (karr k53)
143 # ============================================================
144  
145 23 desc 'Full server deployment: prepare -> [GPU] -> '.$DIST.' -> kubeconfig -> Cilium -> [device plugin] -> untaint';
146 6 ▶task 'deploy', sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
147 6 deploy_server();
148 6 say '';
149 6 say 'Done. export KUBECONFIG='.$KUBECONFIG;
150 6 say 'Next: rex -f eg/lan.Rexfile -H '.connection->server.' check';
151 23 };
152  
153 23 desc 'Same deploy again; compares the service and the Cilium release before and after';
154 0 ▶task 'rerun', sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
155 0 my $before = snapshot();
156 0 deploy_server();
157 0 my $after = snapshot();
158  
159 0 say '';
160 0 say '=== Re-run result ===';
161 0 printf " %-24s %s -> %s\n", $_, $before->{$_}, $after->{$_} for sort keys %$before;
162  
163 0 my $restarted = $before->{service} ne $after->{service};
164 0 ▶ if ( $DIST eq 'k3s' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DIST eq 'k3s') { } 0 0 0
165 0 ▶ say ' '.$D->{server_service}.' '.( $restarted ? 'restarted' : 'NOT restarted' )
Branch: 1 branch
BranchTrueFalseTotal
$restarted ? : 0 0 0
166 .' -- K3s is restarted on every run by design (install script rewrites the unit)';
167 }
168 else {
169 say $restarted
170 ? ' FAIL: '.$D->{server_service}.' was restarted -- a re-run with the same options must stay at start'
171 0 ▶ : ' OK: '.$D->{server_service}.' kept running (systemctl start, no restart)';
Branch: 1 branch
BranchTrueFalseTotal
$restarted ? : 0 0 0
172 }
173 say $before->{cilium_release} eq $after->{cilium_release}
174 0 ▶ ? ' OK: Cilium release untouched (noop)'
Branch: 1 branch
BranchTrueFalseTotal
$before->{'cilium_release'} eq $after->{'cilium_release'} ? : 0 0 0
175 : ' NOTE: Cilium release changed -- expected only if version/values differ from the last run';
176 23 };
177  
178 23 desc 'Upgrade Cilium through the saved kubeconfig to LAN_CILIUM_UPGRADE_TO, waiting until ready';
179 4 ▶task 'cilium_upgrade', sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
180 my $to = $ENV{LAN_CILIUM_UPGRADE_TO}
181 4 ▶ or die "Set LAN_CILIUM_UPGRADE_TO to the Cilium version to upgrade to\n";
Branch: 1 branch
BranchTrueFalseTotal
my $to = $ENV{"LAN_CILIUM_UPGRADE_TO"} or die "Set LAN_CILIUM_UPGRADE_TO to the Cilium version to upgrade to\n" 3 1 4
182 3 ▶ -f $KUBECONFIG or die 'No kubeconfig at '.$KUBECONFIG." -- run deploy first\n";
Branch: 1 branch
BranchTrueFalseTotal
-f $KUBECONFIG or die 'No kubeconfig at ' . $KUBECONFIG . " -- run deploy first\n" 2 1 3
183  
184 upgrade_cilium(
185 distribution => $DIST,
186 kubeconfig => $KUBECONFIG,
187 version => $to,
188 wait => 1,
189 $DIST eq 'k3s' ? ( k8s_service_host => server_address() ) : (),
190 2 ▶ $ENV{LAN_CILIUM_CLI_VERSION} ? ( cli_version => $ENV{LAN_CILIUM_CLI_VERSION} ) : ()
Branch: 2 branches
BranchTrueFalseTotal
$DIST eq 'k3s' ? : 1 1 2
$ENV{'LAN_CILIUM_CLI_VERSION'} ? : 0 2 2
191 );
192 2 say 'Cilium release now: '.cilium_release();
193 23 };
194  
195 23 desc 'Join this host as agent to LAN_SERVER (token read from the server unless LAN_TOKEN)';
196 6 ▶task 'join_agent', sub {
Subroutine __ANON__: called CC=9 SCAR=22.9
197 my $server = $ENV{LAN_SERVER}
198 6 ▶ or die "Set LAN_SERVER to the server's LAN address\n";
Branch: 1 branch
BranchTrueFalseTotal
my $server = $ENV{"LAN_SERVER"} or die "Set LAN_SERVER to the server's LAN address\n" 5 1 6
199 5 ▶ my $url = $ENV{LAN_JOIN_URL} || 'https://'.$server.':'.$D->{join_port};
Condition100%2/2
$ENV{'LAN_JOIN_URL'} || 'https://' . $server . ':' . $D->{'join_port'}
l!l
14
MC/DC100%1/1
$ENV{'LAN_JOIN_URL'} || 'https://' . $server . ':' . $D->{'join_port'}
$ENV{'LAN_JOIN_URL'}
Truth table100%2/2
A
A= $ENV{'LAN_JOIN_URL'}
Aresult
11
00
200  
201 # Read before the agent is touched; the token is never printed.
202 5 ▶ my $token = $ENV{LAN_TOKEN} || run_task( 'join_token', on => $server );
Condition33%1/3
$ENV{'LAN_TOKEN'} || run_task('join_token', 'on', $server)
l!l&&r!l&&!r
500
MC/DC0%0/2
$ENV{'LAN_TOKEN'} || run_task('join_token', 'on', $server)
$ENV{'LAN_TOKEN'} run_task('join_token', 'on', $server)
Truth table33%1/3
A || B
A= $ENV{'LAN_TOKEN'}B= run_task('join_token', 'on', $server)
ABresult
1X1
011
000
203 5 ▶ die 'No join token from '.$server." -- is the server deployed?\n" unless $token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 5 5
204  
205 rancher_deploy_agent(
206 distribution => $DIST,
207 server => $url,
208 token => $token,
209 gpu => ( $ENV{LAN_AGENT_GPU} ? 1 : 0 ),
210 reboot => ( $ENV{LAN_AGENT_GPU} ? 1 : 0 ),
211 node_opts('LAN_AGENT_'),
212 -f $KUBECONFIG ? ( kubeconfig_file => $KUBECONFIG ) : (),
213 5 ▶ $ENV{LAN_VERSION} ? ( version => $ENV{LAN_VERSION} ) : ()
Branch: 4 branches
BranchTrueFalseTotal
$ENV{'LAN_AGENT_GPU'} ? : 1 4 5
$ENV{'LAN_AGENT_GPU'} ? : 1 4 5
-f $KUBECONFIG ? : 0 5 5
$ENV{'LAN_VERSION'} ? : 0 5 5
214 );
215 5 say 'Joined '.connection->server.' via '.$url;
216 23 };
217  
218 23 desc 'Internal: returns the server join token to `join_agent` (prints nothing)';
219 0 ▶task 'join_token', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
220 0 return get_token($DIST);
221 23 };
222  
223 # ============================================================
224 # Control points
225 # ============================================================
226  
227 23 desc 'Print the control points: local via kubeconfig, remote via run';
228 2 ▶task 'check', sub {
Subroutine __ANON__: called CC=20 SCAR=50.7
229 my $svc = run( 'systemctl is-active '.$D->{agent_service}.' 2>/dev/null', auto_die => 0 ) eq 'active'
230 2 ▶ ? $D->{agent_service} : $D->{server_service};
Branch: 1 branch
BranchTrueFalseTotal
run('systemctl is-active ' . $D->{'agent_service'} . ' 2>/dev/null', 'auto_die', 0) eq 'active' ? : 0 2 2
231 2 my $cd = $D->{data_dir}.'/agent/etc/containerd';
232  
233 2 section( 'Host '.connection->server.' ('.$DIST.', '.$svc.')' );
234 2 remote( 'binary', 'PATH=$PATH:/usr/local/bin '.$D->{binary}.' --version 2>&1 | head -1' );
235 2 remote( 'is-active', 'systemctl is-active '.$svc );
236 2 remote( 'service', 'systemctl show -p MainPID -p ActiveEnterTimestamp -p NRestarts '.$svc );
237 2 remote( 'config.yaml', 'sed -e "s/^\(token:\).*/\1 <redacted>/" '.$D->{config_dir}.'/config.yaml' );
238 2 remote( 'swap', 'swapon --show --noheadings | grep . || echo off' );
239 2 remote( 'modules', 'lsmod | grep -E "^(br_netfilter|overlay) " | cut -d" " -f1' );
240 2 remote( 'sshd subsystem', 'sshd -T 2>/dev/null | grep -i "^subsystem" || echo "none (SFTP off)"' );
241  
242 2 section('GPU');
243 2 remote( 'nvidia-smi', 'nvidia-smi --query-gpu=name,driver_version,memory.total --format=csv,noheader 2>&1' );
244 2 remote( 'libcuda', 'ldconfig -p | grep -m1 libcuda.so.1 || echo missing' );
245 2 remote( 'drop-in', 'ls -1 '.$cd.'/config-v3.toml.d/ 2>/dev/null; cat '.$cd.'/config-v3.toml.d/99-nvidia.toml 2>/dev/null || echo "(no 99-nvidia.toml)"' );
246 2 remote( 'templates', 'ls -1 '.$cd.'/config*.tmpl 2>/dev/null || echo "(none)"' );
247 2 remote( 'nvidia runtime', 'grep -n "nvidia" '.$cd.'/config.toml 2>/dev/null | head -5' );
248  
249 2 ▶ return unless $svc eq $D->{server_service};
Branch: 1 branch
BranchTrueFalseTotal
unless $svc eq $D->{"server_service"} 0 2 2
250  
251 2 section( 'Cluster via '.$KUBECONFIG );
252 2 ▶ unless ( -f $KUBECONFIG ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $KUBECONFIG) 2 0 2
253 2 say ' no kubeconfig -- run deploy first';
254 2 return;
255 }
256 0 my $api = eval { Kubernetes::REST::Kubeconfig->new( kubeconfig_path => $KUBECONFIG )->api };
257 0 ▶ my $nodes = $api && eval { $api->list('Node') };
Condition0%0/3
$api && eval { do { $api->list('Node') } }
!ll&&!rl&&r
000
MC/DC0%0/2
$api && eval { do { $api->list('Node') } }
$api eval { do { $api->list('Node') } }
Truth table0%0/3
A && B
A= $apiB= eval { do { $api->list('Node') } }
ABresult
0X0
100
111
258 0 ▶ unless ($nodes) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nodes) 0 0 0
259 0 ▶ say ' API not reachable: '.( $@ || 'unknown error' );
Condition0%0/2
$@ || 'unknown error'
l!l
00
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
260 0 return;
261 }
262 0 for my $node ( @{ $nodes->items } ) {
263 0 my $st = $node->status;
264 0 ▶ my ($ready) = grep { $_->type eq 'Ready' } @{ $st->conditions // [] };
Condition0%0/2
$st->conditions // []
l!l
00
MC/DC0%0/1
$st->conditions // []
$st->conditions
Truth table0%0/2
A
A= $st->conditions
Aresult
11
00
265 0 ▶ my $taints = join ',', map { $_->key.':'.$_->effect } @{ $node->spec->taints // [] };
Condition0%0/2
$node->spec->taints // []
l!l
00
MC/DC0%0/1
$node->spec->taints // []
$node->spec->taints
Truth table0%0/2
A
A= $node->spec->taints
Aresult
11
00
266 printf " %-20s %-9s %-22s nvidia.com/gpu=%s taints=%s\n",
267 $node->metadata->name,
268 ( $ready && $ready->status eq 'True' ? 'Ready' : 'NotReady' ),
269 $st->nodeInfo->kubeletVersion,
270 0 ▶ ( ( $st->capacity // {} )->{'nvidia.com/gpu'} // 0 ),
Branch: 1 branch
BranchTrueFalseTotal
$ready && $ready->status eq 'True' ? : 0 0 0
Condition0%0/9
$ready and $ready->status eq "True"
!ll&&!rl&&r
000
+($st->capacity // {})->{"nvidia.com/gpu"} // 0
l!l
00
$st->capacity // {}
l!l
00
$taints || '-'
l!l
00
MC/DC0%0/2
$ready and $ready->status eq "True"
$ready $ready->status eq "True"
MC/DC0%0/1
+($st->capacity // {})->{"nvidia.com/gpu"} // 0
$st->capacity
MC/DC0%0/1
$taints || '-'
$taints
Truth table0%0/3
A and B
A= $readyB= $ready->status eq "True"
ABresult
0X0
100
111
Truth table0%0/2
A
A= $st->capacity
Aresult
11
00
Truth table0%0/2
A
A= $taints
Aresult
11
00
271 ( $taints || '-' );
272 }
273 0 for my $ds (qw( cilium nvidia-device-plugin-daemonset )) {
274 0 my $obj = eval { $api->get( 'DaemonSet', $ds, namespace => 'kube-system' ) };
275 0 ▶ my $s = $obj && $obj->status;
Condition0%0/3
$obj && $obj->status
!ll&&!rl&&r
000
MC/DC0%0/2
$obj && $obj->status
$obj $obj->status
Truth table0%0/3
A && B
A= $objB= $obj->status
ABresult
0X0
100
111
276 0 ▶ say ' DaemonSet '.$ds.': '
Branch: 1 branch
BranchTrueFalseTotal
$s ? : 0 0 0
Condition0%0/4
$s->numberReady // 0
l!l
00
$s->desiredNumberScheduled // 0
l!l
00
MC/DC0%0/1
$s->numberReady // 0
$s->numberReady
MC/DC0%0/1
$s->desiredNumberScheduled // 0
$s->desiredNumberScheduled
Truth table0%0/2
A
A= $s->numberReady
Aresult
11
00
Truth table0%0/2
A
A= $s->desiredNumberScheduled
Aresult
11
00
277 .( $s ? ( $s->numberReady // 0 ).'/'.( $s->desiredNumberScheduled // 0 ).' ready' : 'absent' );
278 }
279 0 say ' Cilium Helm release: '.cilium_release($api);
280 23 };
281  
282 # ============================================================
283 # Helpers for check / rerun
284 # ============================================================
285  
286 6 ▶sub section { say ''; say '=== '.$_[0].' ===' }
Subroutine section: called CC=1 SCAR=0.0
287  
288 24 ▶sub remote {
Subroutine remote: called CC=3 SCAR=11.0
289 24 my ( $label, $cmd ) = @_;
290 24 my $out = run( $cmd, auto_die => 0 );
291 24 ▶ $out = '(no output)' unless length $out;
Branch: 1 branch
BranchTrueFalseTotal
unless length $out 0 24 24
292 24 my @lines = split /\n/, $out;
293 24 printf " %-15s %s\n", $label, shift @lines;
294 24 printf " %-15s %s\n", '', $_ for @lines;
295 }
296  
297 # Newest revision of Cilium's Helm release as "vN status chart", or 'none'.
298 2 ▶sub cilium_release {
Subroutine cilium_release: called CC=10 SCAR=36.8
299 2 my ( $api ) = @_;
300 2 ▶ return 'no kubeconfig' unless -f $KUBECONFIG;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $KUBECONFIG 0 2 2
301 2 ▶ $api //= eval { Kubernetes::REST::Kubeconfig->new( kubeconfig_path => $KUBECONFIG )->api };
Condition33%1/3
$api //= eval { do { "Kubernetes::REST::Kubeconfig"->new("kubeconfig_path", $KUBECONFIG)->api } }
l!l&&r!l&&!r
002
MC/DC0%0/2
$api //= eval { do { "Kubernetes::REST::Kubeconfig"->new("kubeconfig_path", $KUBECONFIG)->api } }
$api eval { do { "Kubernetes::REST::Kubeconfig"->new("kubeconfig_path", $KUBECONFIG)->api } }
Truth table33%1/3
A //= B
A= $apiB= eval { do { "Kubernetes::REST::Kubeconfig"->new("kubeconfig_path", $KUBECONFIG)->api } }
ABresult
1X1
011
000
302 2 ▶ my $list = $api && eval {
Condition33%1/3
$api && eval { do { $api->list('Secret', 'namespace', 'kube-system', 'labelSelector', 'owner=helm,name=cilium') } }
!ll&&!rl&&r
200
MC/DC0%0/2
$api && eval { do { $api->list('Secret', 'namespace', 'kube-system', 'labelSelector', 'owner=helm,name=cilium') } }
$api eval { do { $api->list('Secret', 'namespace', 'kube-system', 'labelSelector', 'owner=helm,name=cilium') } }
Truth table33%1/3
A && B
A= $apiB= eval { do { $api->list('Secret', 'namespace', 'kube-system', 'labelSelector', 'owner=helm,name=cilium') } }
ABresult
0X0
100
111
303 0 $api->list( 'Secret', namespace => 'kube-system', labelSelector => 'owner=helm,name=cilium' );
304 };
305 2 ▶ return 'unreadable ('.( $@ || 'no API' ).')' unless $list;
Branch: 1 branch
BranchTrueFalseTotal
unless $list 2 0 2
Condition50%1/2
$@ || 'no API'
l!l
20
MC/DC0%0/1
$@ || 'no API'
$@
Truth table50%1/2
A
A= $@
Aresult
11
00
306 0 my ($newest) = sort { $b->{version} <=> $a->{version} }
307 0 ▶ map { $_->metadata->labels // {} } @{ $list->items // [] };
Condition0%0/4
$_->metadata->labels // {}
l!l
00
$list->items // []
l!l
00
MC/DC0%0/1
$_->metadata->labels // {}
$_->metadata->labels
MC/DC0%0/1
$list->items // []
$list->items
Truth table0%0/2
A
A= $_->metadata->labels
Aresult
11
00
Truth table0%0/2
A
A= $list->items
Aresult
11
00
308 0 ▶ return 'none' unless $newest;
Branch: 1 branch
BranchTrueFalseTotal
unless $newest 0 0 0
309 0 ▶ return 'v'.$newest->{version}.' '.( $newest->{status} // '?' );
Condition0%0/2
$newest->{"status"} // "?"
l!l
00
MC/DC0%0/1
$newest->{"status"} // "?"
$newest->{"status"}
Truth table0%0/2
A
A= $newest->{"status"}
Aresult
11
00
310 }
311  
312 0 ▶sub snapshot {
Subroutine snapshot: not called CC=1 SCAR=6.9
313 0 my $svc = $D->{server_service};
314 0 my $out = run( 'systemctl show -p MainPID -p ActiveEnterTimestamp '.$svc, auto_die => 0 );
315 0 $out =~ s/\n/ /g;
316 0 return { service => $out, cilium_release => cilium_release() };
317 }
318  
319 # ============================================================
320 # Pre-connect host-key scan (Rex::LibSSH >= 0.004)
321 # ============================================================
322 #
323 # A freshly installed LAN machine has no known_hosts entry; scan it in before
324 # the verified connect instead of switching verification off. Must come after
325 # the task definitions: 'before' attaches to tasks that already exist. After
326 # a reinstall the old key is stale -- remove it first (ssh-keygen -R <IP>).
327 0 ▶before 'ALL' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
328 0 my ( $server ) = @_;
329 0 rancher_scan_known_hosts($server);
330 23 };
331  
332 23 1;
« blib/lib/Rex/Rancher.pm ↑ Summary lib/Rex/Rancher/K8s.pm »