[project/schemas]: go types contains conflicting code if two xrd's in same api-group has integer enum field
Los mantenedores suelen responder en 7 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- go
- Área
- build-system
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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)
- Lenguaje dominante
- Go
- Estrellas
- 22
- Forks
- 37
- Merge medio
- 6 d 8 h
- PR fusionados (30 d)
- 22
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de crossplane/cli
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
crossplane/cli#445 ·
Los mantenedores suelen responder en 7 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
crossplane/cli#432 ·
Los mantenedores suelen responder en 7 días
-
`credsStore` in docker config causes unit test failuresPosiblemente ocupada @sujeito-operator la tomó hace 65 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
crossplane/cli#282 ·
Los mantenedores suelen responder en 7 días
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
crossplane/cli#437 ·
Los mantenedores suelen responder en 7 días
-
Generated schemas go stale because each source writes into the shared tree on its ownPosiblemente ocupada @stevendborrelli la tomó hace 8 días. Abiertoenhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 18/100
crossplane/cli#428 ·
Los mantenedores suelen responder en 7 días
Todos los issues de crossplane/cli
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
FiloSottile/age#758 ·
-
nginx configAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
Los mantenedores suelen responder en 1 día