Skip to content

fix(resource): tolerate existing usage in Track - #1270

Closed
jonasz-lasut wants to merge 1 commit into
crossplane:mainfrom
jonasz-lasut:fix/pcu-track-already-exists
Closed

jonasz-lasut wants to merge 1 commit into
crossplane:mainfrom
jonasz-lasut:fix/pcu-track-already-exists

Conversation

@jonasz-lasut

@jonasz-lasut jonasz-lasut commented Nov 13, 2026 •

Copy link
Copy Markdown

Description of your changes

Fixes crossplane-contrib/provider-upjet-gcp#1067

With a cache-backed client, a second Track for the same managed resource can run before the informer has seen the ProviderConfigUsage the first one created: its Get returns NotFound, its Create returns AlreadyExists, and the reconcile fails with cannot apply ProviderConfigUsage: cannot create object: providerconfigusages.gcp.m.upbound.io "c9c357e2-1f8a-4065-a6d3-8d2044781bfd" already exists. Upjet providers call Track twice per reconcile, from the reconciliationpolicy wrapper and from Connect, and crossplane-contrib/provider-upjet-gcp#1067 reports every new managed resource failing its first reconcile this way in some cases.

ProviderConfigUsageTracker.Track and LegacyProviderConfigUsageTracker.Track now ignore AlreadyExists from the apply, next to IsNotAllowed. APIUpdatingApplicator is unchanged, so its other callers still get the error. If the existing usage references a different ProviderConfig, it's left as is until the next Track, whose Get finds it and updates it through AllowUpdateIf.

TestTrackModern and TestTrackLegacy each have a new AlreadyExists case that runs Track through NewAPIUpdatingApplicator with a mock client returning NotFound from Get and AlreadyExists from Create.

I have:

Need help with this checklist? See the cheat sheet.

Track gets the ProviderConfigUsage and creates it when the get returns
NotFound. With a cache-backed client a second Track for the same
managed resource, run before the informer has seen the first create,
gets NotFound again, and its create fails with AlreadyExists:

  cannot apply ProviderConfigUsage: cannot create object:
  providerconfigusages.gcp.m.upbound.io "<uid>" already exists

Upjet providers call Track twice per reconcile, from the
reconciliationpolicy wrapper and from Connect, so every new managed
resource fails its first reconcile and emits a warning event. The
double call was read from provider code; the cache lag is inferred
from the code, not observed at runtime.

Track and the legacy tracker's Track now ignore AlreadyExists from the
apply, next to IsNotAllowed. APIUpdatingApplicator is unchanged, so its
other callers still get the error. If the existing usage references a
different ProviderConfig it is left as is until the next Track, whose
get finds it and updates it through AllowUpdateIf.

Reported in crossplane-contrib/provider-upjet-gcp#1067.

Signed-off-by: Jonasz Małecki <jonasz@upbound.io>
@jonasz-lasut
jonasz-lasut marked this pull request as ready for review November 13, 2026 13:32
@jonasz-lasut
jonasz-lasut requested a review from a team as a code owner November 13, 2026 13:32
@jonasz-lasut
jonasz-lasut requested a review from negz November 13, 2026 13:32
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Modern and legacy Track methods now ignore Kubernetes AlreadyExists errors, as they already do IsNotAllowed errors. Tests cover the case where a usage lookup returns NotFound and creation returns AlreadyExists.

Changes: Track Usage Handling

Layer / File(s) Summary
Ignore AlreadyExists during tracking
pkg/resource/providerconfig.go, pkg/resource/providerconfig_test.go
Both Track methods treat AlreadyExists as non-fatal while other errors remain wrapped with errApplyPCU. The documentation describes how later calls handle an existing usage with a different ProviderConfig reference. Tests cover the NotFound-then-AlreadyExists case for both methods.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: erhancagirici

Merge Risk: Minimal · up to b7930

