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

Track resources that are pending external name assignment #279

Closed
wants to merge 3 commits into from

Conversation

negz
Copy link
Member

@negz negz commented Aug 13, 2021

Description of your changes

Edit: I had originally hoped this would fix crossplane-contrib/provider-aws#802, but it appears there was a simpler fix for that specific case. Nonetheless, I do believe we're hypothetically vulnerable to the issue this PR addresses, so we may want to consider merging it anyhow.

Some Crossplane resources have non-deterministic external names that are returned at Create time. We must record those names and rely on them to determine whether the external resources exist during subsequent Observe calls.

The absence of an external name does not guarantee that we didn't create an external resource. It's possible that we created the resource but failed to update its name. It's also possible that we did update the name but have since read a stale, unnamed, version of the resource from cache.

To deal with this we set a 'pending external name' annotation immediately before creating our external resource. If we get to the Create call because we have a stale view of our managed resource the Update call that persists the annotation will fail. If we are already pending external name assignment when we get to the Create call we know it's possible that we created an external resource but did not persist its name, so we refuse to proceed rather than creating a duplicate.

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

It has not yet. I'll move it out of draft once it has been tested.

@negz negz force-pushed the impending branch 2 times, most recently from d4cf5ec to 7ec0887 Compare August 13, 2021 06:07
Mostly just to get one more green line of code coverage. :)

Signed-off-by: Nic Cope <negz@rk0n.org>
Some Crossplane resources have non-deterministic external
names that are returned at Create time. We must record those
names and rely on them to determine whether the external
resources exist during subsequent Observe calls.

The absence of an external name does not guarantee that we
didn't create an external resource. It's possible that we
created the resource but failed to update its name. It's
also possible that we did update the name but have since
read a stale, unnamed, version of the resource from cache.

To deal with this we set a 'pending external name' annotation
immediately before creating our external resource. If we get
to the Create call because we have a stale view of our managed
resource the Update call that persists the annotation will fail.
If we are already pending external name assignment when we get
to the Create call we know it's possible that we created an
external resource but did not persist its name, so we refuse to
proceed rather than creating a duplicate.

Signed-off-by: Nic Cope <negz@rk0n.org>
Signed-off-by: Nic Cope <negz@rk0n.org>
// annotation should be set before an external resource is created.
// Crossplane uses this annotation to ensure it creates at most one
// external resource.
AnnotationKeyExternalNamePending = "crossplane.io/external-name-pending"
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering if we could combine this PR with #280 by using an annotation like crossplane.io/external-name-pending-since given we also set timestamp as a value here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't see a clean way to combine the two annotations into one, if that's what you're thinking? In this case it's important that we write the annotation immediately before calling create, in order to guarantee that we have the latest version of the managed resource before we create the external resource. In #280 we want to record the time that the external resource was successfully created, i.e. after the creation of the external resource.

Perhaps though we could combine them in some other way, i.e. rather than adding an external-name-pending annotation then removing it when the name was no longer pending, we could add an annotation that indicated a create was about to happen, then another one indicating it succeeded? 🤔

@negz
Copy link
Member Author

negz commented Aug 31, 2021

Closing in favor of #283.

@negz negz closed this Aug 31, 2021
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.

Leaked RouteTable due to eventually consistent DescribeRouteTables API
2 participants