kopium
                                
                                 kopium copied to clipboard
                                
                                    kopium copied to clipboard
                            
                            
                            
                        empty `type` field is not handled
When trying to generate code for the cert-manager ClusterIssuer CRD, kopium fails with:
$ kopium clusterissuers.cert-manager.io
Error: unknown empty dict type for config
It seems that the CRD contains a field that has no type set (config):
                              webhook:
                                description: Configure an external webhook based DNS01 challenge solver to manage DNS01 challenge records.
                                type: object
                                required:
                                  - groupName
                                  - solverName
                                properties:
                                  config:
                                    description: Additional configuration that should be passed to the webhook apiserver when challenges are processed. This can contain arbitrary JSON data. Secret values should not be specified in this stanza. If secret values are needed (e.g. credentials for a DNS service), you should use a SecretKeySelector to reference a Secret resource. For details on the schema of this field, consult the webhook provider implementation's documentation.
                                    x-kubernetes-preserve-unknown-fields: true
                                  groupName:
                                    description: The API group name that should be used when POSTing ChallengePayload resources to the webhook apiserver. This should be the same as the GroupName specified in the webhook provider implementation.
                                    type: string
                                  solverName:
                                    description: The name of the solver to use, as defined in the webhook provider implementation. This will typically be the name of the provider, e.g. 'cloudflare'.
                                    type: string
Manually adding type: object makes kopium generate the code correctly.
I am actually not sure if this is allowed, but at least Kubernetes seems to accept emtpy type fields.
Thanks for the report.
I am not sure what's best way forward right now. Your particular case does actually align with #31 and we can probably deal with it however we deal with that, but not sure if this is the only place where we will see it.
If it is indeed the case that Kubernetes always treats the missing type case as type: object then we can probably do some defaulting, but would be nice to have some sources for this before doing potentially ill-advised implementations.
After reading
https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#specifying-a-structural-schema
I think that from a Kubernetes perspective there is no default on the  x-kubernetes-preserve-unknown-fields: true fields. One can optionally specify the type if this is supposed to be validated by the API server. When I understand it correctly, I guess it means there could potentially be arrays or other values behind such a field.
If my interpretation is correct that means assuming object is probably wrong. In the generated code, could the resulting field just be serde_json::Value? Then it would be up to the user to handle it correctly?
hm, yeah agreed, that is probably a better default.
I had forgotten about this bug. I don't remember what we did in the last year and a half, but this no longer fails as can be seen in the metio registry: https://github.com/metio/kube-custom-resources-rs/blob/54b8ac550b127b16736608c5c5cc240c498aa1b6/kube-custom-resources-rs/src/cert_manager_io/v1/clusterissuers.rs from https://github.com/metio/kube-custom-resources-rs/blob/main/crd-catalog/cert-manager/cert-manager/cert-manager.io/v1/clusterissuers.yaml
i'm still hitting this using kopium v0.19.0. i'm trying to convert the traefik v2.11 middlewares crd using kopium and am getting the error
Error: unknown empty dict type for plugin
oddly enough, the plugin attribute does have a type on it.
here is a link to the yaml file i'm attempting to convert. any thoughts would be appreciated.
https://github.com/traefik/traefik-helm-chart/blob/ba3c4c44d60214dbfd6d15fae69b464bbcbbd4a6/traefik/crds/traefik.io_middlewares.yaml
ok. so i figured out the issue. it wasn't the plugin object that was causing the issue, though the error appears to say plugin is the issue. the issue was that the additionalProperties didn't have a type on it. i think the correct type in my case is object.
@w3irdrobot i think we should be generating maps of string -> raw json in this case (since it's within an additionalProperties) what do you think of #244?
yeah that lgtm