Skip to content

Commit

Permalink
Unpack cni_plugins, crictl & etcd to folders in /opt and use symlinks
Browse files Browse the repository at this point in the history
Makes the installation of cni_plugins, crictl & etcd similar to the way
the main k8s binaries are installed. The archives are unpacked to folders
in /opt and symlinked to /usr/local/bin . The target folder is unique
per version, making it possible to update these components.

Fixes #95.
  • Loading branch information
olavst-spk committed May 31, 2024
1 parent 843a4a1 commit f7dd164
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 18 deletions.
36 changes: 29 additions & 7 deletions manifests/install/cni_plugins.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,50 @@

'/etc/cni': ;
'/etc/cni/net.d': ;
'/opt/cni': ;
}

file { '/opt/cni':
ensure => stdlib::ensure($ensure, 'directory'),
purge => true,
recurse => true,
force => true,
}

case $method {
'tarball', 'loose': {
$_url = k8s::format_url($download_url_template, {
version => $version,
})
$_target = "/opt/cni/${version}";
$_tarball_target = '/opt/cni/archives';

file { '/opt/cni/bin':
ensure => directory,
file { $_target:
ensure => stdlib::ensure($ensure, 'directory'),
}

file { $_tarball_target:
ensure => stdlib::ensure($ensure, 'directory'),
purge => true,
recurse => true,
}

archive { 'cni-plugins':
ensure => $ensure,
path => "/tmp/cni-plugins-linux-${version}.tgz",
path => "${_tarball_target}/cni-plugins-linux-${version}.tgz",
source => $_url,
extract => true,
extract_path => '/opt/cni/bin',
creates => '/opt/cni/bin/bridge',
extract_path => $_target,
creates => "${_target}/bridge",
cleanup => true,
require => File['/opt/cni/bin'],
}

file { '/opt/cni/bin':
ensure => stdlib::ensure($ensure, 'link'),
mode => '0755',
replace => true,
force => true,
target => $_target,
require => Archive['cni-plugins'],
}
}
'package':{
Expand Down
31 changes: 28 additions & 3 deletions manifests/install/crictl.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,45 @@

$config_require = Package[$pkg]
} else {
file { '/opt/cri-tools':
ensure => stdlib::ensure($ensure, 'directory'),
purge => true,
recurse => true,
force => true,
}

$_url = k8s::format_url($download_url_template, {
version => $version,
})
$_target = "/opt/cri-tools/${version}";
$_tarball_target = '/opt/cri-tools/archives';

file { $_target:
ensure => stdlib::ensure($ensure, 'directory'),
}

file { $_tarball_target:
ensure => stdlib::ensure($ensure, 'directory'),
}

archive { 'crictl':
ensure => $ensure,
path => "/tmp/crictl-${version}-linux.tar.gz",
path => "${_tarball_target}/crictl-${version}-linux.tar.gz",
source => $_url,
extract => true,
extract_path => '/usr/local/bin',
creates => '/usr/local/bin/crictl',
extract_path => $_target,
creates => "${_target}/crictl",
cleanup => true,
}

file { '/usr/local/bin/crictl':
ensure => stdlib::ensure($ensure, 'link'),
mode => '0755',
replace => true,
target => "${_target}/crictl",
require => Archive['crictl'],
}

$config_require = Archive['crictl']
}

Expand Down
44 changes: 36 additions & 8 deletions manifests/server/etcd/setup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,52 @@
Optional[Integer[0, 65535]] $gid = undef,
) {
if $install == 'archive' {
file { '/opt/etcd':
ensure => stdlib::ensure($ensure, 'directory'),
purge => true,
recurse => true,
force => true,
}

$_url = k8s::format_url($archive_template, { version => $version, })
$_file = basename($_url)
$_target = "/opt/etcd/${version}";
$_tarball_target = '/opt/etcd/archives';

file { $_target:
ensure => stdlib::ensure($ensure, 'directory'),
}

archive { "/var/tmp/${_file}":
file { $_tarball_target:
ensure => stdlib::ensure($ensure, 'directory'),
}

archive { 'etcd':
ensure => $ensure,
path => "${_tarball_target}/${_file}",
source => $_url,
extract => true,
extract_command => 'tar xfz %s --strip-components=1',
extract_path => '/usr/local/bin',
extract_path => $_target,
cleanup => true,
creates => ['/usr/local/bin/etcd', '/usr/local/bin/etcdctl'],
notify => Service['etcd'],
creates => ["${_target}/etcd", "${_target}/etcdctl"],
}

file { '/usr/local/bin/etcd':
ensure => stdlib::ensure($ensure, 'link'),
mode => '0755',
replace => true,
target => "${_target}/etcd",
require => Archive['etcd'],
notify => Service['etcd'],
}

if $ensure == 'absent' {
file { ['/usr/local/bin/etcd', '/usr/local/bin/etcdctl']:
ensure => 'absent',
}
file { '/usr/local/bin/etcdctl':
ensure => stdlib::ensure($ensure, 'link'),
mode => '0755',
replace => true,
target => "${_target}/etcdctl",
require => Archive['etcd'],
}

group { $group:
Expand Down

0 comments on commit f7dd164

Please sign in to comment.