Skip to content

Is it possible to inject new fields during code generation? #881

Closed
@ulucinar

Description

@ulucinar

Is your feature request related to a problem?
Similar to being able to ignore certain resources or field paths during code generation by specifying them under ignore.resource_names or ignore.field_paths in a generator_config.yaml file, is it/would it be possible to introduce new fields at specified paths with specified types & tags?

For example, while using the crossplane pipeline, we can have referencer fields that enable us to refer to another custom resource via a label selector or its name. The use case would be to introduce these extra "referencer" fields during code generation.

Describe the solution you'd like
To be able to define extra fields at specified paths with specified types (possibly a type unknown to the code-generator pipeline) and with specified tags.

Describe alternatives you've considered
One alternative might be to have the code-generator ignore the type/field which we need to expand and manually define those types/fields. But we would then not be utilizing the code generator. There are also other alternatives for the problem at hand in the crossplane context but it seems to be extending the code-generator with such functionality (if not already provided) will open up other possibilities.

For more context, the original context of the problem is a CloudFront Distribution can have multiple CacheBehaviors, each of which can refer to a (possibly distinct) CachePolicy. Now if we have a Distribution CR and multiple CachePolicy CRs to which we would like to refer to from the Distribution, I think it makes most sense to introduce the references fields (e.g., CachePolicy CR name and/or label selector) in the generated CacheBehavior struct. What I'm planning to implement for this PR at the moment is to introduce an index field that will point to the CacheBehavior object in the cacheBehaviors array for which a reference is being defined (assuming cachePolicyID is optional for a CacheBehavior).

Thank you very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/code-generationIssues or PRs as related to controllers or docs code generationarea/crossplaneIssues or PRs related to crossplanekind/enhancementCategorizes issue or PR as related to existing feature enhancements.lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions