Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Struggling to fix k3s ebuild
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
erg_samowzbudnik
Apprentice
Apprentice


Joined: 09 Sep 2011
Posts: 229
Location: European sticks

PostPosted: Fri Dec 20, 2024 10:38 am    Post subject: Struggling to fix k3s ebuild Reply with quote

I'm attempting to fix a sys-cluster/k3s ebuild and I'm struggling.

What started as an attempt to add missing architectures support for k3s ebuild turned out to be bigger than that.
After adding arm64 support I realised it doesn't work even for amd64.

Be aware this is fairly involved ebuild and I'm new to this.

A diff between my attempt and an existing ebuild:

Code:
# diff k3s-1.25.4_p1.ebuild ../../../gentoo/sys-cluster/k3s/k3s-1.25.4_p1.ebuild
9,11c9,11
< K3S_CONTAINERD_VERSION=1.7.23-k3s2
< K3S_RUNC_VERSION=v1.2.1
< K3S_ROOT_VERSION=0.14.1
---
> K3S_CONTAINERD_VERSION=1.6.8-k3s1
> K3S_RUNC_VERSION=v1.1.4
> K3S_ROOT_VERSION=0.11.0
23,24c23
<       amd64? ( https://github.com/rancher/k3s-root/releases/download/v${K3S_ROOT_VERSION}/k3s-root-amd64.tar -> k3s-root-amd64-${K3S_ROOT_VERSION}.tar )
<       arm64? ( https://github.com/rancher/k3s-root/releases/download/v${K3S_ROOT_VERSION}/k3s-root-arm64.tar -> k3s-root-arm64-${K3S_ROOT_VERSION}.tar )"
---
>       amd64? ( https://github.com/rancher/k3s-root/releases/download/v${K3S_ROOT_VERSION}/k3s-root-amd64.tar -> k3s-root-amd64-${K3S_ROOT_VERSION}.tar )"
30c29
< REQUIRED_USE="|| ( amd64 arm64 )"
---
> REQUIRED_USE="|| ( amd64 )"
94c93
<       dobin "dist/artifacts/${PN}-${ARCH}"
---
>       dobin "dist/artifacts/${PN}"


A full ebuild:

Code:

# Copyright 2021-2023 Gentoo Authors # E: unknown USE flags: 'kubectl-symlink', 'rootless'
  # Distributed under the terms of the GNU General Public License v2
         
  EAPI=7 
  inherit go-module linux-info systemd
 
  DESCRIPTION="Lightweight Kubernetes"
  HOMEPAGE="https://k3s.io"
  K3S_CONTAINERD_VERSION=1.7.23-k3s2
  K3S_RUNC_VERSION=v1.2.1
  K3S_ROOT_VERSION=0.14.1
  K3S_TRAEFIK_VERSION=19.0.4
  K3S_TRAEFIK_PACKAGE_VERSION=00
  K3S_CNIPLUGINS_VERSION=1.1.1
  CONFIG_CHECK="~BRIDGE_NETFILTER ~CFS_BANDWIDTH ~CGROUP_DEVICE ~CGROUP_PERF ~CGROUP_PIDS ~IP_VS ~MEMCG ~NETFILTER_XT_MATCH_COMMENT ~OVERLAY_FS ~VLAN_8021Q ~VXLAN"
         
  MY_PV=${PV%_p*}+k3s${PV#*_p}
  SRC_URI="https://github.com/zmedico/k3s/archive/refs/tags/v${MY_PV}-vendor.tar.gz -> ${P}-vendor.tar.gz
      https://github.com/k3s-io/containerd/archive/refs/tags/v${K3S_CONTAINERD_VERSION}.tar.gz -> k3s-containerd-${K3S_CONTAINERD_VERSION}.tar.gz
      https://github.com/opencontainers/runc/archive/refs/tags/${K3S_RUNC_VERSION}.tar.gz -> k3s-runc-${K3S_RUNC_VERSION}.tar.gz
      https://traefik.github.io/charts/traefik/traefik-${K3S_TRAEFIK_VERSION}.tgz
      https://github.com/rancher/plugins/archive/refs/tags/v${K3S_CNIPLUGINS_VERSION}-k3s1.tar.gz -> k3s-cni-plugins-${K3S_CNIPLUGINS_VERSION}.tar.gz
      amd64? ( https://github.com/rancher/k3s-root/releases/download/v${K3S_ROOT_VERSION}/k3s-root-amd64.tar -> k3s-root-amd64-${K3S_ROOT_VERSION}.tar )
      arm64? ( https://github.com/rancher/k3s-root/releases/download/v${K3S_ROOT_VERSION}/k3s-root-arm64.tar -> k3s-root-arm64-${K3S_ROOT_VERSION}.tar )"
     
  LICENSE="Apache-2.0"
  SLOT="0"
  KEYWORDS="~amd64"
  IUSE="+kubectl-symlink rootless"
  REQUIRED_USE="|| ( amd64 arm64 )"
  DEPEND="
      app-misc/yq
      net-firewall/conntrack-tools
      sys-fs/btrfs-progs
      rootless? ( app-containers/slirp4netns )
  "   
  RDEPEND="kubectl-symlink? ( !sys-cluster/kubectl )"
  RESTRICT+=" test"
 
  S=${WORKDIR}/${PN}-${MY_PV/+/-}-vendor
     
  src_unpack() {
      unpack ${P}-vendor.tar.gz
      cd "${S}" || die
      mkdir -p bin/aux build/static/charts cache etc || die
      cp "${DISTDIR}/traefik-${K3S_TRAEFIK_VERSION}.tgz" build/static/charts/traefik-${K3S_TRAEFIK_VERSION}${K3S_TRAEFIK_PACKAGE_VERSION}.tgz || die
      cp "${DISTDIR}/k3s-cni-plugins-${K3S_CNIPLUGINS_VERSION}.tar.gz" cache/ || die
  }
 
  src_prepare() {
      local filename pattern replacement
      default
 
      local CONTAINERD_DIR=build/src/github.com/containerd/containerd
      mkdir -p "${CONTAINERD_DIR}" || die
      tar -x --strip-components=1 -f "${DISTDIR}/k3s-containerd-${K3S_CONTAINERD_VERSION}.tar.gz" -C "${CONTAINERD_DIR}" || die
      if has_version -b ">=dev-lang/go-1.18"; then
          # https://bugs.gentoo.org/835601
          sed -i -e "/github.com\/containerd\/containerd => .\/.empty-mod/d" "${CONTAINERD_DIR}"/{go.mod,vendor/modules.txt} || die
      fi
 
      local RUNC_DIR=build/src/github.com/opencontainers/runc
      mkdir -p "${RUNC_DIR}" || die
      tar -x --strip-components=1 -f "${DISTDIR}/k3s-runc-${K3S_RUNC_VERSION}.tar.gz" -C "${RUNC_DIR}" || die
 
      # Disable download for files fetched via SRC_URI.
      sed -e 's:^[[:space:]]*curl:#\0:' \
          -e 's:^[[:space:]]*git:#\0:' \
          -e 's:^rm -rf \${CHARTS_DIR}:#\0:' \
          -e 's:^rm -rf \${RUNC_DIR}:#\0:' \
          -e 's:^rm -rf \${CONTAINERD_DIR}:#\0:' \
          -e 's:yq e :yq -r :' \
          -e "s:^setup_tmp\$:TMP_DIR=${S}/build/static/charts:" \
          -i scripts/download || die
      sed -e '/scripts\/build-upload/d' -i scripts/package-cli || die
      pattern='git clone -b $VERSION_CNIPLUGINS https://github.com/rancher/plugins.git $WORKDIR'
      filename=scripts/build
      grep -qF "${pattern}" "${filename}" || \
          die "failed to locate plugins clone command"
      sed -e "s|${pattern}|mkdir -p \"\$WORKDIR\" \\&\\& tar -xzf \"${S}/cache/k3s-cni-plugins-${K3S_CNIPLUGINS_VERSION}.tar.gz\" --strip-components=1 -C \"\$WORKDIR\  "|" \
          -e 's|rm -rf $TMPDIR||' \
          -i "${filename}" || die
      sed -e 's:/usr/local/bin:/usr/bin:g' -i k3s.service || die
  }
 
  src_compile() {
      mkdir -p build/data || die
      "${BASH}" -ex ./scripts/download || die
      ./scripts/build || die
      ./scripts/package-cli || die
  }
 
  src_install() {
      dobin "dist/artifacts/${PN}-${ARCH}"
      newbin "${FILESDIR}/k3s-killall.sh" k3s-killall
      use kubectl-symlink && dosym k3s /usr/bin/kubectl
      systemd_dounit "${FILESDIR}/${PN}.service"
      newinitd "${FILESDIR}/${PN}.initd" "${PN}"
      newconfd "${FILESDIR}/${PN}.confd" "${PN}"
      insinto /etc/logrotate.d
      newins "${FILESDIR}/${PN}.logrotated" "${PN}"
      dodoc README.md
  }


The problem I have with this now is in src_install.
Turns out k3s-killall.sh (and other scripts ebuild looks for in $FILESDIR) are not installed to the $FILESDIR (/var/tmp/portage/portage/sys-cluster/k3s-1.25.4_p1/files/) directory but to /usr/portage/sys-cluster/k3s/files/

Should I point ebuild to /usr/portage or try and make it copy to $FILESDIR in the first place? If so, how?

I'm sure there are more issues with this ebuild I can't see yet, please tell.
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1777
Location: South America

PostPosted: Fri Dec 20, 2024 12:54 pm    Post subject: Re: Struggling to fix k3s ebuild Reply with quote

erg_samowzbudnik wrote:
The problem I have with this now is in src_install.
Turns out k3s-killall.sh (and other scripts ebuild looks for in $FILESDIR) are not installed to the $FILESDIR (/var/tmp/portage/portage/sys-cluster/k3s-1.25.4_p1/files/) directory but to /usr/portage/sys-cluster/k3s/files/

I don't understand. For example, if you say this in the ebuild:

erg_samowzbudnik wrote:
Code:
newbin "${FILESDIR}/k3s-killall.sh" k3s-killal


you are providing k3s-killall.sh in $FILESDIR, and want it installed in /usr/bin (by default) with the name k3s-killall. Is this not what happens?
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1960

PostPosted: Fri Dec 20, 2024 1:27 pm    Post subject: Reply with quote

If you make a new repository for an ebuild from an existing Gentoo ebuild, you must copy (or otherwise provide) all the relevant items from under the Gentoo repos files directory where the original repository resides to the new location's files directory.

$FILESDIR refers to that "files" directory from wherever the running ebuild is read from. The portage setup process ensures the ebuild has the access it needs to it.
Back to top
View user's profile Send private message
erg_samowzbudnik
Apprentice
Apprentice


Joined: 09 Sep 2011
Posts: 229
Location: European sticks

PostPosted: Fri Dec 20, 2024 3:49 pm    Post subject: Reply with quote

grknight: this

So turns out this ebuild does work. I managed to install k3s with it.

With caveats:

1.) Binary is now k3s-arm64 witch makes service crash on start. Manually changing binary name in /etc/init.d/k3s fixes that, suppose I could create a symlink, but those are not ideal solutions.
2.) I was expecting something like /etc/k3s/k3s.yaml - but it's not there. Not a big one problem

I wonder if those versions of components are ok though. I just pulled them off the go.mod package from k3s repo. This did not contain `traefik` and `cniplugins` so I left them as they were.
I don't consider this OK - but have trouble finding them so far.
Back to top
View user's profile Send private message
erg_samowzbudnik
Apprentice
Apprentice


Joined: 09 Sep 2011
Posts: 229
Location: European sticks

PostPosted: Mon Dec 23, 2024 8:43 am    Post subject: Reply with quote

In an attempt to fix the naming issue of the resulting binary I have changed src_install:

Code:

<       newbin "dist/artifacts/${PN}-${ARCH}" ${PN}
---
>       dobin "dist/artifacts/${PN}"


This works fine for arm64 (I suppose it should work like so for other 'alternative' arches as well) but fails for amd64: this binary does not have it's architecture as a suffix.
Guess I'll need an `if` statement somewhere?
Or rather remove architecture suffix from the binary name?
Back to top
View user's profile Send private message
erg_samowzbudnik
Apprentice
Apprentice


Joined: 09 Sep 2011
Posts: 229
Location: European sticks

PostPosted: Mon Dec 23, 2024 10:30 am    Post subject: Reply with quote

Would such a solution be acceptable in an official ebuild?

Code:

src_install() {
    if [ ${ARCH} = 'amd64' ]; then
        dobin "dist/artifacts/${PN}"
    else
        newbin "dist/artifacts/${PN}-${ARCH}" ${PN}
    fi
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22866

PostPosted: Mon Dec 23, 2024 1:32 pm    Post subject: Reply with quote

I cannot speak to whether the Gentoo maintainers would accept that specific construct, but I will say that there is plenty of precedent for an ebuild that inspects the target architecture and varies its behavior accordingly. I think I saw architecture-testing written as if use amd64; then ..., rather than if [ ${ARCH} = 'amd64' ]; then ....
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum