Fix cross-compilation issue with cgroups package for Darwin builds#1
Open
Fix cross-compilation issue with cgroups package for Darwin builds#1
Conversation
- Split cgroups functionality into platform-specific files using build tags - Create cgroups_linux.go for Linux-specific cgroups operations - Create cgroups_other.go for non-Linux platforms (returns false) - Replace direct cgroups.Mode() calls with shouldUnmountCalicoGroup() function - This fixes the 'undefined: unix.CGROUP2_SUPER_MAGIC' error when cross-compiling for Darwin
- Add unit test to verify shouldUnmountCalicoGroup() behavior - Test ensures function returns false on non-Linux platforms - Test verifies function doesn't panic on any platform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
make releaseflow was failing when cross-compiling for Darwin (macOS) platforms due to thegithub.com/containerd/cgroups/v3package containing Linux-specific code that referencesunix.CGROUP2_SUPER_MAGICconstants not available on Darwin.Error encountered:
Additional QingStor Issue:
The release workflow also had an issue with QingStor upload failing due to missing access credentials:
Solution
Implemented platform-specific code using Go build tags to handle cgroups functionality:
Changes Made:
Split cgroups functionality into platform-specific files:
cmd/kk/pkg/bootstrap/os/cgroups_linux.go- Linux-specific cgroups operationscmd/kk/pkg/bootstrap/os/cgroups_other.go- Non-Linux platforms (stub implementation)Used build tags for conditional compilation:
//go:build linuxfor Linux-specific code//go:build !linuxfor non-Linux platformsRefactored cgroups usage:
cgroups.Mode()calls withshouldUnmountCalicoGroup()functionfalseon non-Linux systems (appropriate since cgroups are Linux-specific)Added comprehensive test coverage:
QingStor Setup Documentation:
docs/qingstor-setup.mdwith complete setup instructionsTesting
✅ All platforms now compile successfully:
✅ Complete release flow verified:
make release-binariesworks for all platformsmake releasecompletes successfully✅ Backward compatibility maintained:
QingStor Configuration
To fix the QingStor upload issue, repository maintainers need to add these GitHub Secrets:
KS_QSCTL_ACCESS_KEY_ID- QingStor access key IDKS_QSCTL_SECRET_ACCESS_KEY- QingStor secret access keyDetailed setup instructions are provided in
docs/qingstor-setup.md.Note: Due to GitHub permissions, the workflow file changes couldn't be pushed directly. The QingStor fix involves adding proper error handling to
.github/workflows/release.yamlto gracefully handle missing credentials and provide helpful setup instructions.Technical Details
This fix uses Go's build tags feature, which is the standard approach for handling platform-specific code. The solution ensures:
Files Changed
cmd/kk/pkg/bootstrap/os/tasks.go- Refactored to use new abstractioncmd/kk/pkg/bootstrap/os/cgroups_linux.go- Linux-specific implementationcmd/kk/pkg/bootstrap/os/cgroups_other.go- Non-Linux stub implementationcmd/kk/pkg/bootstrap/os/cgroups_test.go- Test coveragedocs/qingstor-setup.md- QingStor configuration guideFixes the cross-compilation build failures and enables successful release builds for all supported platforms. Also provides solution for QingStor upload configuration.