Skip to content
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

[bug]: Source generator fires for unit tests as well as operator #698

Open
robertcoltheart opened this issue Jan 17, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@robertcoltheart
Copy link
Contributor

Describe the bug

When the operator is using the source generator package, an unit test project that references the operator project shows this compile error:

error CS0121: The call is ambiguous between the following methods or properties: 'ControllerRegistrations.RegisterControllers(KubeOps.Abstractions.Builder.IOperatorBuilder)' and 'ControllerRegistrations.RegisterControllers(KubeOps.Abstractions.Builder.IOperatorBuilder)'

To reproduce

  1. Create an example operator, using the KubeOps.Generator library
  2. Create a unit test project that references the operator project
  3. Build the solution

Expected behavior

No response

Screenshots

No response

Additional Context

No response

@robertcoltheart robertcoltheart added the bug Something isn't working label Jan 17, 2024
@oionut
Copy link

oionut commented Jan 25, 2024

This has a wider impact as it is blocking moving the entity classes in a different assembly than the controller one. This means that the library is enforcing having everything in a single project making the life harder in case of a complex operator.

A potential solution would be to skip generating the OperatorBuilderExtensions, FinalizerRegistrations and ControllerRegistrations in case no IEntityController is found in the current assembly

@robertcoltheart in case your problem is only with the Test project(s), one workaround is adding the below code in (each of) your test project:

<Target Name="DisableAnalyzers" BeforeTargets="CoreCompile">
    <ItemGroup>	    
	    <Analyzer Remove="@(Analyzer)" Condition="'%(Filename)' == 'KubeOps.Generator'"/>
    </ItemGroup>
   </Target>

edited: added fix suggestion

@buehler
Copy link
Owner

buehler commented Jan 29, 2024

@oionut thanks for the workaround!

Is it not possible to use a library with your entities in one project and attach the generator there?

Maybe an idea would be to have some csproj properties to ignore or disable certain parts of the generator. Do you have any suggestions or best practices regarding source generators? It's the first I ever wrote ;-)

@oionut
Copy link

oionut commented Feb 6, 2024

Hi @buehler. Source generators are new to mee too, unfortunately I cannot suggest a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants