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

Ensure to watch image from image providers #1117

Merged
merged 9 commits into from Dec 8, 2020
Merged

Conversation

nakabonne
Copy link
Member

@nakabonne nakabonne commented Nov 18, 2020

What this PR does / why we need it:
Base implementation of #1114.

Sorry for the huge patch. I'd be happy to work on tiny issues respectively after this.

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

NONE

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

pkg/app/piped/imageprovider/gcr/gcr.go Outdated Show resolved Hide resolved
pkg/app/piped/imageprovider/gcr/gcr.go Outdated Show resolved Hide resolved
pkg/app/piped/imagewatcher/watcher.go Outdated Show resolved Hide resolved
pkg/config/image_watcher.go Outdated Show resolved Hide resolved
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.01%. This pull request decreases coverage by -0.05%.

File Function Base Head Diff
pkg/config/image_watcher.go LoadImageWatcher -- 0.00% +0.00%
pkg/config/image_watcher.go ImageWatcherSpec.Validate -- 0.00% +0.00%
pkg/model/image_name.go ImageName.String -- 0.00% +0.00%
pkg/model/image_name.go ImageRef.String -- 0.00% +0.00%
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 55.56% 57.14% +1.59%
pkg/config/config.go Config.init 66.67% 60.87% -5.80%

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

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

pkg/model/image_name.go Outdated Show resolved Hide resolved
pkg/app/piped/imageprovider/provider.go Show resolved Hide resolved
pkg/app/piped/imagewatcher/watcher.go Show resolved Hide resolved
pkg/config/image_watcher.go Outdated Show resolved Hide resolved
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.89%. This pull request decreases coverage by -0.05%.

File Function Base Head Diff
pkg/config/image_watcher.go LoadImageWatcher -- 0.00% +0.00%
pkg/config/image_watcher.go ImageWatcherSpec.Validate -- 0.00% +0.00%
pkg/model/image_name.go ImageName.String -- 0.00% +0.00%
pkg/model/image_name.go ImageName.Name -- 0.00% +0.00%
pkg/model/image_name.go ImageRef.String -- 0.00% +0.00%
pkg/config/config.go Config.init 66.67% 60.87% -5.80%
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 55.56% 57.14% +1.59%

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

pkg/app/piped/imageprovider/provider.go Show resolved Hide resolved
pkg/app/piped/imagewatcher/watcher.go Show resolved Hide resolved
pkg/config/image_watcher.go Outdated Show resolved Hide resolved
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.89%. This pull request decreases coverage by -0.05%.

File Function Base Head Diff
pkg/config/image_watcher.go LoadImageWatcher -- 0.00% +0.00%
pkg/config/image_watcher.go ImageWatcherSpec.Validate -- 0.00% +0.00%
pkg/model/image_name.go ImageName.String -- 0.00% +0.00%
pkg/model/image_name.go ImageName.Name -- 0.00% +0.00%
pkg/model/image_name.go ImageRef.String -- 0.00% +0.00%
pkg/config/config.go Config.init 66.67% 60.87% -5.80%
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 55.56% 57.14% +1.59%

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

pkg/app/piped/imageprovider/provider.go Show resolved Hide resolved
pkg/app/piped/imagewatcher/watcher.go Show resolved Hide resolved
pkg/config/image_watcher.go Outdated Show resolved Hide resolved
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.90%. This pull request decreases coverage by -0.05%.

File Function Base Head Diff
pkg/config/image_watcher.go LoadImageWatcher -- 0.00% +0.00%
pkg/config/image_watcher.go ImageWatcherSpec.Validate -- 0.00% +0.00%
pkg/model/image_name.go ImageName.String -- 0.00% +0.00%
pkg/model/image_name.go ImageName.Name -- 0.00% +0.00%
pkg/model/image_name.go ImageRef.String -- 0.00% +0.00%
pkg/config/config.go Config.init 66.67% 60.87% -5.80%
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 55.56% 57.14% +1.59%

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

pkg/app/piped/imageprovider/provider.go Show resolved Hide resolved
pkg/app/piped/imagewatcher/watcher.go Show resolved Hide resolved
pkg/config/image_watcher.go Outdated Show resolved Hide resolved
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.98%. This pull request increases coverage by 0.03%.

File Function Base Head Diff
pkg/config/image_watcher.go LoadImageWatcher -- 0.00% +0.00%
pkg/config/image_watcher.go ImageWatcherSpec.Validate -- 0.00% +0.00%
pkg/model/image_name.go ImageName.String -- 0.00% +0.00%
pkg/model/image_name.go ImageName.Name -- 0.00% +0.00%
pkg/model/image_name.go ImageRef.String -- 0.00% +0.00%
pkg/config/config.go Config.init 66.67% 60.87% -5.80%
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 55.56% 85.71% +30.16%

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

pkg/app/piped/imageprovider/provider.go Show resolved Hide resolved
pkg/app/piped/imagewatcher/watcher.go Show resolved Hide resolved
pkg/config/image_watcher.go Outdated Show resolved Hide resolved
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.30%. This pull request increases coverage by 0.03%.

File Function Base Head Diff
pkg/config/image_watcher.go LoadImageWatcher -- 0.00% +0.00%
pkg/config/image_watcher.go ImageWatcherSpec.Validate -- 0.00% +0.00%
pkg/model/image_name.go ImageName.String -- 0.00% +0.00%
pkg/model/image_name.go ImageName.Name -- 0.00% +0.00%
pkg/model/image_name.go ImageRef.String -- 0.00% +0.00%
pkg/config/config.go Config.init 66.67% 60.87% -5.80%
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 55.56% 85.71% +30.16%

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

pkg/app/piped/imageprovider/provider.go Show resolved Hide resolved
pkg/app/piped/imagewatcher/watcher.go Show resolved Hide resolved
pkg/config/image_watcher.go Outdated Show resolved Hide resolved
"github.com/pipe-cd/pipe/pkg/model"
)

// Provider acs as a container registry client.
Copy link
Member

Choose a reason for hiding this comment

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

nit: acts

Repo string
}

func (i ImageName) String() string {
Copy link
Member

Choose a reason for hiding this comment

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

return path.Join(i.Domain, i.Repo)

if i.Tag != "" {
tag = ":" + i.Tag
}
return fmt.Sprintf("%s%s", i.ImageName.String(), tag)
Copy link
Member

Choose a reason for hiding this comment

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

nit:

if i.Tag == "" {
    return i.ImageName.String()
}

return fmt.Sprintf("%s:%s", i.ImageTag.String(), i.Tag)

Name string `json:"name"`
Type model.ImageProviderType `json:"type"`
// Default is five minute.
PullInterval Duration `json:"pullInterval"`

DockerhubConfig *ImageProviderDockerhubConfig
GCRConfig *ImageProviderGCRConfig
ECRConfig *ImageProviderECRConfig
}

type genericPipedImageProvider struct {
Copy link
Member

Choose a reason for hiding this comment

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

line 384: Dockerhub -> DockerHub

switch cfg.Type {
case model.ImageProviderTypeGCR:
return gcr.NewProvider(cfg.Name, cfg.GCRConfig, doChallenge, logger)
case model.ImageProviderTypeDockerhub:
Copy link
Member

Choose a reason for hiding this comment

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

Dockerhub -> DockerHub

Type model.ImageProviderType
Name string `json:"name"`
Type model.ImageProviderType `json:"type"`
// Default is five minute.
Copy link
Member

Choose a reason for hiding this comment

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

nit: 5m (to be same with the specifying in the config file)

if err != nil {
return nil, err
}
_, err = repository.Tags(ctx).All(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

As they described:

For repositories with a large number of tags, this response may be quite large. If such a response is expected, one should use the pagination.

https://docs.docker.com/registry/spec/api/#listing-image-tags

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for the lack of description, the implementation of GCR is still WIP, and we decided to prioritize ECR over GCR. So will just leave TODO comments.


go w.run(ctx, p, cfg.PullInterval.Duration())
}
return nil
Copy link
Member

Choose a reason for hiding this comment

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

This is exited immediately after starting goroutines for all image providers.
Please ensure that all of its child tasks must be stopped before exiting.

}
includes = append(includes, target.Includes...)
excludes = append(excludes, target.Excludes...)
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: Instead of finding and saving these include/exclude list, just finding and marking the target.

Copy link
Member Author

Choose a reason for hiding this comment

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

return true
}
branch := repo.GetClonedBranch()
if err := repo.Pull(ctx, branch); 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.

git.Repo is a pointer and pointing to the same disk location of git data.
This Pull can be called from multiple goroutines and may cause a data race.

@nghialv
Copy link
Member

nghialv commented Dec 7, 2020

@nakabonne Reviewing is not finished yet, but please check the comments.

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

pkg/model/imageprovider.go Outdated Show resolved Hide resolved
@nakabonne
Copy link
Member Author

@nghialv Fixed. Could you take a look?

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.38%. This pull request increases coverage by 0.10%.

File Function Base Head Diff
pkg/config/image_watcher.go LoadImageWatcher -- 0.00% +0.00%
pkg/config/image_watcher.go ImageWatcherSpec.Validate -- 0.00% +0.00%
pkg/model/image_name.go ImageName.String -- 100.00% +100.00%
pkg/model/image_name.go ImageName.Name -- 0.00% +0.00%
pkg/model/image_name.go ImageRef.String -- 100.00% +100.00%
pkg/config/config.go Config.init 66.67% 60.87% -5.80%
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 55.56% 85.71% +30.16%

@@ -17,7 +17,7 @@ package model
type ImageProviderType string

const (
ImageProviderTypeDockerhub ImageProviderType = "DOCKERHUB"
ImageProviderTypeDockerHub ImageProviderType = "DOCKERHUB"
Copy link
Member

Choose a reason for hiding this comment

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

DOCKER_HUB

mu sync.Mutex

// Indexed by repo id.
gitRepos sync.Map
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why do we need to use a sync map instead of a normal map?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, you're right. A map can be read when it's being read. Gonna fix them.

@pipecd-bot
Copy link
Collaborator

TODO

The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use /todo skip command.

Details

1. Stop listing all tags

https://github.com/pipe-cd/pipe/blob/dc28c17cdf7b385830ef789b0e00d907b47f5196/pkg/app/piped/imageprovider/gcr/gcr.go#L90-L93

This was created by todo plugin since "TODO:" was found in dc28c17 when #1117 was merged. cc: @nakabonne.

2. Give back latest image from GCR

https://github.com/pipe-cd/pipe/blob/dc28c17cdf7b385830ef789b0e00d907b47f5196/pkg/app/piped/imageprovider/gcr/gcr.go#L95-L98

This was created by todo plugin since "TODO:" was found in dc28c17 when #1117 was merged. cc: @nakabonne.

3. Use credentials for GCR configured by user

https://github.com/pipe-cd/pipe/blob/dc28c17cdf7b385830ef789b0e00d907b47f5196/pkg/app/piped/imageprovider/gcr/gcr.go#L100-L103

This was created by todo plugin since "TODO:" was found in dc28c17 when #1117 was merged. cc: @nakabonne.

4. Handle the no challenge case

https://github.com/pipe-cd/pipe/blob/dc28c17cdf7b385830ef789b0e00d907b47f5196/pkg/app/piped/imageprovider/provider.go#L68-L71

This was created by todo plugin since "TODO:" was found in dc28c17 when #1117 was merged. cc: @nakabonne.

5. Control not to reach the rate limit

https://github.com/pipe-cd/pipe/blob/dc28c17cdf7b385830ef789b0e00d907b47f5196/pkg/app/piped/imagewatcher/watcher.go#L173-L176

This was created by todo plugin since "TODO:" was found in dc28c17 when #1117 was merged. cc: @nakabonne.

6. Compares between image repos in the image registry and image repos in git

https://github.com/pipe-cd/pipe/blob/dc28c17cdf7b385830ef789b0e00d907b47f5196/pkg/app/piped/imagewatcher/watcher.go#L178-L181

This was created by todo plugin since "TODO:" was found in dc28c17 when #1117 was merged. cc: @nakabonne.

7. Make it possible to push outdated images to Git

https://github.com/pipe-cd/pipe/blob/dc28c17cdf7b385830ef789b0e00d907b47f5196/pkg/app/piped/imagewatcher/watcher.go#L186-L188

This was created by todo plugin since "TODO:" was found in dc28c17 when #1117 was merged. cc: @nakabonne.

8. Load image watcher config

https://github.com/pipe-cd/pipe/blob/dc28c17cdf7b385830ef789b0e00d907b47f5196/pkg/config/image_watcher.go#L31-L34

This was created by todo plugin since "TODO:" was found in dc28c17 when #1117 was merged. cc: @nakabonne.

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

pkg/model/imageprovider.go Show resolved Hide resolved
@nakabonne
Copy link
Member Author

@nghialv I really appreciate your polite review. Please take a look again 😄

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.38%. This pull request increases coverage by 0.10%.

File Function Base Head Diff
pkg/config/image_watcher.go LoadImageWatcher -- 0.00% +0.00%
pkg/config/image_watcher.go ImageWatcherSpec.Validate -- 0.00% +0.00%
pkg/model/image_name.go ImageName.String -- 100.00% +100.00%
pkg/model/image_name.go ImageName.Name -- 0.00% +0.00%
pkg/model/image_name.go ImageRef.String -- 100.00% +100.00%
pkg/config/config.go Config.init 66.67% 60.87% -5.80%
pkg/config/piped.go PipedImageProvider.UnmarshalJSON 55.56% 85.71% +30.16%

@nghialv nghialv changed the title Ensure to call image providers periodically Ensure to watch image from image providers Dec 8, 2020
@nghialv
Copy link
Member

nghialv commented Dec 8, 2020

Nice.
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by nghialv.

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.

@nakabonne
Copy link
Member Author

Thanks 😃

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.

None yet

3 participants