Skip to content
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

[Bug] Crossplane - XRD definition not appear functional when applied to cluster #130

Closed
Sunspar opened this issue Apr 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Sunspar
Copy link

Sunspar commented Apr 25, 2024

Bug Report

When pulling in the CompositeResourceDefinition schema and creating data using it, it seems that the KCL validations on the schema type and the Crossplane webhook validations from the cluster are incompatible.

1. Minimal reproduce step (Required)

Given the following file, hello_world.k:

import manifests
import crossplane.v1.apiextensions_crossplane_io_v1_composite_resource_definition as xrd

hello_world_xrd = xrd.CompositeResourceDefinition {
    metadata.name = "helloworlds.crossplane.example.com"
    spec = {
        group = "crossplane.example.com"
        names.kind = "HelloWorld"
        names.plural = "helloworlds"
        claimNames.kind = "HelloWorldClaim"
        claimNames.plural = "helloworldclaims"
        versions = [{
            name = "v1alpha1"
            served = True
            referenceable = True
            deprecated = False
            # deprecationWarning = Undefined
            schema.openAPIV3Schema.type = "object"
            schema.openAPIV3Schema.properties = {
                spec = {
                    type = "object"
                    properties = {
                        thing = {
                            type = "string"
                        }
                    }
                }
            }
        }]
    }
}

manifests.yaml_stream([hello_world_xrd])

You should find that you cannot export this definition to YAML via something like kcl hello-world.k unless you provide a string value for spec.versions[].deprecationWarning. The schema claims this field is optional, but the check constraint here forces it to exist (len() fails if the value of the field is Undefined). https://github.com/kcl-lang/modules/blob/main/crossplane/v1/apiextensions_crossplane_io_v1_composite_resource_definition.k#L438

If you try and leave this field undefined, you get the following error:

Error: failed to compile the kcl package
EvaluationError
   --> /Users/sunspar/.kcl/kpm/crossplane_1.15.2/v1/apiextensions_crossplane_io_v1_composite_resource_definition.k:438:1
    |
438 |         len(deprecationWarning) <= 256
    |  object of type 'UndefinedType' has no len()
    |

If instead you define it with any string message (including an empty string), then the YAML generates correctly (given the config you have) but applying it to the cluster causes the following error:

The CompositeResourceDefinition "helloworlds.crossplane.example.com" is invalid: <generated_CRD_"helloworlds.crossplane.example.com">.spec.versions[0].deprecationWarning: Invalid value: "": can only be set for deprecated versions`

2. What did you expect to see? (Required)deprecationWarning

I expected that since the field was optional, not providing it was allowed and would allow me to generate YAML output.

3. What did you see instead (Required)

The field is required and I cannot export this to YAML without it. providing this value however is problematic, because the K8S admission webhook blocks publishing XRDs with this field when deprecated = false.

4. What is your KCL components version? (Required)

0.8.6-darwin-arm64

@Sunspar
Copy link
Author

Sunspar commented Apr 25, 2024

I've got this working with a local copy of the module when I change the check to the following, but I'm not sure if there is a better way to handle this issue since these files are auto-generated and likely to be overwritten (or worse, regresses when these schemas are generated for future versions of Crossplane):

check:
    len(deprecationWarning) <= 256 if deprecationWarning != Undefined

@Peefy
Copy link
Contributor

Peefy commented Apr 26, 2024

Thank you for your feedback. Your modification is correct and can be changed to the following format.

check:
    len(deprecationWarning) <= 256 if deprecationWarning

Although it is created by kcl-openapi tool automatically https://github.com/kcl-lang/kcl-openapi , but the generated code is not correct. You can submit a PR to modify this code and upgrade the version in the kcl.mod . When the PR is merged, the package on the registry will be automatically updated. Thank you! ❤️

@Peefy Peefy added the bug Something isn't working label Apr 26, 2024
@Peefy Peefy closed this as completed May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants