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

Implement the sync state calculation for the kubernetes livestate plugin #5676

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Warashi
Copy link
Contributor

@Warashi Warashi commented Mar 17, 2025

What this PR does:

as title

Why we need it:

We want to support DriftDetection feature with k8s plugin

Which issue(s) this PR fixes:

Part of #5363

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

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

Copy link

codecov bot commented Mar 17, 2025

Codecov Report

Attention: Patch coverage is 41.55844% with 45 lines in your changes missing coverage. Please review.

Project coverage is 25.69%. Comparing base (317a7c9) to head (9d2d19c).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
.../app/pipedv1/plugin/kubernetes/livestate/plugin.go 41.55% 44 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5676      +/-   ##
==========================================
- Coverage   25.73%   25.69%   -0.04%     
==========================================
  Files         478      474       -4     
  Lines       51400    50981     -419     
==========================================
- Hits        13230    13102     -128     
+ Misses      37166    36888     -278     
+ Partials     1004      991      -13     

☔ 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.

Warashi added 3 commits March 17, 2025 17:02
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
}, nil
}

func calculateSyncState(diffResult *provider.DiffListResult, commit string) sdk.ApplicationSyncState {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reference implementation is here

func makeSyncState(r *provider.DiffListResult, commit string) model.ApplicationSyncState {
if r.NoChange() {
return model.ApplicationSyncState{
Status: model.ApplicationSyncStatus_SYNCED,
ShortReason: "",
Reason: "",
Timestamp: time.Now().Unix(),
}
}
total := len(r.Adds) + len(r.Deletes) + len(r.Changes)
shortReason := fmt.Sprintf("There are %d manifests not synced (%d adds, %d deletes, %d changes)", total, len(r.Adds), len(r.Deletes), len(r.Changes))
if len(commit) >= 7 {
commit = commit[:7]
}
var b strings.Builder
b.WriteString(fmt.Sprintf("Diff between the defined state in Git at commit %s and actual state in cluster:\n\n", commit))
b.WriteString("--- Actual (LiveState)\n+++ Expected (Git)\n\n")
details := r.Render(provider.DiffRenderOptions{
MaskSecret: true,
MaskConfigMap: true,
MaxChangedManifests: 3,
// Currently, we do not use the diff command to render the result
// because Kubernetes adds a large number of default values to the
// running manifest that causes a wrong diff text.
UseDiffCommand: false,
})
b.WriteString(details)
return model.ApplicationSyncState{
Status: model.ApplicationSyncStatus_OUT_OF_SYNC,
ShortReason: shortReason,
Reason: b.String(),
Timestamp: time.Now().Unix(),
}
}

@Warashi Warashi marked this pull request as ready for review March 18, 2025 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant