Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

[project/schemas]: go types contains conflicting code if two xrd's in same api-group has integer enum field

Ouverte
#444 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 7 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
72/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
go
Domaine
build-system

Piste de recherche

Start by tracing Go schema generation from crossplane project build and inspect the generated enum constants in the same API package, using the Subnet and VirtualNetwork examples in the issue to reproduce the collision. Add a regression case with two XRDs that define the same integer enum, then confirm the generated package compiles and its enum constants remain usable.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug
What happened?

The generated go schemas from `crossplane project build`` seems to be conflicting when two XRDs in the same API group and version contain integer enums.

Example:

Both resources (Subnet and VirtualNetwork in example.io/v1alpha1) define a spec.size integer enum with the values 8, 16, 32, 64, 128, 256, 512.

The generated models will declare the same package-level constant name for both enum types:

// Subnet model
const (
    Empty SubnetSpecSize = 8
)

// VirtualNetwork model
const (
    Empty VirtualNetworkSpecSize = 8
)

These declarations collide and the embedded functions that imports a type from this api group will fail:

crossplane: error: failed to build function "firewall": failed to build runtime images: failed to build function: build: go build: exit status 1: # dev.crossplane.io/models/io/example/azure/v1alpha1
../../schemas/go/io/example/azure/v1alpha1/virtualnetwork.go:109:2: Empty redeclared in this block
    ../../schemas/go/io/example/azure/v1alpha1/subnet.go:91:2: other declaration of Empty
../../schemas/go/io/example/azure/v1alpha1/virtualnetwork.go:115:7: invalid case Empty in switch on e (mismatched types SubnetSpecSize and VirtualNetworkSpecSize)

Expected behavior: Go model generation should generate unique constant names so resources in the same package compile successfully.

How can we reproduce it?

Use a Crossplane project with Go schema generation enabled (spec.schemas.languages: ["go"]) and an embedded Go function that imports the generated API package.

Create apis/subnets/definition.yaml:

---
apiVersion: apiextensions.crossplane.io/v2
kind: CompositeResourceDefinition
metadata:
  name: subnets.example.io
spec:
  scope: Namespaced
  group: example.io
  names:
    kind: Subnet
    plural: subnets
  versions:
    - name: v1alpha1
      served: true
      referenceable: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                size:
                  type: integer
                  enum: [8, 16, 32, 64, 128, 256, 512]

Create apis/virtualnetworks/definition.yaml:

---
apiVersion: apiextensions.crossplane.io/v2
kind: CompositeResourceDefinition
metadata:
  name: virtualnetworks.example.io
spec:
  scope: Namespaced
  group: example.io
  names:
    kind: VirtualNetwork
    plural: virtualnetworks
  versions:
    - name: v1alpha1
      served: true
      referenceable: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                size:
                  type: integer
                  enum: [8, 16, 32, 64, 128, 256, 512]

Run crossplane project build.

Observe the duplicate Empty constants and resulting Go compilation errors.

What environment did it happen in?

Crossplane CLI version: v2.5.0
Platform: linux/amd64
Crossplane version: v2.4.2 (the failure occurs locally during the CLI build)

Langage dominant
Go
Étoiles
22
Forks
37
Merge moyen
6 j 8 h
PR mergées (30 j)
22

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de crossplane/cli

Toutes les issues de crossplane/cli

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.