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

Sync the MaxItems constraints between the Go & JSON schemas #759

Merged
merged 4 commits into from
Jun 12, 2024

Conversation

ulucinar
Copy link
Collaborator

@ulucinar ulucinar commented Jun 3, 2024

Description of your changes

Depends on: crossplane/upjet#411

When replacing the singleton lists with embedded objects in the MR APIs, we had figured out that the MaxItems constraints in the JSON resource schema were not in-sync with the constraints declared in the Go schema. For more context, please see the description of #745.

We've previously addressed this issue by manually configuring the MaxItems constraints for the affected resources in #745. This also implies that if the constraints are not in sync for any future resources, then we will also need to manually configure them.

With crossplane/upjet#411, we introduce a new schema traverser, traverser.maxItemsSync, that syncs the MaxItems constraints from a source schema to a target schema.

This PR removes the manual MaxItems configurations and uses traverser.maxItemsSync to sync the MaxItems constraints from the Go resource schema to the JSON resource schema. This will also help us with any future resources for which the MaxItems constraints are not in sync. We could in theory sync the other constraints than MaxItems but currently it's the only known constraint with inconsistencies causing us trouble.

With a major version bump of the provider, we would also like to get rid of the JSON resource schema that we only use during the code generation, as a long term strategy.

Note:

As we bump the upjet version with this PR to be able to use the traverser.maxItemsSync, we also generate the secret references for sensitive fields under the spec.initProvider API tree. This has been implemented in a separate initial commit before the manual MaxItems constraints are removed, so that it becomes easy for the reviewers to observe how the schema traverser behaves and whether it can effective replace the current manual configuration.

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Via the uptest runs of the resources tested in #745:

Also, please observe that commit 9d9d45022022d3ae4d641ba8b46de615a654812c (which invokes the syncMaxItems schema traverser) on top of the commit a228c35e0527fc9fb2f5997369747f9fee67f356 (which removes the MaxItems configuration) produces no diff in the generated code.

@ulucinar
Copy link
Collaborator Author

ulucinar commented Jun 3, 2024

/test-examples="examples/network/v1beta2/routefilter.yaml"

@ulucinar
Copy link
Collaborator Author

ulucinar commented Jun 3, 2024

/test-examples="examples/network/v1beta2/subnet.yaml"

@ulucinar
Copy link
Collaborator Author

ulucinar commented Jun 3, 2024

/test-examples="examples/cdn/v1beta2/endpoint.yaml"

@ulucinar
Copy link
Collaborator Author

ulucinar commented Jun 3, 2024

/test-examples="examples/compute/v1beta2/sharedimage.yaml"

@ulucinar
Copy link
Collaborator Author

ulucinar commented Jun 3, 2024

/test-examples="examples/network/v1beta2/profile.yaml"

Copy link
Collaborator

@sergenyalcin sergenyalcin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ulucinar LGTM. I left two nit comments that are proposing the removal of the functions that are no longer functional after the change. Also, checked the diffs in the apis and package to ensure that the configuration changes do not affect the APIs. It seems that all changes are related-to generation of SecretRefs in InitProvider blocks.

config/network/config.go Outdated Show resolved Hide resolved
config/synapse/config.go Outdated Show resolved Hide resolved
- Generate the secret references for the sensitive fields under
  the spec.initProvider API tree.

Signed-off-by: Alper Rifat Ulucinar <[email protected]>
- We are introducing a schema traverser in upjet that's capable of
  synching the MaxItems constraints from the Go resource schema to
  the JSON schema. So we switch from manual configuration to
  automatic constraint syncing (for now, only MaxItems constraints
  are synced).
- We would like to get rid of the JSON schema completely with a major
  version bump.
- Automatic syncing will also help with the new resources as we will
  not need to consider syncing the MaxItems constraints on their
  fields.

Signed-off-by: Alper Rifat Ulucinar <[email protected]>
from the Go resource schema to the JSON schema.

Signed-off-by: Alper Rifat Ulucinar <[email protected]>
Signed-off-by: Alper Rifat Ulucinar <[email protected]>
@ulucinar
Copy link
Collaborator Author

/test-examples="examples/network/v1beta2/profile.yaml"

@ulucinar
Copy link
Collaborator Author

/test-examples="examples/compute/v1beta2/sharedimage.yaml"

@ulucinar
Copy link
Collaborator Author

/test-examples="examples/cdn/v1beta2/endpoint.yaml"

@ulucinar
Copy link
Collaborator Author

/test-examples="examples/network/v1beta2/subnet.yaml"

@ulucinar
Copy link
Collaborator Author

/test-examples="examples/network/v1beta2/routefilter.yaml"

@ulucinar ulucinar merged commit 51ecccb into crossplane-contrib:main Jun 12, 2024
16 checks passed
@ulucinar ulucinar deleted the sync-maxitems branch June 12, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants