[draft]: Type-changing conversion functions #482
Draft
+641
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of your changes
I have added functionality to change the type of a specified list of field paths between two CRD versions.
This is a prerequisite for my work-in-progress to upgrade the terraform provider in provider-upjet-aws, in which one resource is migrated from the terraform plugin sdk to the terraform plugin framework, resulting in several field paths changing type from string to float. I probably could have done it entirely in provider-upjet-aws, by writing a custom conversion that acted on the
Managedlevel, but the idea of making something reusable was appealing, and could be reused to gracefully handle issues like crossplane-contrib/provider-upjet-aws#1682 in the future.While testing my code, I discovered that the tests for singleton list conversions were using standard go json serialization/deserialization, while crossplane-runtime actually uses kubernetes json serialization/deserialization, which differ in their handling of json
numbers (go always deserializes to float, while k8s deserializes to either float or int depending on the value). I fixed the test function to match what crossplane-runtime does, and am including the additional unit tests I wrote when I was debugging this. I put these in a separate commit so that they can be included even if the more significant change proves unwise.Open questions
This is still a draft/proof-of-concept. I've given very little thought to things like "which file should this go in" or "what should that be named" and would appreciate opinions from others.
One significant long-term question is how we want to handle numeric fields. Currently, for SDK resources, in the four official providers, they are sometimes floats and sometimes strings, depending on the options configured in the terraform schema. In most cases, the actual values need to be integers, but it's not obvious to me how to detect in which cases they should be integers, except perhaps a manually-maintained list of field paths to override.
There's a TODO in the code that converts a tfjson schema to a terraform sdkv2 schema to figure out handling of floats with IntOrString, but as far as I can tell that's not even started. I remember reading somewhere that floats are discouraged in kubernetes CRDs.
I have:
make reviewableto ensure this PR is ready for review.How has this code been tested
I'm testing this with provider-upjet-aws. I'll link to this PR when I open the PR there.