Skip to content

Conversation

@Warashi
Copy link
Member

@Warashi Warashi commented Aug 22, 2024

What this PR does / why we need it:

Normalize both old and new manifests when calculating diff.

Without this PR, the unexpected difference is calculated when resource/limit numbers have floating-point values such as cpu: "1.5"
The diff signs 1.5 and 1500m are different.
This occurs because the new manifests are normalized, but the old ones are not.

Which issue(s) this PR fixes:

N/A

Does this PR introduce a user-facing change?: Yes

  • How are users affected by this change:
    Users can get the correct plan-preview diffs.
    Some deployments triggered by incorrect diffs become not triggered.

  • Is this breaking change:

  • How to migrate (if breaking change):

Signed-off-by: Shinnosuke Sawada <[email protected]>
Signed-off-by: Shinnosuke Sawada <[email protected]>
Signed-off-by: Shinnosuke Sawada <[email protected]>
Signed-off-by: Shinnosuke Sawada <[email protected]>
normalize both of old and new manifests

Signed-off-by: Shinnosuke Sawada <[email protected]>
Signed-off-by: Shinnosuke Sawada <[email protected]>
@codecov
Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Project coverage is 22.82%. Comparing base (c0d5b79) to head (ead1e14).
Report is 597 commits behind head on master.

Files with missing lines Patch % Lines
pkg/app/piped/platformprovider/kubernetes/diff.go 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5154      +/-   ##
==========================================
+ Coverage   22.79%   22.82%   +0.02%     
==========================================
  Files         412      412              
  Lines       43827    43833       +6     
==========================================
+ Hits         9992    10003      +11     
+ Misses      33047    33040       -7     
- Partials      788      790       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Warashi Warashi enabled auto-merge (squash) August 22, 2024 01:39
Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

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

Thank you! This is the nice improvement!
I left nit comments.

Comment on lines +555 to +569
for _, change := range result.Changes {
t.Log(change.Old.Key, change.New.Key)
for _, node := range change.Diff.Nodes() {
t.Log(node.PathString)
t.Log(node.ValueX)
t.Log(node.ValueY)
t.Log("---")
}
}
for _, add := range result.Adds {
t.Log(add.Key)
}
for _, delete := range result.Deletes {
t.Log(delete.Key)
}
Copy link
Member

Choose a reason for hiding this comment

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

[ask] This codes are for checking the diff when result.NoChange() is false?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, and these are logs for debugging, not assertions.


normalizedOld, err := remarshal(old.u)
if err != nil {
logger.Info("compare manifests directly since it was unable to remarshal Kubernetes manifest to normalize special fields", zap.Error(err))
Copy link
Member

Choose a reason for hiding this comment

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

[nit] It would be nice to show old or new when investigating with this log.
It is the same for the remarshal new one.

Suggested change
logger.Info("compare manifests directly since it was unable to remarshal Kubernetes manifest to normalize special fields", zap.Error(err))
logger.Info("compare manifests directly since it was unable to remarshal old Kubernetes manifest to normalize special fields", zap.Error(err))

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed by this commit
ead1e14

khanhtc1202
khanhtc1202 previously approved these changes Aug 22, 2024
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

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

Nice catch, thank you 👍

Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

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

🚀

Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

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

ready to go 🚀

@Warashi Warashi merged commit c24ce35 into master Aug 22, 2024
@Warashi Warashi deleted the kustomize-limits-diff branch August 22, 2024 02:11
@github-actions github-actions bot mentioned this pull request Aug 26, 2024
github-actions bot pushed a commit that referenced this pull request Aug 26, 2024
* Add TestLoadAndDiff

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Make testcase smaller

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Separate test cases

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Add test cases

Signed-off-by: Shinnosuke Sawada <[email protected]>

* FIx the k8s diff

normalize both of old and new manifests

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Rename the testcase

Signed-off-by: Shinnosuke Sawada <[email protected]>

---------

Signed-off-by: Shinnosuke Sawada <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>
@github-actions github-actions bot mentioned this pull request Aug 26, 2024
github-actions bot pushed a commit that referenced this pull request Aug 26, 2024
* Add TestLoadAndDiff

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Make testcase smaller

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Separate test cases

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Add test cases

Signed-off-by: Shinnosuke Sawada <[email protected]>

* FIx the k8s diff

normalize both of old and new manifests

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Rename the testcase

Signed-off-by: Shinnosuke Sawada <[email protected]>

---------

Signed-off-by: Shinnosuke Sawada <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>
Warashi added a commit that referenced this pull request Aug 26, 2024
* Add note to RELEASE file (#5149)

Signed-off-by: khanhtc1202 <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>

* Fix the kubernetes manifest diff (#5154)

* Add TestLoadAndDiff

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Make testcase smaller

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Separate test cases

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Add test cases

Signed-off-by: Shinnosuke Sawada <[email protected]>

* FIx the k8s diff

normalize both of old and new manifests

Signed-off-by: Shinnosuke Sawada <[email protected]>

* Rename the testcase

Signed-off-by: Shinnosuke Sawada <[email protected]>

---------

Signed-off-by: Shinnosuke Sawada <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>

* Release v0.48.7 (#5157)

Signed-off-by: Shinnosuke Sawada <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>

---------

Signed-off-by: khanhtc1202 <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>
Signed-off-by: Shinnosuke Sawada <[email protected]>
Co-authored-by: Khanh Tran <[email protected]>
Co-authored-by: Shinnosuke Sawada-Dazai <[email protected]>
This was referenced Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants