Skip to content

Commit 6b51ed4

Browse files
Fix call for k3s-selinux versions in airgapped environments (#7264)
* Fix call for k3s-selinux versions in airgapped environments Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com> * use timeout options in the donwloader Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com> * more fixes Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com> * run verify_downloader in case binary was skipped Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com> --------- Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
1 parent 027cc18 commit 6b51ed4

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

install.sh

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,45 @@ get_release_version() {
372372
info "Using ${VERSION_K3S} as release"
373373
}
374374

375+
# --- get k3s-selinux version ---
376+
get_k3s_selinux_version() {
377+
available_version="k3s-selinux-1.2-2.${rpm_target}.noarch.rpm"
378+
info "Finding available k3s-selinux versions"
379+
380+
# run verify_downloader in case it binary installation was skipped
381+
verify_downloader curl || verify_downloader wget || fatal 'Can not find curl or wget for downloading files'
382+
383+
case $DOWNLOADER in
384+
curl)
385+
DOWNLOADER_OPTS="-s"
386+
;;
387+
wget)
388+
DOWNLOADER_OPTS="-q -O -"
389+
;;
390+
*)
391+
fatal "Incorrect downloader executable '$DOWNLOADER'"
392+
;;
393+
esac
394+
for i in {1..3}; do
395+
set +e
396+
if [ "${rpm_channel}" = "testing" ]; then
397+
version=$(timeout 5 ${DOWNLOADER} ${DOWNLOADER_OPTS} https://api.github.com/repos/k3s-io/k3s-selinux/releases | grep browser_download_url | awk '{ print $2 }' | grep -oE "[^\/]+${rpm_target}\.noarch\.rpm" | head -n 1)
398+
else
399+
version=$(timeout 5 ${DOWNLOADER} ${DOWNLOADER_OPTS} https://api.github.com/repos/k3s-io/k3s-selinux/releases/latest | grep browser_download_url | awk '{ print $2 }' | grep -oE "[^\/]+${rpm_target}\.noarch\.rpm")
400+
fi
401+
set -e
402+
if [ "${version}" != "" ]; then
403+
break
404+
fi
405+
sleep 1
406+
done
407+
if [ "${version}" == "" ]; then
408+
warn "Failed to get available versions of k3s-selinux..defaulting to ${available_version}"
409+
return
410+
fi
411+
available_version=${version}
412+
}
413+
375414
# --- download from github url ---
376415
download() {
377416
[ $# -eq 2 ] || fatal 'download needs exactly 2 arguments'
@@ -497,12 +536,6 @@ setup_selinux() {
497536
package_installer=dnf
498537
fi
499538

500-
if [ "${rpm_channel}" = "testing" ]; then
501-
available_version=$(curl -s https://api.github.com/repos/k3s-io/k3s-selinux/releases | grep -oP '(?<="browser_download_url": ")[^"]*' | grep -oE "[^\/]+${rpm_target}\.noarch\.rpm" | head -n 1)
502-
else
503-
available_version=$(curl -s https://api.github.com/repos/k3s-io/k3s-selinux/releases/latest | grep -oP '(?<="browser_download_url": ")[^"]*' | grep -oE "[^\/]+${rpm_target}\.noarch\.rpm" )
504-
fi
505-
506539
policy_hint="please install:
507540
${package_installer} install -y container-selinux
508541
${package_installer} install -y https://${rpm_site}/k3s/${rpm_channel}/common/${rpm_site_infix}/noarch/${available_version}
@@ -511,6 +544,7 @@ setup_selinux() {
511544
if [ "$INSTALL_K3S_SKIP_SELINUX_RPM" = true ] || can_skip_download_selinux || [ ! -d /usr/share/selinux ]; then
512545
info "Skipping installation of SELinux RPM"
513546
else
547+
get_k3s_selinux_version
514548
install_selinux_rpm ${rpm_site} ${rpm_channel} ${rpm_target} ${rpm_site_infix}
515549
fi
516550

@@ -863,8 +897,8 @@ respawn_delay=5
863897
respawn_max=0
864898
865899
set -o allexport
866-
if [ -f /etc/environment ]; then sourcex /etc/environment; fi
867-
if [ -f ${FILE_K3S_ENV} ]; then sourcex ${FILE_K3S_ENV}; fi
900+
if [ -f /etc/environment ]; then . /etc/environment; fi
901+
if [ -f ${FILE_K3S_ENV} ]; then . ${FILE_K3S_ENV}; fi
868902
set +o allexport
869903
EOF
870904
$SUDO chmod 0755 ${FILE_K3S_SERVICE}

0 commit comments

Comments
 (0)