-
Notifications
You must be signed in to change notification settings - Fork 183
Execute git clean partially when drift detection for every app is done #5312
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
Conversation
Signed-off-by: Yoshiki Fujikane <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5312 +/- ##
==========================================
- Coverage 25.27% 25.26% -0.01%
==========================================
Files 444 444
Lines 47516 47554 +38
==========================================
+ Hits 12010 12016 +6
- Misses 34563 34596 +33
+ Partials 943 942 -1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
pkg/git/repo.go
Outdated
@@ -259,6 +260,15 @@ func (r repo) Clean() error { | |||
return os.RemoveAll(r.dir) | |||
} | |||
|
|||
// CleanPartially deletes data in the given relative path in the repo with git clean. | |||
func (r repo) CleanPartially(ctx context.Context, relativePath string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh I think partially
is not suitable for the function name; how about renaming it CleanPath
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@khanhtc1202
Thank you, got it. Fixed in ab2b33c
Signed-off-by: Yoshiki Fujikane <[email protected]>
@@ -259,6 +260,15 @@ func (r repo) Clean() error { | |||
return os.RemoveAll(r.dir) | |||
} | |||
|
|||
// CleanPath deletes data in the given relative path in the repo with git clean. | |||
func (r repo) CleanPath(ctx context.Context, relativePath string) error { | |||
out, err := r.runGitCommand(ctx, "clean", "-f", relativePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Since this is a relative path, do we need to check whether the given path points to an under dir or outer dir? (If it contains ../
or /,
can the git clean command handle it carefully?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@khanhtc1202
git clean command checks whether the path is under the repo or not.
So IMO, we don't need the check. WDYT?
~/oss/pipe-cd/pipecd [fujiwo]
% git clean -f ../tutorial
fatal: ../tutorial: '../tutorial' is outside repository at '$HOME/oss/pipe-cd/pipecd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 I tried git clean
at repo2 with both relative and absolute path.
at ~/test/repo2
% git clean -f ../repo1/
fatal: ../repo1/: '../repo1/' is outside repository at '/$HOME/test/repo2'
at ~/test/repo2
% git clean -f /$HOME/test/repo1
fatal: /$HOME/test/repo1: '/$HOME/test/repo1' is outside repository at '/$HOME/test/repo2'
% tree .
.
├── repo1
│ └── README.md
├── repo2
└── README.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also added the test case for them f1ef1a9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's nice 👍
Signed-off-by: Yoshiki Fujikane <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@Warashi Sorry, plz re-approve 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
#5312) * Execute git clean partially when drift detection for every app is done Signed-off-by: Yoshiki Fujikane <[email protected]> * Rename to CleanPath Signed-off-by: Yoshiki Fujikane <[email protected]> * Add test for the outside dir pattern Signed-off-by: Yoshiki Fujikane <[email protected]> --------- Signed-off-by: Yoshiki Fujikane <[email protected]> Signed-off-by: pipecd-bot <[email protected]>
* Add event context (#5295) * Add contexts to the RegisterEventRequest Signed-off-by: Yoshiki Fujikane <[email protected]> * Add contexts to model.Event Signed-off-by: Yoshiki Fujikane <[email protected]> * Store event context in Control Plane Signed-off-by: Yoshiki Fujikane <[email protected]> * Add trailers when commiting on event watcher Signed-off-by: Yoshiki Fujikane <[email protected]> * Fix for failed build Signed-off-by: Yoshiki Fujikane <[email protected]> --------- Signed-off-by: Yoshiki Fujikane <[email protected]> Signed-off-by: pipecd-bot <[email protected]> * Add docs for pipectl event register --contexts on the event watcher usage page (#5299) * Add docs for pipectl event register --contexts on the event watcher usage page Signed-off-by: Yoshiki Fujikane <[email protected]> * Fix docs Signed-off-by: Yoshiki Fujikane <[email protected]> * Fix command Signed-off-by: Yoshiki Fujikane <[email protected]> --------- Signed-off-by: Yoshiki Fujikane <[email protected]> Signed-off-by: pipecd-bot <[email protected]> * Clone manifests not to modify original manifests (#5306) Signed-off-by: t-kikuc <[email protected]> Signed-off-by: pipecd-bot <[email protected]> * Lambda: clone manifests not to modify original manifests (#5308) Signed-off-by: t-kikuc <[email protected]> Signed-off-by: pipecd-bot <[email protected]> * Skip commit and push when no replacement happens in EventWatcher (#5310) * fix: skip push if no diff exist Signed-off-by: t-kikuc <[email protected]> * modify message Signed-off-by: t-kikuc <[email protected]> * refactor: use noChange variable Signed-off-by: t-kikuc <[email protected]> --------- Signed-off-by: t-kikuc <[email protected]> Signed-off-by: pipecd-bot <[email protected]> * Execute git clean partially when drift detection for every app is done (#5312) * Execute git clean partially when drift detection for every app is done Signed-off-by: Yoshiki Fujikane <[email protected]> * Rename to CleanPath Signed-off-by: Yoshiki Fujikane <[email protected]> * Add test for the outside dir pattern Signed-off-by: Yoshiki Fujikane <[email protected]> --------- Signed-off-by: Yoshiki Fujikane <[email protected]> Signed-off-by: pipecd-bot <[email protected]> * Update RELEASE and docs to v0.49.3 (#5315) Signed-off-by: Yoshiki Fujikane <[email protected]> Signed-off-by: pipecd-bot <[email protected]> --------- Signed-off-by: Yoshiki Fujikane <[email protected]> Signed-off-by: pipecd-bot <[email protected]> Signed-off-by: t-kikuc <[email protected]> Co-authored-by: Yoshiki Fujikane <[email protected]> Co-authored-by: Tetsuya Kikuchi <[email protected]>
What this PR does:
Fixed to execute
git clean -f
for every app dir after doing k8s drift detection.Why we need it:
During drift detection, a Git repository is cloned and reused, and a common manifest cache is utilized for various operations like drift detection, plan preview, plan, and deploy.
If an incorrect manifest is cached, it can affect other processes. When running kustomize build --enable-helm, a charts directory is created, and the Helm chart is downloaded locally.
However, before kustomize v5.3.0, this directory is not updated if the Helm chart version in kustomization.yaml changes, causing drift detection to load outdated manifests.
These manifests are cached based on commit hash, leading to incorrect manifests being applied during Plan or Deploy if the same commit hash is used.
For the context, see #5124 (comment)
Which issue(s) this PR fixes:
Fixes #5124
Does this PR introduce a user-facing change?: