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 #537

Merged
merged 4 commits into from
Jun 12, 2024

Conversation

ulucinar
Copy link
Collaborator

@ulucinar ulucinar commented Jun 4, 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 #527.

We've previously addressed this issue by manually configuring the MaxItems constraints for the affected resources in #527. 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 #527:

  • ...

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

- Generate the secret references for the sensitive fields under
  the spec.initProvider API tree.

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
- 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 <ulucinar@users.noreply.github.com>
from the Go resource schema to the JSON schema.

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
@ulucinar
Copy link
Collaborator Author

ulucinar commented Jun 4, 2024

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

@ulucinar
Copy link
Collaborator Author

ulucinar commented Jun 4, 2024

/test-examples="examples/container/v1beta2/nodepool.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 a nit comment that is proposing the removal of the function that is 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/kms/config.go Show resolved Hide resolved
Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
@ulucinar
Copy link
Collaborator Author

/test-examples="examples/container/v1beta2/nodepool.yaml"

@ulucinar
Copy link
Collaborator Author

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

@ulucinar ulucinar merged commit c79f63e into crossplane-contrib:main Jun 12, 2024
11 checks passed
@ulucinar ulucinar deleted the sync-maxitems branch June 12, 2024 17:11
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