crossplane / crossplane/crossplane-tools

Endless recursion when running make generate for recursive types

Open
#47 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
37
Forks
38
PR merge metrics
No merged PRs in 30d

Description

### What happened?

I am working on an crossplane-runtime based Elasticsearch provider. One of the things I'd like to automate is the lifecycle of Ingest Pipelines. As you can see in the [docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/ingest.html) there is a recursive "on_failure" element to the API call.

An example of a real, even more nested ingest pipeline:

```
"processors": [
{
"rename": {
"description": "Rename 'provider' to 'my.field'",
"field": "field",
"target_field": "my.field",
"on_failure": [
{
"set": {
"description": "Set 'error.message'",
"field": "error.message",
"value": "Field 'field' does not exist. Cannot rename to 'my.field'",
"override": false,
"on_failure": [
{
"set": {
"description": "Set 'error.message.multi'",
"field": "error.message.multi",
"value": "Document encountered multiple ingest errors",
"override": true
}
}
]
}
}
]
}
}
]
```
### How can we reproduce it?

An example with some irrelevant fields omitted:

```
type OpensearchIndexPipelineSpec struct {
xpv1.ResourceSpec `json:",inline"`
Description string `json:"description"`
Version int64 `json:"version"`
Processors []*PipelineProcessorSpec `json:"processors"`
}

type PipelineProcessorSpec struct {
Set *SetProcessorSpec `json:"set,omitempty"`
Rename *RenameProcessorSpec `json:"rename,omitempty"`
}

type SetProcessorSpec struct {
Field string `json:"field,omitempty"`
Value string `json:"value,omitempty"`
Description string `json:"description,omitempty"`
Override bool `json:"override,omitempty"`
OnFailure []PipelineProcessorSpec `json:"on_failure,omitempty"`
}

type RenameProcessorSpec struct {
Field string `json:"field,omitempty"`
TargetField string `json:"target_field,omitempty"`
OnFailure []PipelineProcessorSpec `json:"on_failure,omitempty"`
}
```
run make generate

The generation will fail due to endless recursion in https://github.com/crossplane/crossplane-tools/blob/master/internal/types/types.go#L89

### What environment did it happen in?
crossplane-provider template tip

I have a patch ready and will send it shortly.

Cheers

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.