Skip to content

Fix cross-compilation issue with cgroups package for Darwin builds#1

Open
heyingyue wants to merge 2 commits intomasterfrom
fix/cross-compilation-cgroups-issue
Open

Fix cross-compilation issue with cgroups package for Darwin builds#1
heyingyue wants to merge 2 commits intomasterfrom
fix/cross-compilation-cgroups-issue

Conversation

@heyingyue
Copy link
Copy Markdown

@heyingyue heyingyue commented Jun 26, 2025

Problem

The make release flow was failing when cross-compiling for Darwin (macOS) platforms due to the github.com/containerd/cgroups/v3 package containing Linux-specific code that references unix.CGROUP2_SUPER_MAGIC constants not available on Darwin.

Error encountered:

# github.com/containerd/cgroups/v3
/go/pkg/mod/github.com/containerd/cgroups/v3@v3.0.5/utils.go:62:13: undefined: unix.CGROUP2_SUPER_MAGIC
/go/pkg/mod/github.com/containerd/cgroups/v3@v3.0.5/utils.go:69:23: undefined: unix.CGROUP2_SUPER_MAGIC

Additional QingStor Issue:
The release workflow also had an issue with QingStor upload failing due to missing access credentials:

access key not provided

Solution

Implemented platform-specific code using Go build tags to handle cgroups functionality:

Changes Made:

  1. Split cgroups functionality into platform-specific files:

    • cmd/kk/pkg/bootstrap/os/cgroups_linux.go - Linux-specific cgroups operations
    • cmd/kk/pkg/bootstrap/os/cgroups_other.go - Non-Linux platforms (stub implementation)
  2. Used build tags for conditional compilation:

    • //go:build linux for Linux-specific code
    • //go:build !linux for non-Linux platforms
  3. Refactored cgroups usage:

    • Replaced direct cgroups.Mode() calls with shouldUnmountCalicoGroup() function
    • Maintained exact same behavior on Linux systems
    • Returns false on non-Linux systems (appropriate since cgroups are Linux-specific)
  4. Added comprehensive test coverage:

    • Unit test to verify platform-specific behavior
    • Ensures function doesn't panic on any platform
  5. QingStor Setup Documentation:

    • Added docs/qingstor-setup.md with complete setup instructions
    • Explains how to configure GitHub Secrets for QingStor access
    • Provides troubleshooting guide

Testing

All platforms now compile successfully:

  • Linux amd64
  • Linux arm64
  • Darwin amd64
  • Darwin arm64

Complete release flow verified:

  • make release-binaries works for all platforms
  • make release completes successfully
  • Generated binaries are functional

Backward compatibility maintained:

  • No behavior changes on Linux systems
  • Existing functionality preserved

QingStor Configuration

To fix the QingStor upload issue, repository maintainers need to add these GitHub Secrets:

  • KS_QSCTL_ACCESS_KEY_ID - QingStor access key ID
  • KS_QSCTL_SECRET_ACCESS_KEY - QingStor secret access key

Detailed 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.yaml to 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:

  • Cross-platform compatibility - Builds work on all target platforms
  • Maintainability - Platform-specific logic is clearly separated
  • Performance - No runtime overhead for platform detection
  • Safety - Compile-time guarantees that appropriate code is used

Files Changed

  • cmd/kk/pkg/bootstrap/os/tasks.go - Refactored to use new abstraction
  • cmd/kk/pkg/bootstrap/os/cgroups_linux.go - Linux-specific implementation
  • cmd/kk/pkg/bootstrap/os/cgroups_other.go - Non-Linux stub implementation
  • cmd/kk/pkg/bootstrap/os/cgroups_test.go - Test coverage
  • docs/qingstor-setup.md - QingStor configuration guide

Fixes the cross-compilation build failures and enables successful release builds for all supported platforms. Also provides solution for QingStor upload configuration.

- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant