Skip to content

fix: add check to Observe the last sync status for the resource#492

Merged
SatabdiG merged 15 commits into
mainfrom
fix/wrong_state_handling_491
May 12, 2026
Merged

fix: add check to Observe the last sync status for the resource#492
SatabdiG merged 15 commits into
mainfrom
fix/wrong_state_handling_491

Conversation

@SatabdiG
Copy link
Copy Markdown
Contributor

@SatabdiG SatabdiG commented Feb 3, 2026

Fixes #491

ServiceInstance shows Ready: True, Synced: True when async update operations fail

Bug Description

When a ServiceInstance update fails asynchronously in BTP (e.g., due to invalid parameters), the Crossplane resource incorrectly shows Ready: True and Synced: True even though the operation failed. The failure is only visible in the LastAsyncOperation condition.

Root Cause

The controller was not checking the LastAsyncOperation condition status in the Observe() method. When terraform detected drift and triggered an Update that failed asynchronously, the subsequent Observe would see Drift status and return ResourceUpToDate: false, but Crossplane would still set Synced: True because no error was returned.

Fix

Added checkAsyncOperationFailure() helper that checks LastAsyncOperation condition before the terraform status switch, ensuring failed async operations are caught regardless of whether terraform reports Drift or UpToDate.

Affected Resources

  • ServiceInstance (account.btp.sap.crossplane.io/v1alpha1)

Note
Potentially other resources using upjet with async operations

@SatabdiG SatabdiG self-assigned this Feb 3, 2026
@SatabdiG SatabdiG marked this pull request as ready for review February 3, 2026 13:43
@SatabdiG SatabdiG added bug BTP BTP Provider labels Feb 3, 2026
@SatabdiG SatabdiG moved this from Validation to In Progress in Crossplane Provider Boards Feb 3, 2026
@SatabdiG SatabdiG moved this from Ready for Sprint to In Progress in OLD! Backlog: Crossplane BTP Provider Feb 3, 2026
}

//Check for failed async operations ONCE, before the switch
if e.checkAsyncOperationFailure(cr) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we are checking the cr. But the CR has the status from the last Observe. Wouldnt it be better to check the status of the current Observe?

Copy link
Copy Markdown
Contributor Author

@SatabdiG SatabdiG Feb 3, 2026

Choose a reason for hiding this comment

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

We could but the catch is we have to use the last observe because:
The synced condition should reflect whether our last reconciliation attempt succeeded, not just whether there's drift. The LastAsyncOperation condition (set by upjet's saveCallback during Update) tells us if the previous update succeeded or failed. Without this check, resources would show Synced=True even when updates fail, because terraform would only report "Drift" without exposing the failure reason

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

According to what I found This pattern follows upjet's native controller implementation, where conditions from async operations are checked in subsequent Observe cycles. The conditions are "fresh" because
upjet's saveCallback updates them immediately when the async terraform operation completes.

Any other alternative would require refactoring Upjets saveCallback which is more refactoring work and not sure we even want to go in that direction.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I got it, the CR contains the status of the current observe cycle because it is immediately saved by tf. Than this is good :)
Maybe add this as a comment in case someone is wondering the next time :D

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just wondering, is the status condition Unavailable() commonly used for purposes like that?
Missed potentially the last discussions, just wondering if we should have this discussion and formalize it a bit more in an ADR or so, because I think reflected failed updates is generally a topic we (and for all a know the whole crossplane community) has totally ignored up until now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sdischer-sap, good point, seems like a dev sync topic.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@SatabdiG SatabdiG added the release-notes/bugfix Marks PR as bugfix for release note generation label Mar 20, 2026
@sdischer-sap
Copy link
Copy Markdown
Member

@SatabdiG can we merge that one? I think we reached an agreement right?

@sdischer-sap sdischer-sap added the requires/author-action Requires more input from issue creator. label Mar 26, 2026
@SatabdiG
Copy link
Copy Markdown
Contributor Author

As decided we will update to reflect synced:false in such cases as opposed to ready:false

@SatabdiG SatabdiG requested a deployment to pr-e2e-approval May 6, 2026 07:43 — with GitHub Actions Waiting
@SatabdiG SatabdiG requested a deployment to pr-e2e-approval May 6, 2026 07:56 — with GitHub Actions Waiting
@SatabdiG SatabdiG requested a deployment to pr-e2e-approval May 6, 2026 08:18 — with GitHub Actions Waiting
@SatabdiG SatabdiG temporarily deployed to pr-e2e-approval May 6, 2026 08:46 — with GitHub Actions Inactive
@SatabdiG SatabdiG temporarily deployed to pr-e2e-approval May 7, 2026 12:43 — with GitHub Actions Inactive
@SatabdiG SatabdiG merged commit 5ed5652 into main May 12, 2026
41 of 42 checks passed
@SatabdiG SatabdiG deleted the fix/wrong_state_handling_491 branch May 12, 2026 08:13
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Crossplane Provider Boards May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BTP BTP Provider release-notes/bugfix Marks PR as bugfix for release note generation requires/author-action Requires more input from issue creator.

Projects

Status: Done
Status: In Progress

Development

Successfully merging this pull request may close these issues.

[BUG] Failed Updates not reflected in states in ServiceInstance

5 participants