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

Make MaxItems values consistent between JSON schema and provider schema #745

Merged

Conversation

sergenyalcin
Copy link
Collaborator

@sergenyalcin sergenyalcin commented May 20, 2024

Description of your changes

During tests of the `Convert all singleton lists in the MR APIs to embedded objects' PRs, we observed an issue regarding the inconsistency between the JSON schema and provider schema.

The GetProvider function returns provider configuration in the providers. This function has a parameter generationProvider. If it is set to true, the JSON schema is used to obtain provider configuration. If it is false, the Go schema is used.

In theory, the two schemas are equivalent. However, during tests, we observed inconsistencies in some fields MaxItems values. This means that we use different schemas during generation and reconciliation.

This causes issues with the conversion of singleton lists to embedded objects. This type of change may also cause bigger problems.

This PR makes MaxItems values consistent between JSON schema and provider schema by manipulating the resource schemas.

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

@sergenyalcin
Copy link
Collaborator Author

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

@sergenyalcin
Copy link
Collaborator Author

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

@sergenyalcin
Copy link
Collaborator Author

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

@sergenyalcin
Copy link
Collaborator Author

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

@sergenyalcin
Copy link
Collaborator Author

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

Copy link
Collaborator

@ulucinar ulucinar left a comment

Choose a reason for hiding this comment

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

Thanks @sergenyalcin for fixing these configurations. We will need to fix the snake_case second arguments to Resource.AddSingletonListConversion throughout the PR. We expect a CRD path as the second argument.

Let's merge #746 and rebase this PR before merging to get a green check-examples job.

Comment on lines +617 to +626
r.Version = "v1beta2"
r.PreviousVersions = []string{"v1beta1"}
// we would like to set the storage version to v1beta1 to facilitate
// downgrades.
r.SetCRDStorageVersion("v1beta1")
r.ControllerReconcileVersion = "v1beta1"
r.Conversions = []conversion.Conversion{
conversion.NewIdentityConversionExpandPaths(conversion.AllVersions, conversion.AllVersions, conversion.DefaultPathPrefixes(), r.CRDListConversionPaths()...),
conversion.NewSingletonListConversion("v1beta1", "v1beta2", conversion.DefaultPathPrefixes(), r.CRDListConversionPaths(), conversion.ToEmbeddedObject),
conversion.NewSingletonListConversion("v1beta2", "v1beta1", conversion.DefaultPathPrefixes(), r.CRDListConversionPaths(), conversion.ToSingletonList)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need this explicit singleton list conversion configuration because there are no other singleton list fields in this resource than the rule field, right? And the rule field's MaxItems constraint is not 1 in the JSON schema, whereas it's set to 1 in the Go schema?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes this is the case here. We only rule field for conversion here. So, I specifically configure this resource version and conversion functions because they can't be configured via central function. Also the case is that we make consistent the JSON schema value with Go schema.

r.TerraformResource.Schema["encryption"].MaxItems = 1
r.TerraformResource.Schema["network_rule_set"].MaxItems = 1

r.AddSingletonListConversion("retention_policy", "retention_policy")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like the CRD paths are misconfigured, i.e.:

Suggested change
r.AddSingletonListConversion("retention_policy", "retention_policy")
r.AddSingletonListConversion("retention_policy", "retentionPolicy")

We also need to fix the other snake_case second arguments to Resource.AddSingletonListConversion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
Copy link
Collaborator

@ulucinar ulucinar left a comment

Choose a reason for hiding this comment

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

Thank you @sergenyalcin, lgtm.

@sergenyalcin sergenyalcin merged commit 0c238ce into crossplane-contrib:main May 22, 2024
11 checks passed
@sergenyalcin sergenyalcin deleted the configure-max-items branch May 22, 2024 08:46
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.

None yet

2 participants