Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#444 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 7 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
build-system

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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)

Lingua principale
Go
Stelle
22
Fork
37
Merge medio
6g 8h
PR unite (30g)
22

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di crossplane/cli

Tutte le issue di crossplane/cli

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.