From 306dbafa4d6053ca19d68280d6994c1bacefc109 Mon Sep 17 00:00:00 2001 From: olavst-spk Date: Thu, 30 May 2024 14:55:39 +0200 Subject: [PATCH 1/2] Unpack cni_plugins, crictl & etcd to folders in /opt and use symlinks 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. --- manifests/install/cni_plugins.pp | 35 ++++++++++++++++---- manifests/install/crictl.pp | 31 ++++++++++++++++-- manifests/server/etcd/setup.pp | 44 +++++++++++++++++++++----- spec/classes/server/etcd/setup_spec.rb | 21 ++++++++++-- 4 files changed, 111 insertions(+), 20 deletions(-) diff --git a/manifests/install/cni_plugins.pp b/manifests/install/cni_plugins.pp index 50715a9..ea3bbc7 100644 --- a/manifests/install/cni_plugins.pp +++ b/manifests/install/cni_plugins.pp @@ -24,23 +24,46 @@ case $method { 'tarball', 'loose': { + file { '/opt/cni-plugins': + ensure => stdlib::ensure($ensure, 'directory'), + purge => true, + recurse => true, + force => true, + } + $_url = k8s::format_url($download_url_template, { version => $version, }) + $_target = "/opt/cni-plugins/${version}"; + $_tarball_target = '/opt/cni-plugins/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':{ diff --git a/manifests/install/crictl.pp b/manifests/install/crictl.pp index 9abd559..7b1b644 100644 --- a/manifests/install/crictl.pp +++ b/manifests/install/crictl.pp @@ -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'] } diff --git a/manifests/server/etcd/setup.pp b/manifests/server/etcd/setup.pp index da774e3..f1159e2 100644 --- a/manifests/server/etcd/setup.pp +++ b/manifests/server/etcd/setup.pp @@ -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: diff --git a/spec/classes/server/etcd/setup_spec.rb b/spec/classes/server/etcd/setup_spec.rb index 1c39e69..024d6a5 100644 --- a/spec/classes/server/etcd/setup_spec.rb +++ b/spec/classes/server/etcd/setup_spec.rb @@ -31,15 +31,30 @@ class { '::k8s::server::etcd': it { is_expected.to compile } it do - is_expected.to contain_archive('/var/tmp/etcd-v3.6.0-linux-amd64.tar.gz').with( + is_expected.to contain_archive('etcd').with( ensure: 'present', + path: '/opt/etcd/archives/etcd-v3.6.0-linux-amd64.tar.gz', source: 'https://storage.googleapis.com/etcd/v3.6.0/etcd-v3.6.0-linux-amd64.tar.gz', extract: true, extract_command: 'tar xfz %s --strip-components=1', - extract_path: '/usr/local/bin', + extract_path: '/opt/etcd/3.6.0', cleanup: true, - creates: ['/usr/local/bin/etcd', '/usr/local/bin/etcdctl'] + creates: ['/opt/etcd/3.6.0/etcd', '/opt/etcd/3.6.0/etcdctl'] + ) + + is_expected.to contain_file('/usr/local/bin/etcd').with( + ensure: 'link', + mode: '0755', + replace: true, + target: '/opt/etcd/3.6.0/etcd' ).that_notifies('Service[etcd]') + + is_expected.to contain_file('/usr/local/bin/etcdctl').with( + ensure: 'link', + mode: '0755', + replace: true, + target: '/opt/etcd/3.6.0/etcdctl' + ) end it { is_expected.to contain_user('etcd') } From c9e4f2edb2f32280c58e2b66ecc92800011444e0 Mon Sep 17 00:00:00 2001 From: olavst-spk Date: Mon, 3 Jun 2024 14:21:16 +0200 Subject: [PATCH 2/2] Move cni_plugins, crictl & etcd to subfolders in /opt/k8s --- manifests/install/cni_plugins.pp | 17 ++--------------- manifests/install/crictl.pp | 15 ++------------- manifests/server/etcd/setup.pp | 15 ++------------- spec/classes/server/etcd/setup_spec.rb | 10 +++++----- 4 files changed, 11 insertions(+), 46 deletions(-) diff --git a/manifests/install/cni_plugins.pp b/manifests/install/cni_plugins.pp index ea3bbc7..218611f 100644 --- a/manifests/install/cni_plugins.pp +++ b/manifests/install/cni_plugins.pp @@ -24,29 +24,16 @@ case $method { 'tarball', 'loose': { - file { '/opt/cni-plugins': - ensure => stdlib::ensure($ensure, 'directory'), - purge => true, - recurse => true, - force => true, - } - $_url = k8s::format_url($download_url_template, { version => $version, }) - $_target = "/opt/cni-plugins/${version}"; - $_tarball_target = '/opt/cni-plugins/archives'; + $_target = "/opt/k8s/cni-${version}"; + $_tarball_target = '/opt/k8s/archives'; 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 => "${_tarball_target}/cni-plugins-linux-${version}.tgz", diff --git a/manifests/install/crictl.pp b/manifests/install/crictl.pp index 7b1b644..6b23444 100644 --- a/manifests/install/crictl.pp +++ b/manifests/install/crictl.pp @@ -31,27 +31,16 @@ $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'; + $_target = "/opt/k8s/crictl-${version}"; + $_tarball_target = '/opt/k8s/archives'; file { $_target: ensure => stdlib::ensure($ensure, 'directory'), } - file { $_tarball_target: - ensure => stdlib::ensure($ensure, 'directory'), - } - archive { 'crictl': ensure => $ensure, path => "${_tarball_target}/crictl-${version}-linux.tar.gz", diff --git a/manifests/server/etcd/setup.pp b/manifests/server/etcd/setup.pp index f1159e2..b54a459 100644 --- a/manifests/server/etcd/setup.pp +++ b/manifests/server/etcd/setup.pp @@ -78,26 +78,15 @@ 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'; + $_target = "/opt/k8s/etcd-${version}"; + $_tarball_target = '/opt/k8s/archives'; file { $_target: ensure => stdlib::ensure($ensure, 'directory'), } - file { $_tarball_target: - ensure => stdlib::ensure($ensure, 'directory'), - } - archive { 'etcd': ensure => $ensure, path => "${_tarball_target}/${_file}", diff --git a/spec/classes/server/etcd/setup_spec.rb b/spec/classes/server/etcd/setup_spec.rb index 024d6a5..920b30e 100644 --- a/spec/classes/server/etcd/setup_spec.rb +++ b/spec/classes/server/etcd/setup_spec.rb @@ -33,27 +33,27 @@ class { '::k8s::server::etcd': it do is_expected.to contain_archive('etcd').with( ensure: 'present', - path: '/opt/etcd/archives/etcd-v3.6.0-linux-amd64.tar.gz', + path: '/opt/k8s/archives/etcd-v3.6.0-linux-amd64.tar.gz', source: 'https://storage.googleapis.com/etcd/v3.6.0/etcd-v3.6.0-linux-amd64.tar.gz', extract: true, extract_command: 'tar xfz %s --strip-components=1', - extract_path: '/opt/etcd/3.6.0', + extract_path: '/opt/k8s/etcd-3.6.0', cleanup: true, - creates: ['/opt/etcd/3.6.0/etcd', '/opt/etcd/3.6.0/etcdctl'] + creates: ['/opt/k8s/etcd-3.6.0/etcd', '/opt/k8s/etcd-3.6.0/etcdctl'] ) is_expected.to contain_file('/usr/local/bin/etcd').with( ensure: 'link', mode: '0755', replace: true, - target: '/opt/etcd/3.6.0/etcd' + target: '/opt/k8s/etcd-3.6.0/etcd' ).that_notifies('Service[etcd]') is_expected.to contain_file('/usr/local/bin/etcdctl').with( ensure: 'link', mode: '0755', replace: true, - target: '/opt/etcd/3.6.0/etcdctl' + target: '/opt/k8s/etcd-3.6.0/etcdctl' ) end