Skip to content

Commit

Permalink
explicitly return diff when a resource switches integrations (#4415)
Browse files Browse the repository at this point in the history
* explicitly return diff when a resource switches integrations

* add tests and format
  • Loading branch information
maorfr authored Jun 3, 2024
1 parent 9f4c1fa commit 2c63bfc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions reconcile/test/test_three_way_diff_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,13 @@ def test_3wpd_diff_detects_missing_annotation(deployment):
del c_item.body["metadata"]["annotations"]["new-annotation"]

assert three_way_diff_using_hash(c_item, d_item) is False


def test_3wpd_diff_detects_switch_integration(deployment):
d_item = OR(deployment, "same-integration", "")
deployment["metadata"]["annotations"]["qontract.integration"] = (
"different-integration"
)
c_item = OR(deployment, "same-integration", "").annotate(canonicalize=False)

assert three_way_diff_using_hash(c_item, d_item) is False
8 changes: 8 additions & 0 deletions reconcile/utils/three_way_diff_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ def three_way_diff_using_hash(c_item: OR, d_item: OR) -> bool:
logging.debug("Current object QR hash is missing -> Apply")
return False

if (
c_item_integration := annotations["qontract.integration"]
) != d_item.integration:
logging.info(
f"resource switching integration from {c_item_integration} to {d_item.integration}"
)
return False

# Original object does not match Desired -> Apply
# Current object hash is not recalculated!
if c_item_sha256 != d_item.sha256sum():
Expand Down

0 comments on commit 2c63bfc

Please sign in to comment.