Skip to content

Commit

Permalink
Look for fallback OS support through ID_LIKE field (#584)
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke authored Oct 24, 2023
1 parent 5d4b8ee commit df2bb0e
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,35 @@ jobs:
LINUX_IMAGE: ${{ matrix.image }}
run: make smoke-basic

smoke-basic-idlike:
name: Basic 1+1 smoke (ID_LIKE fallback)
needs: build
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true

- {"name":"Go modules cache","uses":"actions/cache@v3","with":{"path":"~/go/pkg/mod\n~/.cache/go-build\n~/Library/Caches/go-build\n%LocalAppData%\\go-build\n","key":"${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}","restore-keys":"${{ runner.os }}-go-\n"}}
- {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}}
- {"name":"Make executable","run":"chmod +x k0sctl"}
- {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl\n~/.cache/k0sctl\n!*.log\n","key":"k0sctl-cache"}}
- {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-1.21.3"}}
- {"name":"Go modules cache","uses":"actions/cache@v3","with":{"path":"~/go/pkg/mod\n~/.cache/go-build\n~/Library/Caches/go-build\n%LocalAppData%\\go-build\n","key":"${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}","restore-keys":"${{ runner.os }}-go-\n"}}
- {"name":"Docker Layer Caching For Bootloose","uses":"satackey/[email protected]","continue-on-error":true}

- name: Build image
run: |
make -C smoke-test kalilinux.iid
echo "LINUX_IMAGE=$(cat smoke-test/kalilinux.iid)" >> "$GITHUB_ENV"
- name: Run smoke tests
run: make smoke-basic

smoke-basic-openssh:
strategy:
matrix:
Expand Down
12 changes: 12 additions & 0 deletions phase/detect_os.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package phase

import (
"strings"

"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"

// anonymous import is needed to load the os configurers
Expand Down Expand Up @@ -31,6 +33,16 @@ func (p *DetectOS) Run() error {
}
if err := h.ResolveConfigurer(); err != nil {
p.SetProp("missing-support", h.OSVersion.String())
if h.OSVersion.IDLike != "" {
log.Debugf("%s: trying to find a fallback OS support module for %s using os-release ID_LIKE '%s'", h, h.OSVersion.String(), h.OSVersion.IDLike)
for _, id := range strings.Split(h.OSVersion.IDLike, " ") {
h.OSVersion.ID = id
if err := h.ResolveConfigurer(); err == nil {
log.Warnf("%s: using '%s' as OS support fallback for %s", h, id, h.OSVersion.String())
return nil
}
}
}
return err
}
os := h.OSVersion.String()
Expand Down
5 changes: 3 additions & 2 deletions smoke-test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
footloose.yaml
bootloose.yaml
id_rsa*
k0sctl_040
*.tar.gz
*.tar.gz
*.iid
47 changes: 47 additions & 0 deletions smoke-test/Dockerfile.kalilinux
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM kalilinux/kali-rolling:latest

ENV container docker

# Don't start any optional services except for the few we need.
RUN find /etc/systemd/system \
/lib/systemd/system \
-path '*.wants/*' \
-not -name '*journald*' \
-not -name '*systemd-tmpfiles*' \
-not -name '*systemd-user-sessions*' \
-exec rm \{} \;

RUN apt-get update && \
apt-get install -y \
dbus systemd openssh-server net-tools iproute2 iputils-ping curl wget vim-tiny sudo && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Truncate machine ID files to trigger regeneration.
RUN >/etc/machine-id
RUN >/var/lib/dbus/machine-id

EXPOSE 22

RUN systemctl set-default multi-user.target
RUN systemctl mask \
dev-hugepages.mount \
sys-fs-fuse-connections.mount \
systemd-update-utmp.service \
systemd-tmpfiles-setup.service \
console-getty.service

# This container image doesn't have locales installed. Disable forwarding the
# user locale env variables or we get warnings such as:
# bash: warning: setlocale: LC_ALL: cannot change locale
RUN sed -i -e 's/^AcceptEnv LANG LC_\*$/#AcceptEnv LANG LC_*/' /etc/ssh/sshd_config
RUN systemctl enable ssh

# This may be needed for some systemd services to start properly.
RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d

# https://www.freedesktop.org/wiki/Software/systemd/ContainerInterface/
STOPSIGNAL SIGRTMIN+3

CMD ["/bin/bash"]

2 changes: 2 additions & 0 deletions smoke-test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ smoke-os-override: $(bootloose) id_rsa_k0s k0sctl
smoke-backup-restore: $(bootloose) id_rsa_k0s k0sctl
./smoke-backup-restore.sh

%.iid: Dockerfile.%
docker build --iidfile '$@' - < '$<'

0 comments on commit df2bb0e

Please sign in to comment.