Skip to content

Fix HasDiff returning false when OwnerIds or ParentIds actually differ - #7137

Merged
khanhtc1202 merged 3 commits into
pipe-cd:masterfrom
vipulpandey21:fix/kubernetes-resource-hasdiff-owner-parent-mismatch
Aug 22, 2026
Merged

Fix HasDiff returning false when OwnerIds or ParentIds actually differ#7137
khanhtc1202 merged 3 commits into
pipe-cd:masterfrom
vipulpandey21:fix/kubernetes-resource-hasdiff-owner-parent-mismatch

Conversation

@vipulpandey21

Copy link
Copy Markdown
Contributor

What this PR does:

Fixes KubernetesResourceState.HasDiff so a mismatch in OwnerIds or ParentIds returns true instead of false.

- return false
+ return true

(both loops, same one-line change)

Why we need it:

Every other check in this function returns true on a mismatch — that's the whole point of HasDiff. For OwnerIds/ParentIds it did the opposite, so when a resource's owner or parent changes, piped never reports it as an update. Details in #7135.

How I tested it:

Added TestKubernetesResourceState_HasDiff. Fails on current code:

--- FAIL: TestKubernetesResourceState_HasDiff/owner_ids_differ_in_content,_same_length
--- FAIL: TestKubernetesResourceState_HasDiff/parent_ids_differ_in_content,_same_length

Passes with the fix. go test ./pkg/model/... passes, go build ./... is clean.

Which issue(s) this PR fixes:

Fixes #7135

Does this PR introduce a user-facing change?:

  • How are users affected by this change: a resource whose owner or parent changes is now correctly reported as changed in the live state, instead of appearing unchanged.
  • Is this breaking change: No

HasDiff is supposed to tell the caller whether a Kubernetes resource's
state changed, so piped knows whether to report an update. For every
other field (ApiVersion, Namespace, HealthStatus, HealthDescription)
a mismatch correctly returns true. For OwnerIds and ParentIds, a
mismatch returns false instead - the exact opposite of what the rest
of the function does.

Practical effect: when a resource's owner or parent changes (for
example a Pod getting picked up by a different ReplicaSet during a
rolling update), HasDiff says nothing changed, so the update is never
reported and the stored live state keeps showing the old relationship.

Added a table test covering this case; it fails on the current code
and passes with the fix.

Signed-off-by: Vipul Subhash Pandey <vipulpandey7917@gmail.com>
@vipulpandey21
vipulpandey21 requested a review from a team as a code owner August 5, 2026 12:59
@netlify

netlify Bot commented Aug 22, 2026

Copy link
Copy Markdown

Deploy Preview for pipecd-site canceled.

Name Link
🔨 Latest commit 6762a37
🔍 Latest deploy log https://app.netlify.com/projects/pipecd-site/deploys/6a89257abc1c3d0009ec9549

Comment thread pkg/model/application_live_state.go
@khanhtc1202

Copy link
Copy Markdown
Member

Good catch, I left a comment 👍

@khanhtc1202 khanhtc1202 left a comment

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.

Good catch, I almost forgot about this line 😅

@khanhtc1202
khanhtc1202 merged commit 8c4c9ac into pipe-cd:master Aug 22, 2026
64 checks passed
@vipulpandey21

Copy link
Copy Markdown
Contributor Author

Hi Khanh sir, thanks for double-checking the sort order instead of just taking the fix at face value. Appreciate you tracing it back to state.go rather than trusting the comparison blind. Good to have this one closed out, especially since it had been sitting unchanged since 2020.

srinivasr pushed a commit to srinivasr/pipecd that referenced this pull request Aug 24, 2026
pipe-cd#7137)

HasDiff is supposed to tell the caller whether a Kubernetes resource's
state changed, so piped knows whether to report an update. For every
other field (ApiVersion, Namespace, HealthStatus, HealthDescription)
a mismatch correctly returns true. For OwnerIds and ParentIds, a
mismatch returns false instead - the exact opposite of what the rest
of the function does.

Practical effect: when a resource's owner or parent changes (for
example a Pod getting picked up by a different ReplicaSet during a
rolling update), HasDiff says nothing changed, so the update is never
reported and the stored live state keeps showing the old relationship.

Added a table test covering this case; it fails on the current code
and passes with the fix.

Signed-off-by: Vipul Subhash Pandey <vipulpandey7917@gmail.com>
Co-authored-by: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com>
srinivasr added a commit to srinivasr/pipecd that referenced this pull request Aug 24, 2026
The test added in pipe-cd#7137 passes struct values to HasDiff; adapt it to
the pointer-receiver signature used by this branch, following the same
index-loop style as the other model tests here.

Signed-off-by: srinivasr <sriniv4sreddy@gmail.com>
srinivasr added a commit to srinivasr/pipecd that referenced this pull request Aug 24, 2026
Cover the OwnerIds/ParentIds mismatch cases fixed on master (pipe-cd#7137),
written against the pointer-receiver signature used by this branch.

Signed-off-by: srinivasr <sriniv4sreddy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HasDiff returns false when a resource's OwnerIds or ParentIds actually changed

2 participants