crd2pulumi icon indicating copy to clipboard operation
crd2pulumi copied to clipboard

Duplicate declarations in generated Go package

Open Amit-Biderman opened this issue 2 years ago • 2 comments

What happened?

Hello, I have a problem with crd2pulumi - I have generated from the following crd - https://github.com/argoproj/argo-rollouts/blob/master/manifests/crds/rollout-crd.yaml - a pulumi package using the above command, and I got errors in the pulumiTypes.go file! When I am running pulumi up, I get the following error message:

argoRollout/argoproj/v1alpha1/pulumiTypes.go:1842:6: RolloutSpecStrategyBluegreenPostpromotionanalysisArgs redeclared in this block argoRollout/argoproj/v1alpha1/pulumiTypes.go:1674:6: other declaration of RolloutSpecStrategyBluegreenPostpromotionanalysisArgs argoRollout/argoproj/v1alpha1/pulumiTypes.go:1917:98: v.Name undefined (type RolloutSpecStrategyBluegreenPostpromotionanalysisArgs has no field or method Name) argoRollout/argoproj/v1alpha1/pulumiTypes.go:1921:99: v.Value undefined (type RolloutSpecStrategyBluegreenPostpromotionanalysisArgs has no field or method Value) argoRollout/argoproj/v1alpha1/pulumiTypes.go:1926:12: v.ValueFrom undefined (type RolloutSpecStrategyBluegreenPostpromotionanalysisArgs has no field or method ValueFrom) argoRollout/argoproj/v1alpha1/pulumiTypes.go:2719:6: RolloutSpecStrategyBluegreenPrepromotionanalysisArgs redeclared in this block argoRollout/argoproj/v1alpha1/pulumiTypes.go:2551:6: other declaration of RolloutSpecStrategyBluegreenPrepromotionanalysisArgs argoRollout/argoproj/v1alpha1/pulumiTypes.go:2794:97: v.Name undefined (type RolloutSpecStrategyBluegreenPrepromotionanalysisArgs has no field or method Name) argoRollout/argoproj/v1alpha1/pulumiTypes.go:2798:98: v.Value undefined (type RolloutSpecStrategyBluegreenPrepromotionanalysisArgs has no field or method Value) argoRollout/argoproj/v1alpha1/pulumiTypes.go:4104:6: RolloutSpecStrategyCanaryAnalysisArgs redeclared in this block argoRollout/argoproj/v1alpha1/pulumiTypes.go:3926:6: other declaration of RolloutSpecStrategyCanaryAnalysisArgs argoRollout/argoproj/v1alpha1/pulumiTypes.go:5841:6: RolloutSpecStrategyCanaryStepsAnalysisArgs redeclared in this block argoRollout/argoproj/v1alpha1/pulumiTypes.go:5673:6: other declaration of RolloutSpecStrategyCanaryStepsAnalysisArgs argoRollout/argoproj/v1alpha1/pulumiTypes.go:6813:6: RolloutSpecStrategyCanaryStepsExperimentAnalysesArgs redeclared in this block argoRollout/argoproj/v1alpha1/pulumiTypes.go:6712:6: other declaration of RolloutSpecStrategyCanaryStepsExperimentAnalysesArgs argoRollout/argoproj/v1alpha1/pulumiTypes.go:2798:98: too many errors

I am taking from this that the crd2pulumi couldn’t create the package from the crd correctly.

Steps to reproduce

  1. Download the following crd - https://github.com/argoproj/argo-helm/blob/main/charts/argo-rollouts/templates/crds/rollout-crd.yaml
  2. Run the command: crd2pulumi --goName argoRollout --goPath ./argoRollout ./rollout-crd.yaml
  3. The generated package contains error in the pulumiTypes.go

Expected Behavior

The files generated are without duplicated declarations (specifically the pulumiTypes.go)

Actual Behavior

The files generated are with duplicated declarations (specifically the pulumiTypes.go)

Output of pulumi about

CLI Version 3.37.2 Go Version go1.18.4 Go Compiler gc

Plugins NAME VERSION aws 5.13.0 gcp 6.34.0 go unknown kubernetes 3.20.4 random 4.8.1

Host OS darwin Version 12.1 Arch arm64

This project is written in go: executable='/usr/local/go/bin/go' version='1.18.5 darwin/amd64'

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

Amit-Biderman avatar Nov 03 '22 13:11 Amit-Biderman

Thank you for taking time to provide a full explanation, it's appreciated. I agree this looks like an outright bug, rather than e.g., not handling a tricky input.

squaremo avatar Nov 07 '22 16:11 squaremo

Hey - still happening, can we please get an update on this issue? @squaremo

Amit-Biderman avatar Jun 27 '24 11:06 Amit-Biderman

Added to epic https://github.com/pulumi/home/issues/3431

cleverguy25 avatar Aug 09 '24 23:08 cleverguy25

A similar error occurs on https://raw.githubusercontent.com/cilium/tetragon/v1.2.0/install/kubernetes/tetragon/crds-yaml/cilium.io_tracingpolicies.yaml

in both cases, the problem is that the crd has a field named "args", which is a suffix pulumi uses when generating the input structs. Thus a crd with fields like:

...
kprobes:
  description: A list of kprobe specs.
  items:
    properties:
      args:
...

Tries to create:

type Kprobes struct {...} // Outer object type
type KprobesArgs struct {...} // Outer object's Input/Arguments type
type KprobesArgs struct {...} // Inner object type
type KprobesArgsArgs struct {...} // Inner object's Input/Arguments type

Which results in a collision

mjeffryes avatar Sep 06 '24 20:09 mjeffryes