-
Notifications
You must be signed in to change notification settings - Fork 208
Change to spawn image watcher workers for each git repository #1270
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
|
Code coverage for golang is
|
| return fmt.Errorf("unknown image provider %s is defined", target.Provider) | ||
| } | ||
| cfg, ok, err := config.LoadImageWatcher(repo.GetPath(), includes, excludes) | ||
| provider, err := imageprovider.NewProvider(&providerCfg, w.logger) |
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.
Initially, I was thinking about making clients singletons but stopped doing so.
ECR client looks not to do write operation to itself. But the investigation for others hasn't done yet. So for their safety, I decided to create clients every time for now.
|
|
||
| // Periodically update this cloned directory as long as this worker continues. | ||
| repo, err := w.gitClient.Clone(ctx, repoCfg.RepoID, repoCfg.Remote, repoCfg.Branch, "") | ||
| if err != nil { |
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.
When one of the goroutine stops due to this error, should we cancel all of the others?
Currently, this one is stopped and the other ones still running and just an error was logged.
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.
Right, we should ensure all workers properly start running. Using sync/errgroup would be better.
| return fmt.Errorf("failed to create a new temporary directory: %w", err) | ||
| } | ||
| defer os.RemoveAll(tmpDir) | ||
| repo, err := w.gitClient.Clone(ctx, repoCfg.RepoID, repoCfg.Remote, repoCfg.Branch, tmpDir) |
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.
repo.Copy may be better. Because cloning is retrieving a new git tree. The commit-tree could be added from the last pull.
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.
Yup, definitely right.
| for _, target := range cfg.Targets { | ||
| if err := w.updateOutdatedImage(ctx, &target, repoCfg, repo.GetPath(), commitMsg); err != nil { | ||
| w.logger.Error("failed to update image", | ||
| zap.String("repo-id", repoCfg.RepoID), |
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.
Instead of checking and updating for each target, how about checking and adding the commit for each target and then pushing once after all.
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.
Thank you. That way can reduce the number of pushing to git. But I'm a bit worried about the commit will be unclear. Including all changes into a single commit may make it tough to revert
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 know this is mainly for dev environment, but just warried.
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.
No, we add multiple commits (each commit for each change) and push after all.
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.
Ah, now I can understand. For that, we should share a temporary directory between all targets, but it looks like no problem to do.
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.
Thank you! It looks the best way!
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.
👍
|
@nghialv Fixed them! PTAL 😄 |
|
Code coverage for golang is
|
| } | ||
| cfg, ok, err := config.LoadImageWatcher(repo.GetPath(), includes, excludes) | ||
| defer os.RemoveAll(tmpDir) | ||
| tmpRepo, err := repo.Copy(tmpDir) |
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.
This Copy is done every 5 minutes even if there are no images to update.
I think it is a waste.
It would be better to check the outdated images based on the original read-only repo and then if there are any images to update, let copy to do.
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.
Right, will fix it.
|
@nghialv Thank you for your polite review! Could you take a look again? |
|
Code coverage for golang is
|
|
/hold |
| if !ok { | ||
| return nil, fmt.Errorf("configuration file for Image Watcher not found: %w", err) | ||
| for _, c := range commits { | ||
| err := tmpRepo.CommitChanges(ctx, tmpRepo.GetClonedBranch(), commitMsg, false, map[string][]byte{ |
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.
dumb, c.message should be used.
|
/hold cancel |
|
Code coverage for golang is
|
|
I have just left some suggestions. Please check again. |
Co-authored-by: Le Van Nghia <[email protected]>
Co-authored-by: Le Van Nghia <[email protected]>
|
The golinter build is completed with FAILURE. The build will be triggered again when you push any other commits. Or you can trigger it manually by You can check the build log from here. |
|
The golinter build is completed with FAILURE. The build will be triggered again when you push any other commits. Or you can trigger it manually by You can check the build log from here. |
|
The golinter build is completed with FAILURE. The build will be triggered again when you push any other commits. Or you can trigger it manually by You can check the build log from here. |
Co-authored-by: Le Van Nghia <[email protected]>
|
The golinter build is completed with FAILURE. The build will be triggered again when you push any other commits. Or you can trigger it manually by You can check the build log from here. |
|
The following files are not gofmt-ed. By commenting pkg/app/piped/imagewatcher/watcher.go--- pkg/app/piped/imagewatcher/watcher.go.orig
+++ pkg/app/piped/imagewatcher/watcher.go
@@ -36,7 +36,7 @@
const (
defaultCommitMessageFormat = "Update image %s to %s defined at %s in %s"
- defaultCheckInterval = 5 * time.Minute
+ defaultCheckInterval = 5 * time.Minute
)
type Watcher interface {
@@ -102,7 +102,7 @@
defer w.wg.Done()
var (
- checkInterval = defaultCheckInterval
+ checkInterval = defaultCheckInterval
commitMsg string
includedCfgs, excludedCfgs []string
)
|
|
/golinter fmt |
|
Fixed done! |
|
Nice. |
|
Code coverage for golang is
|
|
/approve cancel |
|
LOL |
|
haha |
|
🚀 |
What this PR does / why we need it:
This PR makes the worker's unit git repository. Due to this, it changes to use another directory to touch the image.
Which issue(s) this PR fixes:
Fixes #1261
Fixes #1262
Fixes #1263
Does this PR introduce a user-facing change?: