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

Add a new configuration option for required field generation #381

Merged

Conversation

sergenyalcin
Copy link
Member

@sergenyalcin sergenyalcin commented Mar 18, 2024

Description of your changes

This PR adds a new configuration option for required field generation. The name of this new configuration API is RequiredFields and it is included to the Resource.

This change aims to generate fields as Required when needed, without interfering with the underlying provider schema. Before, for generating a field as Required, we used the MarkAsRequired function. This function directly intervenes in the schema and sets the Computed and Optional values of the relevant field equal to false. Schema interventions may have the power to directly affect the internal operations of the underlying provider. This may lead to unexpected behavioral changes. We recently observed the mentioned situation in this issue.

In this issue, it was observed that the behavior of resources that schema was intervened (using MarkAsRequired) changed after the underlying provider version bump, directly related to this schema intervention. This behavioral change directly blocks the provisioning of resources and even causes existing resources be unsynced. This reveals the extent of the dangers of schema interventions.

Of course, there are such needs for generation. However, such needs can be solved without schema intervention. This change paves the way for a field that is not required in the underlying provider schema to be generated as 'Required', with a high-level configuration API, without any schema intervention.

This PR also proposes the deprecation of MarkAsRequired API.

I have:

  • Read and followed Upjet'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

Tested generation in provider-gcp by removing MarkAsRequired and adding the following configuration:

r.MarkAsRequired("zone")

Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
@sergenyalcin sergenyalcin force-pushed the add-required-configuration-option branch from 811aab6 to bdfbe67 Compare March 18, 2024 15:18
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, left some comments for you to consider.

pkg/config/resource.go Outdated Show resolved Hide resolved
pkg/config/resource.go Outdated Show resolved Hide resolved
…iredFields

- Deprecate config.MarkAsRequired in favor of a new configuration function on *config.Resource that still accepts a slice to mark multiple fields as required without doing and invervention in native field schema.

Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
@sergenyalcin sergenyalcin force-pushed the add-required-configuration-option branch from fb16c91 to f25329f Compare March 19, 2024 09:42
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.

Thanks @sergenyalcin, lgtm.

pkg/config/resource.go Show resolved Hide resolved
pkg/types/builder.go Outdated Show resolved Hide resolved
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
@sergenyalcin sergenyalcin merged commit 50919fe into crossplane:main Mar 19, 2024
7 checks passed
@sergenyalcin sergenyalcin deleted the add-required-configuration-option branch March 19, 2024 12:47
@sergenyalcin
Copy link
Member Author

The tests in GCP are successful: crossplane-contrib/provider-upjet-gcp#490 (comment)

Copy link

Successfully created backport PR #383 for release-1.2.

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