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

Support granular managment policies #224

Merged
merged 1 commit into from
Jul 24, 2023

Conversation

lsviben
Copy link
Contributor

@lsviben lsviben commented Jun 29, 2023

Description of your changes

Updated the ObserveOnly management policy support to the new design which
incorporates granular management policies.

The main change is that instead of enum based spec.managementPolicy: FullControl/ObserveOnly/OrphanOnDelete, now we have an more granular array of actions spec.managementPolicy:["Observe", "Create", "Update", "LateInitialize", "Delete"].

So as upjet was already supporting ObserveOnly with Import, we needed to do minor changes on conditionals to make sure that spec.managementPolicy:["Observe"] is still recognized as ObserveOnly. In fact, all combinations which don't contain Create or Update actions can be handled similarly.

Furthermore, as there is now a management policy which skips late initialziation, I noticed that upjet was using late initialization for updating critical annotations on resources. Those annotations are usually set after Create, but as upjet offers async creation, and most resources use that (all in aws-provider for example), they are not set after Create, but in Observe, with using late-init to update the resource.

In this case, when late-init is off, we update the annotations manually in the Observe step. We could consider doing this in all situations and stop relying on late-init to do it for us. Or handle this differently.

Fixes #220

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

Tested it in the same process as crossplane/crossplane-runtime#456 as they are connected. More info on that issue.

go.mod Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
pkg/controller/external.go Outdated Show resolved Hide resolved
@lsviben lsviben force-pushed the granular_managment_policies branch from fd20ebc to 4fba84b Compare June 29, 2023 11:35
@lsviben lsviben marked this pull request as ready for review June 29, 2023 21:17
@lsviben lsviben requested review from ulucinar and turkenh and removed request for ulucinar June 29, 2023 21:17
@lsviben lsviben force-pushed the granular_managment_policies branch from 4fba84b to c26c975 Compare July 4, 2023 08:42
@lsviben lsviben force-pushed the granular_managment_policies branch 3 times, most recently from 1a099c8 to 291bef2 Compare July 12, 2023 21:22
pkg/controller/external.go Outdated Show resolved Hide resolved
Copy link
Member

@turkenh turkenh left a comment

Choose a reason for hiding this comment

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

Thanks @lsviben, looking good!

pkg/controller/external.go Outdated Show resolved Hide resolved
pkg/controller/external.go Outdated Show resolved Hide resolved
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 @lsviben for the PR. Left some comments for my understanding. And thank you for bearing with me while I'm trying to understand these important changes better.

pkg/controller/external.go Show resolved Hide resolved
pkg/controller/external.go Show resolved Hide resolved
pkg/controller/external.go Show resolved Hide resolved
@@ -133,7 +133,7 @@ func (g *Builder) AddToBuilder(typeNames *TypeNames, r *resource) (*types.Named,

for _, p := range r.topLevelRequiredParams {
g.validationRules += "\n"
g.validationRules += fmt.Sprintf(`// +kubebuilder:validation:XValidation:rule="self.managementPolicy == 'ObserveOnly' || has(self.forProvider.%s)",message="%s is a required parameter"`, p, p)
g.validationRules += fmt.Sprintf(`// +kubebuilder:validation:XValidation:rule="!('*' in self.managementPolicies || 'Create' in self.managementPolicies || 'Update' in self.managementPolicies) || has(self.forProvider.%s)",message="%s is a required parameter"`, p, p)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we sure that for a Delete operation, we are fine with not setting a required parameter? Did we validate this? I think it's not possible to have delete-only resource right, at least with the default policy sets? Looks like Delete policy always comes with the Create policy, is this correct?

If so, are we relying on the default supported policy sets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aswered a bit here, but now I see that possibly delete wont work if we dont have required fields, not sure how Terraform reacts to that. As I mentioned I didn't test all unsupported combinations. All supported policies have Delete in a combination with either Create or Update.

Copy link
Collaborator

@ulucinar ulucinar Jul 21, 2023

Choose a reason for hiding this comment

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

... not sure how Terraform reacts to that...

This is also my concern here. I can help validating the behavior.

Another concern is the validation rules (build-time entities) are not aware of if management policies are actually enabled or not (the decision is only available at runtime). But with these "static" rules, we are conditioning whether, for instance, management policy for a resource is set to Observe.

Imagine a case where the management policy is set to Observe and the management policies feature is disabled at runtime. For now, we are relying on the crossplane-runtime to error when the management policies are not enabled but a non-default (non *) management policy is declared. I don't think this is a blocker for this PR, just trying to understand the implications so that we can maintain the new feature.

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 @lsviben for the detailed clarifications, lgtm.

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.

Support for granular management policies
4 participants