Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the kubernetes manifest diff #5154

Merged
merged 7 commits into from
Aug 22, 2024
Merged

Fix the kubernetes manifest diff #5154

merged 7 commits into from
Aug 22, 2024

Conversation

Warashi
Copy link
Contributor

@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 <6warashi9@gmail.com>
Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>
Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>
Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>
normalize both of old and new manifests

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>
Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>
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 116 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.

@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
Contributor 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
Contributor 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 👍

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>
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
18 checks passed
@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 <6warashi9@gmail.com>

* Make testcase smaller

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* Separate test cases

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* Add test cases

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* FIx the k8s diff

normalize both of old and new manifests

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* Rename the testcase

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

---------

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>
Signed-off-by: pipecd-bot <pipecd.dev@gmail.com>
@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 <6warashi9@gmail.com>

* Make testcase smaller

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* Separate test cases

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* Add test cases

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* FIx the k8s diff

normalize both of old and new manifests

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* Rename the testcase

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

---------

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>
Signed-off-by: pipecd-bot <pipecd.dev@gmail.com>
Warashi added a commit that referenced this pull request Aug 26, 2024
* Add note to RELEASE file (#5149)

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>
Signed-off-by: pipecd-bot <pipecd.dev@gmail.com>

* Fix the kubernetes manifest diff (#5154)

* Add TestLoadAndDiff

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* Make testcase smaller

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* Separate test cases

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* Add test cases

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* FIx the k8s diff

normalize both of old and new manifests

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

* Rename the testcase

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>

---------

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>
Signed-off-by: pipecd-bot <pipecd.dev@gmail.com>

* Release v0.48.7 (#5157)

Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>
Signed-off-by: pipecd-bot <pipecd.dev@gmail.com>

---------

Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>
Signed-off-by: pipecd-bot <pipecd.dev@gmail.com>
Signed-off-by: Shinnosuke Sawada <6warashi9@gmail.com>
Co-authored-by: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com>
Co-authored-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
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.

3 participants