Skip to content

feat(controllers): Enable multiple controllers with different label selectors for the same entity type #911

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

stevefan1999-personal
Copy link
Contributor

@stevefan1999-personal stevefan1999-personal commented Jul 2, 2025

Overview

This PR introduces support for registering multiple controllers for the same Kubernetes entity type, each with different label selectors. This enhancement allows operators to handle different subsets of resources using specialized controllers based on label-based filtering.

Fixes #909

Key Changes

🔧 Core Interface Updates

🏗️ Service Registration Improvements

  • Enhanced OperatorBuilder to properly register multiple label selectors as distinct services
  • Simplified controller registration by making the parameterless AddController<TImplementation, TEntity>() method delegate to the selector-aware version with DefaultEntityLabelSelector<TEntity>
  • Removed problematic open generic registration that prevented multiple selector registrations

🔍 Resource Watcher Enhancements

✅ Comprehensive Test Coverage

  • Added test cases in OperatorBuilder.Test.cs to verify multiple selector registration
  • Created TestLabelSelector2 to demonstrate multiple selector scenarios
  • Updated existing tests to reflect the new service registration patterns

Benefits

  1. Multi-tenant Support: Different controllers can handle resources based on tenant-specific labels
  2. Environment Separation: Separate controllers for dev/staging/prod resources within the same cluster
  3. Feature Flagging: Controllers can target resources with specific feature flags
  4. Performance Optimization: Specialized controllers can focus on specific resource subsets

Backward Compatibility

Fully backward compatible - existing code using single controllers continues to work without changes. The parameterless AddController<TImplementation, TEntity>() method automatically uses the default label selector.

Example Usage

// Register multiple controllers for the same entity type
builder.AddController<ProdController, MyEntity, ProdLabelSelector>();
builder.AddController<DevController, MyEntity, DevLabelSelector>();

This enhancement significantly improves the flexibility of the KubeOps operator framework while maintaining full backward compatibility with existing implementations.

@buehler
Copy link
Collaborator

buehler commented Jul 3, 2025

I like the idea :)
If it is backwards compatible, then even more.
Please also update the documentation according to the changes.

@buehler buehler changed the title Enable multiple controllers with different label selectors for the same entity type feat(controllers): Enable multiple controllers with different label selectors for the same entity type Jul 15, 2025
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.

[feature/bug]: Multiple entity controllers with different label selectors
2 participants