Track no longer fails when the usage already exists, which fixes a cache-lag race that the PR reports as causing reconcile errors. In the rare case where an existing usage points at a different ProviderConfig, it is corrected on a later Track call. The change is small and has test coverage, and no concrete merge-blocking risk was found.

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Breaking Changes Inconclusive Summary: The PR changes two exported methods, ProviderConfigUsageTracker.Track and LegacyProviderConfigUsageTracker.Track, in pkg/resource/providerconfig.go. No exported signature, type, field, … Confirm the labels on crossplane/crossplane-runtime PR #1270. - If the breaking-change label is present, this check passes. - If the label is absent, decide whether the behavior change is breaking. The change turns an AlreadyExists erro…
Passed Passed checks: 4 passed

Check name Status Explanation
Title check Passed The title "fix(resource): tolerate existing usage in Track" is 47 characters, under the 72-character limit. It names the change: Track now ignores AlreadyExists errors from the usage apply. It is desc…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description explains the cache-backed client race where a second Track gets NotFound on Get and AlreadyExists on Create, and states that Track in both trackers now ignores AlreadyExists. It also d…
Full details: Title check

Explanation

The title "fix(resource): tolerate existing usage in Track" is 47 characters, under the 72-character limit. It names the change: Track now ignores AlreadyExists errors from the usage apply. It is descriptive and matches the changeset in providerconfig.go and its tests.

Full details: Description check

Explanation

The description explains the cache-backed client race where a second Track gets NotFound on Get and AlreadyExists on Create, and states that Track in both trackers now ignores AlreadyExists. It also describes the new AlreadyExists test cases for TestTrackModern and TestTrackLegacy, so it relates directly to the changeset.

Full details: Breaking Changes

Explanation

Summary: The PR changes two exported methods, ProviderConfigUsageTracker.Track and LegacyProviderConfigUsageTracker.Track, in pkg/resource/providerconfig.go. No exported signature, type, field, or name is removed, renamed, or changed. The change is behavioral. Verified diff: - Both methods now use IgnoreAny(err, IsNotAllowed, kerrors.IsAlreadyExists) instead of Ignore(IsNotAllowed, err). An AlreadyExists error from the usage apply now returns nil. - The doc comments now say a usage that already exists is not an error, and that a later Track updates a usage that references a different ProviderConfig. - APIUpdatingApplicator is unchanged, so other callers keep the error. Breakage assessment: Callers that compile against these methods still compile. Callers that depended on Track returning an error for AlreadyExists now get nil. In that case the usage may still reference an old ProviderConfig until the next Track. The check's "behavior changes that could break existing users" condition may therefore apply. The check also requires the breaking-change label to be absent before it fails. The supplied PR metadata does not include labels, and this run has no tool to read them, so I cannot confirm whether the label is present. The author is jonasz-lasut (provider-reported). Author identity does not affect this check. I cannot decide between PASS and FAIL without the label state. A FAIL needs proof that the label is missing. A PASS needs agreement that this is not a breaking change.

Resolution

Confirm the labels on crossplane/crossplane-runtime PR #1270. - If the breaking-change label is present, this check passes. - If the label is absent, decide whether the behavior change is breaking. The change turns an AlreadyExists error from Track into nil, and can leave a stale ProviderConfig reference until the next Track. If you consider it breaking, add the breaking-change label, or document why it is not breaking. If you do not consider it breaking, this check passes. Consider a short note in the PR or release notes about the new nil return for AlreadyExists, since callers that matched that error will see different behavior.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between adb6fed and b793011.

Files selected for processing: 2

  • pkg/resource/providerconfig.go
  • pkg/resource/providerconfig_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@jonasz-lasut

Copy link
Copy Markdown
Author

Closing, we decided to resolve it on provider level by splitting providerconfig resolution to read and write paths

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.

[Bug]: Transient "ProviderConfigUsage ... already exists" on cloudplatform kinds still occurs in v3.1.0 (no panic)

1 participant