-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kopium do not generate struct with nesting additionalProperties #202
Comments
These are the fields that do not generate: annotations:
additionalProperties:
additionalProperties:
type: string
type: object
nullable: true
type: object
x-kubernetes-preserve-unknown-fields: true
cephConfig:
additionalProperties:
additionalProperties:
type: string
type: object
nullable: true
type: object
labels:
additionalProperties:
additionalProperties:
type: string
type: object
nullable: true
type: object
x-kubernetes-preserve-unknown-fields: true All of those crd have a nesting additionalProperties |
Here is where the annotation crd field generated from: https://github.com/rook/rook/blob/master/pkg/apis/ceph.rook.io/v1/annotations.go#L23-L33 // AnnotationsSpec is the main spec annotation for all daemons
// +kubebuilder:pruning:PreserveUnknownFields
// +nullable
type AnnotationsSpec map[KeyType]Annotations
// Annotations are annotations
type Annotations map[string]string It should be translated to something like BTreeMap<String, BTreeMap<String, String>> . |
This is the minimal crd to reproduce this issue: ---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
name: cephclusters.ceph.rook.io
spec:
group: ceph.rook.io
names:
kind: CephCluster
listKind: CephClusterList
plural: cephclusters
singular: cephcluster
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
properties:
annotations:
additionalProperties:
additionalProperties:
type: string
type: object
nullable: true
type: object
x-kubernetes-preserve-unknown-fields: true
cephConfig:
additionalProperties:
additionalProperties:
type: string
type: object
nullable: true
type: object
cephVersion:
nullable: true
properties:
allowUnsupported:
type: boolean
image:
type: string
imagePullPolicy:
enum:
- IfNotPresent
- Always
- Never
- ""
type: string
type: object
cleanupPolicy:
nullable: true
properties:
allowUninstallWithVolumes:
type: boolean
confirmation:
nullable: true
pattern: ^$|^yes-really-destroy-data$
type: string
sanitizeDisks:
nullable: true
properties:
dataSource:
enum:
- zero
- random
type: string
iteration:
format: int32
type: integer
method:
enum:
- complete
- quick
type: string
type: object
type: object
continueUpgradeAfterChecksEvenIfNotHealthy:
type: boolean
crashCollector:
nullable: true
properties:
daysToRetain:
type: integer
disable:
type: boolean
type: object
type: object |
I think this field: annotations:
additionalProperties:
additionalProperties:
type: string
type: object
nullable: true
type: object
x-kubernetes-preserve-unknown-fields: true may be translated to: #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CephClusterAnnotations {
#[serde(flatten)]
additional_properties: BTreeMap<String, String>,
} |
Run kopium with RUST_LOG=trace:
|
I will manually patch the generated files with // Patched by xxx until https://github.com/kube-rs/kopium/issues/202 is fixed.
// Do not edit it manually.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CephClusterAnnotations {
#[serde(flatten)]
additional_properties: BTreeMap<String, String>,
}
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CephClusterCephConfig {
#[serde(flatten)]
additional_properties: BTreeMap<String, String>,
}
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CephClusterLabels {
#[serde(flatten)]
additional_properties: BTreeMap<String, String>,
} before this issue is fixed. |
Signed-off-by: clux <sszynrae@gmail.com>
Thanks for this bug report! This seems like it will be a bug yes. The part of the analyzer where this ends up is probably a bit too primitive. Have added some premature failing tests in #212 based on your yaml snippets. Do you have examples of actual yaml containing these nested annotations/labels structs? I am unsure whether to do something with flatten in the general kopium case or whether to nest maps. |
@clux Sorry for my late reply. There is a example in rook repo: https://github.com/rook/rook/blob/02a552ce00c4f61703e09e5e3ad8aaca14f724ce/deploy/examples/cluster-test.yaml#L49 It seems to be something like |
This problem could be reproduced with crd cephclusters.ceph.rook.io: https://github.com/rook/rook/blob/v1.13.5/deploy/examples/crds.yaml#L894-L912
kopium generate something like:
and failed to compile:
The text was updated successfully, but these errors were encountered: