Skip to content

Conversation

@nakabonne
Copy link
Member

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?:

NONE

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 34.28%. This pull request increases coverage by 0.00%.

File Function Base Head Diff
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 85.71% 88.89% +3.17%
pkg/config/piped.go PipedImageWatcher.Validate 100.00% 100.00% +0.00%

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)
Copy link
Member Author

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 {
Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

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),
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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!

Copy link
Member

Choose a reason for hiding this comment

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

👍

@nakabonne
Copy link
Member Author

@nghialv Fixed them! PTAL 😄

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 34.28%. This pull request increases coverage by 0.00%.

File Function Base Head Diff
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 85.71% 88.89% +3.17%
pkg/config/piped.go PipedImageWatcher.Validate 100.00% 100.00% +0.00%

}
cfg, ok, err := config.LoadImageWatcher(repo.GetPath(), includes, excludes)
defer os.RemoveAll(tmpDir)
tmpRepo, err := repo.Copy(tmpDir)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, will fix it.

@nakabonne
Copy link
Member Author

@nghialv Thank you for your polite review! Could you take a look again?

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 34.28%. This pull request increases coverage by 0.00%.

File Function Base Head Diff
pkg/config/piped.go PipedImageWatcher.Validate 100.00% 100.00% +0.00%
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 85.71% 88.89% +3.17%

@nakabonne
Copy link
Member Author

/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{
Copy link
Member Author

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.

@nakabonne
Copy link
Member Author

/hold cancel

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 34.28%. This pull request increases coverage by 0.00%.

File Function Base Head Diff
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 85.71% 88.89% +3.17%
pkg/config/piped.go PipedImageWatcher.Validate 100.00% 100.00% +0.00%

@nghialv
Copy link
Member

nghialv commented Dec 18, 2020

I have just left some suggestions. Please check again.

nakabonne and others added 2 commits December 18, 2020 10:55
Co-authored-by: Le Van Nghia <[email protected]>
Co-authored-by: Le Van Nghia <[email protected]>
@pipecd-bot
Copy link
Collaborator

GO_LINTER

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 /golinter trigger command right now.

You can check the build log from here.

@pipecd-bot
Copy link
Collaborator

GO_LINTER

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 /golinter trigger command right now.

You can check the build log from here.

@pipecd-bot
Copy link
Collaborator

GO_LINTER

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 /golinter trigger command right now.

You can check the build log from here.

@pipecd-bot
Copy link
Collaborator

GO_LINTER

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 /golinter trigger command right now.

You can check the build log from here.

@pipecd-bot
Copy link
Collaborator

GO_LINTER

The following files are not gofmt-ed. By commenting /golinter fmt, the formatted one will be appended to this pull request automatically.

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
 	)

@nakabonne
Copy link
Member Author

/golinter fmt

@nakabonne
Copy link
Member Author

Fixed done!

@nghialv
Copy link
Member

nghialv commented Dec 18, 2020

Nice.
/approve

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 34.28%. This pull request increases coverage by 0.00%.

File Function Base Head Diff
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 85.71% 88.89% +3.17%
pkg/config/piped.go PipedImageWatcher.Validate 100.00% 100.00% +0.00%

@nghialv
Copy link
Member

nghialv commented Dec 18, 2020

/approve cancel

@nghialv
Copy link
Member

nghialv commented Dec 18, 2020

LOL
/lgtm

@nakabonne
Copy link
Member Author

haha
/cc @khanhtc1202

@khanhtc1202
Copy link
Member

🚀
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by khanhtc1202.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit 7e2e9aa into master Dec 18, 2020
@pipecd-bot pipecd-bot deleted the watch-repo branch December 18, 2020 02:21
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.

Make it changeable the commit message Clone repository another temporary destination Spawn goroutines for each repository

5 participants