From 9002770d8fff3f1b97aa065c02fd758438b8d4b3 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Fri, 20 Dec 2024 15:50:51 +0100 Subject: [PATCH 1/4] Compile UnmountLazy just for Linux MNT_DETACH is defined for Linux only, hence change the build tag from unix to linux and provide a fallback for everything non-Linux. Signed-off-by: Tom Wieczorek --- pkg/cleanup/{unmount_unix.go => unmount_linux.go} | 2 -- pkg/cleanup/{unmount_windows.go => unmount_other.go} | 12 +++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) rename pkg/cleanup/{unmount_unix.go => unmount_linux.go} (97%) rename pkg/cleanup/{unmount_windows.go => unmount_other.go} (78%) diff --git a/pkg/cleanup/unmount_unix.go b/pkg/cleanup/unmount_linux.go similarity index 97% rename from pkg/cleanup/unmount_unix.go rename to pkg/cleanup/unmount_linux.go index e02ab43996ac..01a617aa8a01 100644 --- a/pkg/cleanup/unmount_unix.go +++ b/pkg/cleanup/unmount_linux.go @@ -1,5 +1,3 @@ -//go:build unix - /* Copyright 2024 k0s authors diff --git a/pkg/cleanup/unmount_windows.go b/pkg/cleanup/unmount_other.go similarity index 78% rename from pkg/cleanup/unmount_windows.go rename to pkg/cleanup/unmount_other.go index 8e936605b7f2..217a4c2f64ae 100644 --- a/pkg/cleanup/unmount_windows.go +++ b/pkg/cleanup/unmount_other.go @@ -1,3 +1,5 @@ +//go:build !linux + /* Copyright 2024 k0s authors @@ -16,8 +18,12 @@ limitations under the License. package cleanup -import "fmt" +import ( + "errors" + "fmt" + "runtime" +) -func UnmountLazy(path string) error { - return fmt.Errorf("lazy unmount is not supported on Windows for path: %s", path) +func UnmountLazy(string) error { + return fmt.Errorf("%w on %s", errors.ErrUnsupported, runtime.GOOS) } From af834fccb652c39d4d8160f8ff58e28453855b94 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Fri, 20 Dec 2024 17:19:05 +0100 Subject: [PATCH 2/4] Provide winExecute fallback not only for Linux This is necessary to make it compile on macOS. Signed-off-by: Tom Wieczorek --- .../worker/containerd/{utils_linux.go => utils_other.go} | 2 ++ 1 file changed, 2 insertions(+) rename pkg/component/worker/containerd/{utils_linux.go => utils_other.go} (97%) diff --git a/pkg/component/worker/containerd/utils_linux.go b/pkg/component/worker/containerd/utils_other.go similarity index 97% rename from pkg/component/worker/containerd/utils_linux.go rename to pkg/component/worker/containerd/utils_other.go index cb8b89ad343d..9f7f5d609c81 100644 --- a/pkg/component/worker/containerd/utils_linux.go +++ b/pkg/component/worker/containerd/utils_other.go @@ -1,3 +1,5 @@ +//go:build !windows + /* Copyright 2023 k0s authors From 07c4324b57601885bc8bee1cfce75b048dece7ef Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Fri, 20 Dec 2024 17:59:03 +0100 Subject: [PATCH 3/4] Make unit tests pass on macOS Skip one test that times out for unknown reasons and needs further debugging. Signed-off-by: Tom Wieczorek --- pkg/constant/constant_test.go | 6 +++--- pkg/supervisor/supervisor_test.go | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/constant/constant_test.go b/pkg/constant/constant_test.go index 413a9c4db057..af0b3610e73c 100644 --- a/pkg/constant/constant_test.go +++ b/pkg/constant/constant_test.go @@ -145,11 +145,11 @@ func TestRuncModuleVersions(t *testing.T) { }, ) - if runtime.GOOS == "windows" { + if runtime.GOOS == "linux" { // The runc dependency is only a thing on Linux. - assert.Zero(t, numMatched, "Expected no packages to pass the filter on Windows.") - } else { assert.NotZero(t, numMatched, "Not a single package passed the filter.") + } else { + assert.Zero(t, numMatched, "Expected no packages to pass the filter on Windows.") } } diff --git a/pkg/supervisor/supervisor_test.go b/pkg/supervisor/supervisor_test.go index 14c757262533..7237d5606091 100644 --- a/pkg/supervisor/supervisor_test.go +++ b/pkg/supervisor/supervisor_test.go @@ -241,8 +241,11 @@ func TestMultiThread(t *testing.T) { } func TestCleanupPIDFile_Gracefully(t *testing.T) { - if runtime.GOOS == "windows" { + switch runtime.GOOS { + case "windows": t.Skip("PID file cleanup not yet implemented on Windows") + case "darwin": + t.Skip("FIXME: times out on macOS, needs debugging") } // Start some k0s-managed process. @@ -279,8 +282,11 @@ func TestCleanupPIDFile_Gracefully(t *testing.T) { } func TestCleanupPIDFile_Forcefully(t *testing.T) { - if runtime.GOOS == "windows" { + switch runtime.GOOS { + case "windows": t.Skip("PID file cleanup not yet implemented on Windows") + case "darwin": + t.Skip("FIXME: times out on macOS, needs debugging") } // Start some k0s-managed process that won't terminate gracefully. From 87a23ca3a57ca79c73f228a407539acaed9e5ba3 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Fri, 20 Dec 2024 18:12:56 +0100 Subject: [PATCH 4/4] Run unit tests on macOS in CI Combine the linux and windows unit test jobs into one matrix job and add a new matrix entry for macOS. Signed-off-by: Tom Wieczorek --- .github/workflows/go.yml | 103 ++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 55 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7f270e62c472..c43ab8fe57f6 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -116,90 +116,83 @@ jobs: name: spdx.json path: sbom/spdx.json - - unittests-k0s-linux-amd64: - name: "Unit tests :: linux-amd64" - runs-on: ubuntu-22.04 - - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Cache GOCACHE - uses: actions/cache@v4 - with: - key: unittests-k0s-linux-amd64-gocache-${{ github.ref_name }}-${{ github.sha }} - restore-keys: | - unittests-k0s-linux-amd64-gocache-${{ github.ref_name }}- - build-k0s-linux-amd64-gocache-${{ github.ref_name }}- - path: | - build/cache/go/build - - - name: Cache GOMODCACHE - uses: actions/cache@v4 - with: - key: unittests-k0s-linux-amd64-gomodcache-${{ hashFiles('go.sum') }} - restore-keys: | - build-k0s-linux-amd64-gomodcache-${{ hashFiles('go.sum') }} - path: | - build/cache/go/mod - - - name: Run unit tests - env: - EMBEDDED_BINS_BUILDMODE: none - run: make check-unit - - unittests-k0s-windows-amd64: - name: "Unit tests :: windows-amd64" - runs-on: windows-2022 + unittests-k0s: + strategy: + fail-fast: false + matrix: + include: + - name: linux-amd64 + runs-on: ubuntu-22.04 + - name: windows-amd64 + runs-on: windows-2022 + target-os: windows + - name: macos-arm64 + runs-on: macos-15 + target-os: darwin + + name: "Unit tests :: k0s :: ${{ matrix.name }}" + runs-on: "${{ matrix.runs-on }}" defaults: run: shell: bash + env: + EMBEDDED_BINS_BUILDMODE: none + steps: - - name: Check out + - name: Check out code into the Go module directory uses: actions/checkout@v4 with: persist-credentials: false + - name: Prepare unit tests + if: matrix.target-os != '' + run: | + cat <>"$GITHUB_ENV" + TARGET_OS=${{ matrix.target-os }} + GO=go + GO_ENV= + GOCACHE=$GITHUB_WORKSPACE/build/cache/go/build + GOMODCACHE=$GITHUB_WORKSPACE/build/cache/go/mod + UNITTEST_EXTRA_ARGS=BUILD_GO_LDFLAGS_EXTRA= + EOF + + echo ::group::Build Environment + cat -- "$GITHUB_ENV" + echo ::endgroup:: + + mkdir -p build/cache + make --touch .k0sbuild.docker-image.k0s + - name: Prepare build environment run: .github/workflows/prepare-build-env.sh - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 + if: matrix.target-os != '' with: go-version: ${{ env.GO_VERSION }} + cache: false - name: Cache GOCACHE uses: actions/cache@v4 with: - key: unittests-k0s-windows-amd64-gocache-${{ github.ref_name }}-${{ github.sha }} + key: unittests-k0s-${{ matrix.name }}-gocache-${{ github.ref_name }}-${{ github.sha }} restore-keys: | - unittests-k0s-windows-amd64-gocache-${{ github.ref_name }}- + unittests-k0s-${{ matrix.name }}-gocache-${{ github.ref_name }}- path: | - ~\AppData\Local\go-build + build/cache/go/build - name: Cache GOMODCACHE uses: actions/cache@v4 with: - key: unittests-k0s-windows-amd64-gomodcache-${{ hashFiles('go.sum') }} - restore-keys: | - build-k0s-windows-amd64-gomodcache-${{ hashFiles('go.sum') }} + key: unittests-k0s-gomodcache-${{ hashFiles('go.sum') }} path: | - ~\go\pkg\mod + build/cache/go/mod - name: Run unit tests - env: - EMBEDDED_BINS_BUILDMODE: none - TARGET_OS: windows - GO: go - GO_ENV: '' - run: | - make --touch .k0sbuild.docker-image.k0s - make check-unit + run: make check-unit $UNITTEST_EXTRA_ARGS smoketests: strategy: