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

Endless recursion when running make generate for recursive types #47

Open
jake-volvo opened this issue Oct 12, 2022 · 0 comments · May be fixed by #48
Open

Endless recursion when running make generate for recursive types #47

jake-volvo opened this issue Oct 12, 2022 · 0 comments · May be fixed by #48
Labels
bug Something isn't working

Comments

@jake-volvo
Copy link

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 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

@jake-volvo jake-volvo added the bug Something isn't working label Oct 12, 2022
jake-volvo pushed a commit to jake-volvo/crossplane-tools that referenced this issue Oct 12, 2022
Simply keep a slice of already visited types and exit early.

Fixes crossplane#47

Signed-off-by: jakub@ciolek.dev
jake-volvo pushed a commit to jake-volvo/crossplane-tools that referenced this issue Oct 12, 2022
Simply keep a slice of already visited types and exit early.

Fixes crossplane#47

Signed-off-by: Jakub Ciolek <jakub@ciolek.dev>
jake-volvo pushed a commit to jake-volvo/crossplane-tools that referenced this issue Oct 12, 2022
Simply keep a slice of already visited types and exit early.

Fixes crossplane#47

Signed-off-by: Jakub Ciolek <jakub@ciolek.dev>
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

Successfully merging a pull request may close this issue.

1 participant