lib/Rex/Rancher/Distribution/RKE2.pm

filter: Statementstmt 100% 65 / 65 Branchbran 91.6% 11 / 12 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 36 / 36 Podpod 100% 30 / 30 totaltotal 94.7% 145 / 153 CC 9 SCAR 4.3
CC
9
Cov
95%
__ANON__
3.5
cilium_helm_defaults
3.0
script_install_cmd
3.0
CRAP 1.5
« lib/Rex/Rancher/Distribution/K3s.pm ↑ Summary
1 # ABSTRACT: RKE2: paths, services and installer of the default distribution
2  
3 package Rex::Rancher::Distribution::RKE2;
4 31 our $VERSION = '0.004';
5 31 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 31 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 31 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 31 ▶use Rex::Commands::Run ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # No `use utf8` here, on purpose: see Rex::Rancher::Distribution.
12  
13 31 extends 'Rex::Rancher::Distribution';
14  
15 371 ▶sub name { 'rke2' }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
16 113 ▶sub label { 'RKE2' }
Subroutine label: called CC=1 SCAR=0.0
Pod documented
17 371 ▶sub config_dir { '/etc/rancher/rke2' }
Subroutine config_dir: called CC=1 SCAR=0.0
Pod documented
18 82 ▶sub install_url { 'https://get.rke2.io' }
Subroutine install_url: called CC=1 SCAR=0.0
Pod documented
19 44 ▶sub channel_url { 'https://update.rke2.io/v1-release/channels/stable' }
Subroutine channel_url: called CC=1 SCAR=0.0
Pod documented
20 76 ▶sub kubeconfig { '/etc/rancher/rke2/rke2.yaml' }
Subroutine kubeconfig: called CC=1 SCAR=0.0
Pod documented
21 1 ▶sub token_file { '/var/lib/rancher/rke2/server/node-token' }
Subroutine token_file: called CC=1 SCAR=0.0
Pod documented
22 39 ▶sub server_token { '/var/lib/rancher/rke2/server/token' }
Subroutine server_token: called CC=1 SCAR=0.0
Pod documented
23 519 ▶sub binary { 'rke2' }
Subroutine binary: called CC=1 SCAR=0.0
Pod documented
24 8 ▶sub release_url { 'https://github.com/rancher/rke2/releases/download' }
Subroutine release_url: called CC=1 SCAR=0.0
Pod documented
25 8 ▶sub artifact_dir { '/tmp/rke2-artifacts' }
Subroutine artifact_dir: called CC=1 SCAR=0.0
Pod documented
26 232 ▶sub containerd_dir { '/var/lib/rancher/rke2/agent/etc/containerd' }
Subroutine containerd_dir: called CC=1 SCAR=0.0
Pod documented
27 794 ▶sub server_service { 'rke2-server' }
Subroutine server_service: called CC=1 SCAR=0.0
Pod documented
28 481 ▶sub agent_service { 'rke2-agent.service' }
Subroutine agent_service: called CC=1 SCAR=0.0
Pod documented
29 65 ▶sub default_start_verb { 'start' }
Subroutine default_start_verb: called CC=1 SCAR=0.0
Pod documented
30 52 ▶sub live_verified { 1 }
Subroutine live_verified: called CC=1 SCAR=0.0
Pod documented
31  
32 # None to compare: the units come in the version's own tarball or RPM, so
33 # the same version brings the same unit.
34 24 ▶sub installer_unit_files { () }
Subroutine installer_unit_files: called CC=1 SCAR=0.0
Pod documented
35  
36 # The install script puts it next to rke2, for server and agent alike.
37 27 ▶sub uninstall_scripts { ( 'rke2-uninstall.sh' ) }
Subroutine uninstall_scripts: called CC=1 SCAR=0.0
Pod documented
38  
39 # Every rke2 node serves the API on 127.0.0.1:6443.
40 297 ▶sub needs_k8s_service_host { 0 }
Subroutine needs_k8s_service_host: called CC=1 SCAR=0.0
Pod documented
41  
42 # RKE2 v1.37+ ships the Gateway API CRDs as its own chart, which would
43 # overwrite what gateway_api applies.
44 9 ▶sub gateway_api_crd_chart { 'rke2-gateway-api-crd' }
Subroutine gateway_api_crd_chart: called CC=1 SCAR=0.0
Pod documented
45  
46 # No bundled ingress controller: RKE2 ships the Traefik charts since v1.30.3
47 # and deploys Traefik by default on new clusters since v1.36; a chart name
48 # the installed RKE2 does not ship is ignored.
49 61 ▶sub default_disable { [ 'rke2-ingress-nginx', 'rke2-traefik', 'rke2-traefik-crd' ] }
Subroutine default_disable: called CC=1 SCAR=0.0
Pod documented
50  
51 # RKE2's own default (10.42.0.0/16) applies unwritten.
52 2 ▶sub default_cluster_cidr { undef }
Subroutine default_cluster_cidr: called CC=1 SCAR=0.0
Pod documented
53  
54 # rke2-server/-agent.service read EnvironmentFile=-/etc/default/%N and set no
55 # PATH (see ensure_nvidia_runtime_path).
56 126 ▶sub env_file {
Subroutine env_file: called CC=2 SCAR=6.9
Pod documented
57 126 my ( $self ) = @_;
58 126 ▶ return $self->is_agent ? '/etc/default/rke2-agent' : '/etc/default/rke2-server';
Branch: 1 branch
BranchTrueFalseTotal
$self->is_agent ? : 38 88 126
59 }
60  
61 8 ▶sub asset_name {
Subroutine asset_name: called CC=1 SCAR=0.0
Pod documented
62 8 my ( $self, $arch ) = @_;
63 8 return "rke2.linux-$arch.tar.gz";
64 }
65  
66 # Cilium is the only CNI and replaces kube-proxy
67 # (Rex::Rancher::Cilium wires kubeProxyReplacement).
68 75 ▶sub cilium_config {
Subroutine cilium_config: called CC=1 SCAR=0.0
Pod documented
69 return {
70 75 'cni' => 'none',
71 'disable-kube-proxy' => JSON()->true,
72 };
73 }
74  
75 # Pods take the node podCIDRs the cluster cuts from its cluster-cidr.
76 119 ▶sub default_ipam_mode { 'kubernetes' }
Subroutine default_ipam_mode: called CC=1 SCAR=0.0
Pod documented
77  
78 # Not exclusive: RKE2 keeps its own CNI config next to Cilium's. The mode is
79 # ipam_mode's where one is given; the server's cluster-cidr is the pool,
80 # which only a cluster-pool mode uses -- the kubernetes mode takes the node
81 # podCIDRs cut from it.
82 131 ▶sub cilium_helm_defaults {
Subroutine cilium_helm_defaults: called CC=3 SCAR=11.1
Pod documented
83 131 my ( $self, %args ) = @_;
84 return {
85 cni => { exclusive => JSON()->false },
86 k8sServiceHost => '127.0.0.1',
87 ipam => {
88 mode => $args{ipam_mode} // $self->default_ipam_mode,
89 ( defined $args{cluster_cidr}
90 131 ▶ ? ( operator => { clusterPoolIPv4PodCIDRList => [ $args{cluster_cidr} ] } )
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'cluster_cidr'} ? : 14 117 131
Condition66%2/3
$args{"ipam_mode"} // $self->default_ipam_mode
l!l&&r!l&&!r
131180
MC/DC0%0/2
$args{"ipam_mode"} // $self->default_ipam_mode
$args{"ipam_mode"} $self->default_ipam_mode
Truth table66%2/3
A // B
A= $args{"ipam_mode"}B= $self->default_ipam_mode
ABresult
1X1
011
000
91 : () ),
92 },
93 };
94 }
95  
96 74 ▶sub script_install_cmd {
Subroutine script_install_cmd: called CC=3 SCAR=11.0
Pod documented
97 74 my ( $self, $server, $version ) = @_;
98 # No server here: an HA join takes it from config.yaml.
99 74 my @env;
100 74 ▶ push @env, 'INSTALL_RKE2_TYPE=agent' if $self->is_agent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_agent 30 44 74
101 74 ▶ push @env, "INSTALL_RKE2_VERSION=$version" if $version;
Branch: 1 branch
BranchTrueFalseTotal
if $version 24 50 74
102 74 my $env_str = join('', map { "$_ " } @env);
103 74 return "curl -sfL " . $self->install_url . " | ${env_str}sh -";
104 }
105  
106 5 ▶sub artifact_install_cmds {
Subroutine artifact_install_cmds: called CC=2 SCAR=6.9
Pod documented
107 5 my ( $self, $spec, $server, $version ) = @_;
108 5 my @env = ("INSTALL_RKE2_ARTIFACT_PATH=$spec->{dir}");
109 5 ▶ push @env, 'INSTALL_RKE2_TYPE=agent' if $self->is_agent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_agent 2 3 5
110 5 push @env, "INSTALL_RKE2_VERSION=$version";
111 5 return ( join(' ', @env) . " sh $spec->{script}" );
112 }
113  
114 39 ▶sub run_server_install_script {
Subroutine run_server_install_script: called CC=1 SCAR=0.0
Pod documented
115 39 my ( $self, $server, $version ) = @_;
116 # auto_die => 0: the script emits GPG key import info on STDERR which can
117 # cause a non-zero exit on some distros (Rocky 10). Success is confirmed
118 # after install_server_package by `command -v rke2` instead.
119 39 Rex::Commands::Run::run($self->script_install_cmd($server, $version), auto_die => 0);
120 }
121  
122 # After either install method: the binary has to be there (the script's exit
123 # status is swallowed above). The version check follows in the caller: a
124 # failed pinned upgrade leaves the old binary in place.
125 39 ▶after install_server_package => sub {
Subroutine __ANON__: called CC=3 SCAR=12.5
126 39 my ( $self ) = @_;
127 39 my $check = Rex::Commands::Run::run("command -v rke2 2>/dev/null", auto_die => 0);
128 39 ▶ die "RKE2 install script failed — rke2 binary not found\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $check and $check =~ /rke2/u 0 39 39
Condition33%1/3
$check and $check =~ /rke2/u
!ll&&!rl&&r
0039
MC/DC0%0/2
$check and $check =~ /rke2/u
$check $check =~ /rke2/u
Truth table33%1/3
A and B
A= $checkB= $check =~ /rke2/u
ABresult
0X0
100
111
129 unless $check && $check =~ /rke2/;
130 31 };
131  
132 31 1;
133  
134 __END__
« lib/Rex/Rancher/Distribution/K3s.pm ↑ Summary