Skip to content

Conversation

@kimpenhaus
Copy link
Collaborator

Description

This PR enhances the source generator to discover and process Kubernetes entities that are defined in referenced assemblies.

Previously, the generator primarily focused on entities defined within the current project. With these changes, the KubernetesEntitySyntaxReceiver now also inspects controllers and finalizers to identify entities they use, even if those entities reside in external libraries.

Additionally, the test suite has been upgraded to xUnit v3 to take advantage of the latest testing features and improvements.

Key Changes

  • Entity Discovery: Updated KubernetesEntitySyntaxReceiver to find entities referenced in IEntityController and IEntityFinalizer implementations from external assemblies.
  • Improved Metadata Handling: Introduced ClassDeclarationMetaData to decouple the generator logic from specific SyntaxNode types, allowing it to handle both source-defined and binary-referenced types uniformly.
  • Generator Updates:
    • EntityInitializerGenerator now correctly generates Initialize() extension methods for entities coming from referenced assemblies.
    • EntityDefinitionGenerator, ControllerRegistrationGenerator, and FinalizerRegistrationGenerator have been updated to support these externally defined entities.
  • xUnit Upgrade: Upgraded the test projects from xUnit v2 to xUnit v3 (v3.2.1) and updated related dependencies and test implementations (e.g., using ValueTask for async disposal).
  • Refactoring: Standardized how entity attributes (Kind, Group, Version, Plural) are extracted from both AttributeSyntax (source) and AttributeData (symbols).
  • Testing: Added comprehensive integration and unit tests covering:
    • Entities from referenced assemblies in namespaces.
    • Entities from referenced assemblies in the global namespace.
    • Entities from referenced assemblies with constant values in attributes.
    • Correct registration of controllers and finalizers using these entities.

Motivation

This allows developers to share common Kubernetes entity definitions across multiple operator projects via NuGet packages or project references without losing the benefits of automated code generation for initializers and registrations.

@kimpenhaus kimpenhaus requested a review from buehler December 22, 2025 11:39
- Prefixed namespaces with "kubeops-" to standardize naming in `IntegrationTestCollection`.
- Changed `MlcProvider` and `InvocationCounter<TEntity>` to `sealed` for better performance and intentionality.
- Updated requeue delay in test logic from 1 second to 5 seconds for better clarity.
- Simplified `DeletedAsync` method syntax.
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