-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(image-cri-shim): add registry priority support for intelligent image matching #6515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
…mage matching (#6503) * feat(image-cri-shim): add registry priority support for intelligent image matching Implemented priority-based registry selection to optimize image pull performance by prioritizing faster registries like sealos.hub while supporting custom priority configuration for user-defined registries. ## Key Features - **Priority System**: - sealos.hub defaults to highest priority (1000) - User registries default to priority 500 - Configurable priority range: 0-1000 - Auto-clamping for out-of-range values - **Smart Matching**: - Checks registries in priority order (highest first) - Tries sealos.hub first, then user registries by priority - Caches match results to avoid redundant manifest checks - Falls back to original image if no registry has it - **Backward Compatible**: - Existing configs work without modification - Priority field is optional - Default values ensure reasonable behavior ## Changes ### Configuration (pkg/types/config.go) - Added Priority field to Registry struct - Added priority constants (SealosHubDefaultPriority=1000, RegistryDefaultPriority=500) - Extended ShimAuthConfig with CRIPriorities and OfflinePriority - Auto-clamping and default value assignment in PreProcess() ### Auth Store (pkg/server/auth_store.go) - Added GetSortedRegistries() for priority-based ordering - Added GetCRIPriorities() and GetOfflinePriority() accessors - Introduced RegistryEntry type for registry metadata - Implemented sortRegistriesByPriority() with tie-breaking rules ### Image Matching (pkg/server/utils.go) - Added RegistryWithPriority type - Implemented ReplaceImageWithPriority() for sequential registry attempts - Enhanced logging for priority-based matching ### CRI Service (pkg/server/cri_server_v1.go) - Refactored rewriteImage() to use priority-based selection - Simplified PullImage() by removing complex fallback logic - Added domain miss tracking for cache statistics ### Testing (pkg/server/priority_test.go) - Comprehensive tests for priority sorting and ordering - Config processing tests with boundary value validation - 100% coverage of new functionality ### Documentation - Updated README.md with priority configuration guide - Added priority-example.yaml with detailed examples - Documented priority rules, behavior, and use cases ## Example Configuration ```yaml address: http://sealos.hub:5000 auth: admin:passw0rd registries: - address: docker.io auth: user:pass # priority: 500 (default) - address: registry.example.com auth: user:pass priority: 800 # higher than docker.io ``` ## Testing All tests pass including: - Priority ordering and sorting - Config parsing with boundary values - Cache statistics tracking - Backward compatibility with existing tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * feat(image-cri-shim): add customizable offlinePriority for sealos.hub Added support for customizing sealos.hub priority through the optional `offlinePriority` configuration field while maintaining full backward compatibility with existing configurations. ## Key Features - **Optional Configuration**: New `offlinePriority` field in Config struct - **Smart Defaults**: - Unconfigured or set to 0: uses default 1000 (highest priority) - Allows lowering sealos.hub priority to favor other registries - **Boundary Safety**: Auto-clamps to [0, 10000] range with warnings - **Fully Backward Compatible**: Existing configs work unchanged ## Use Cases 1. **Default Behavior** (backward compatible): - sealos.hub priority = 1000 (highest) - Tried before all user registries 2. **Custom Lower Priority**: - Set `offlinePriority: 700` to try fast-registry (900) first - Useful when external registries are faster than sealos.hub 3. **Flexible Control**: - Fine-tune registry selection order per deployment - Adapt to different network environments ## Changes ### Configuration (pkg/types/config.go) - Added `OfflinePriority int` field to Config struct - Extended PreProcess() to handle custom offlinePriority: - 0 or unset: use SealosHubDefaultPriority (1000) - < 0: clamp to MinPriority (0) with warning - > 10000: clamp to MaxPriority (10000) with warning ### Testing (pkg/server/priority_test.go) - Added TestOfflinePriorityConfig: - Tests default, custom, and boundary values - Validates clamping behavior - Added TestOfflinePriorityWithRegistries: - Tests sealos.hub priority relative to other registries - Verifies correct sorting order ### Documentation - Updated README.md with offlinePriority field documentation - Added examples showing how to customize sealos.hub priority - Documented backward compatibility guarantees - Updated priority-example.yaml with offlinePriority usage ## Example Configuration ```yaml address: http://sealos.hub:5000 auth: admin:passw0rd # Lower sealos.hub priority to try other registries first offlinePriority: 700 registries: - address: fast-registry.io auth: user:pass priority: 900 # Will be tried before sealos.hub ``` ## Testing All tests pass including: - Default offlinePriority behavior - Custom priority configuration - Boundary value handling - Priority ordering with multiple registries - Backward compatibility (existing tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * feat(image-cri-shim): add ConfigMap priority sync support and comprehensive documentation Enable ConfigMap to fully support priority field synchronization for registries. ### Code Changes 1. **pkg/types/configmap_sync.go**: Add priority sync from ConfigMap - Extend registryEntry struct with Priority field - Extend registryConfigSpec struct with OfflinePriority field - Update mergeShimConfig() to sync priority values - Add detailed logging for debugging sync process 2. **pkg/types/configmap_sync_test.go**: Add comprehensive tests - TestConfigMapPrioritySync: Verify priority and offlinePriority sync - Test edge cases (zero priority, custom priorities) - All tests passing 3. **pkg/server/cri_server_v1.go**: Add priority-aware logging - Log sorted registry list with priorities - Show priority order before image pull - Indicate offline registry in logs 4. **pkg/server/utils.go**: Enhance priority matching logs - Log each registry attempt with priority - Show success/failure status for each attempt - Display final image rewrite result ### Documentation 5. **CONFIGMAP_GUIDE.md**: Comprehensive ConfigMap guide (550+ lines) - Feature overview and core capabilities - Complete ConfigMap configuration specification - Field-by-field documentation - Usage scenarios and examples - Troubleshooting guide - Best practices - Updated to reflect priority support ### Features ✅ ConfigMap fully supports priority field for registries ✅ ConfigMap fully supports offlinePriority for sealos.hub ✅ Detailed debug logging for troubleshooting ✅ Comprehensive documentation with examples ✅ All tests passing ### Technical Details - Priority values are synced as-is from ConfigMap (including 0) - Priority boundary validation (0-10000) happens in PreProcess - ConfigMap registries completely replace local config (existing behavior) - YAML serialization correctly includes priority fields - Debug logs help verify sync process and priority order 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * add license --------- Co-authored-by: Claude <[email protected]>
Whoa! Easy there, Partner!This PR is too big. Please break it up into smaller PRs. |
cuisongliu
approved these changes
Jan 12, 2026
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.
fix(cherry-pick): Automated CherryPick 6503 for release-v5.1
Automated changes by create-pull-request GitHub action