[project/schemas]: go types contains conflicting code if two xrd's in same api-group has integer enum field
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
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
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di crossplane/cli
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
crossplane/cli#445 ·
I maintainer di solito rispondono entro 7 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
crossplane/cli#432 ·
I maintainer di solito rispondono entro 7 giorni
-
`credsStore` in docker config causes unit test failuresForse già presa @sujeito-operator l’ha presa 65 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
crossplane/cli#282 ·
I maintainer di solito rispondono entro 7 giorni
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
crossplane/cli#437 ·
I maintainer di solito rispondono entro 7 giorni
-
Generated schemas go stale because each source writes into the shared tree on its ownForse già presa @stevendborrelli l’ha presa 8 giorni fa. Apertaenhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 18/100
crossplane/cli#428 ·
I maintainer di solito rispondono entro 7 giorni
Tutte le issue di crossplane/cli
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
FiloSottile/age#758 ·
-
nginx configAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
I maintainer di solito rispondono entro 1 giorno