Skip to content

Conversation

@nakabonne
Copy link
Member

What this PR does / why we need it:
Most of the core logic is identical to ImageWatcher's one.

Which issue(s) this PR fixes:

Ref #1381

Does this PR introduce a user-facing change?:

NONE

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 34.13%. This pull request increases coverage by 0.33%.

File Function Base Head Diff
pkg/config/event_watcher.go LoadEventWatcher -- 72.73% +72.73%
pkg/config/event_watcher.go filterEventWatcherFiles -- 100.00% +100.00%
pkg/config/event_watcher.go EventWatcherSpec.Validate -- 87.50% +87.50%
pkg/config/piped.go PipedEventWatcher.Validate -- 0.00% +0.00%
pkg/config/analysis_template.go AnalysisTemplateSpec.Validate 0.00% 100.00% +100.00%
pkg/config/config.go Config.init 60.87% 80.00% +19.13%

replacements:
- file: app2/.pipe.yaml
yamlField: $.spec.input.helmChart.version
labels:
Copy link
Member

Choose a reason for hiding this comment

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

nit: Moving this labels to just above replacements.

}

type PipedEventWatcher struct {
// Interval to fetch the latest event and compare it with one defined in replacement files.
Copy link
Member

Choose a reason for hiding this comment

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

"defined in EventWatcher config files."


// Validate checks if:
// - empty repo ids exist
// - duplicated repository settings exist
Copy link
Member

Choose a reason for hiding this comment

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

nit: The detailed comments can be moved inside the function, right next to its code.

// Validate the existence of repo ID.
...

// Validate something else
...

// - duplicated repository settings exist
func (p *PipedEventWatcher) Validate() error {
repos := make(map[string]struct{}, len(p.GitRepos))
for i := 0; i < len(p.GitRepos); i++ {
Copy link
Member

Choose a reason for hiding this comment

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

nit:

for i, repo := range p.GitRepos {
   if repo.RepoID == "" {
        return fmt.Errorf("missing repoID at index %d"...
   }
}

Replacements []EventWatcherReplacement `json:"replacements"`
// Additional attributes of event. This can make an event definition
// unique even if the one with the same name exists.
Labels map[string]string `json:"labels"`
Copy link
Member

Choose a reason for hiding this comment

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

nit: Moving this to just after the Name?
I mean we have 2 parts: conditions for matching: name and labels and actions: replacements

Copy link
Member Author

@nakabonne nakabonne Jan 12, 2021

Choose a reason for hiding this comment

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

I don't exactly get what you said. Sorry but could you show me some examples of that?

Copy link
Member

Choose a reason for hiding this comment

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

I want to say that our configuration will have 2 groups:

  • first group is about how to match the event. This contains "name" and "labels"
  • second group is about how to handle when the event matches. This contains "replacements"

So I think we should change the order to group them for more readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense! I placed the Label field at the end because this is optional, but putting after Name is more readable in such case.


// EventWatcherEvent defines which file will be replaced when the given event happened.
type EventWatcherEvent struct {
// The event name. The combination of this name and labels must be unique within a project.
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this statement: "The combination of this name and labels must be unique within a project."
Because piped is only handling the events of its project.

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 confusion, as you feel this shouldn't be here.

I just mean that "if you use the same name across repositories, they affect each other. So you have to make that combination unique if you want to explicitly distinguish them".

type EventWatcherEvent struct {
// The event name. The combination of this name and labels must be unique within a project.
Name string `json:"name"`
// List of places where will be replaced when the new event found.
Copy link
Member

Choose a reason for hiding this comment

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

nit: "new event matches"


func (s *EventWatcherSpec) Validate() error {
if len(s.Events) == 0 {
return ErrNotFound
Copy link
Member

Choose a reason for hiding this comment

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

Events are required?

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 thought so because it looks wierd that no events despite the EventWatcher config file exists.

But on second thought, I realized it's not a problem to give back an EventWatcherSpec with no Events 👍

@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. Support JSONField to replace values in json format

https://github.com/pipe-cd/pipe/blob/bca01b2b92f52f91dae5161934642b3306a9bff4/pkg/config/event_watcher.go#L45-L48

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

2. Support HCLField to replace values in HCL format

https://github.com/pipe-cd/pipe/blob/bca01b2b92f52f91dae5161934642b3306a9bff4/pkg/config/event_watcher.go#L46-L49

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

3. Consider merging events if there are events whose combination of name and labels is the same

https://github.com/pipe-cd/pipe/blob/bca01b2b92f52f91dae5161934642b3306a9bff4/pkg/config/event_watcher.go#L133-L136

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

@nakabonne
Copy link
Member Author

@nghialv Thank you for your polite review. Fixed them.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 34.13%. This pull request increases coverage by 0.32%.

File Function Base Head Diff
pkg/config/event_watcher.go LoadEventWatcher -- 72.73% +72.73%
pkg/config/event_watcher.go filterEventWatcherFiles -- 100.00% +100.00%
pkg/config/event_watcher.go EventWatcherSpec.Validate -- 100.00% +100.00%
pkg/config/piped.go PipedEventWatcher.Validate -- 0.00% +0.00%
pkg/config/config.go Config.init 60.87% 80.00% +19.13%
pkg/config/analysis_template.go AnalysisTemplateSpec.Validate 0.00% 100.00% +100.00%

@nghialv
Copy link
Member

nghialv commented Jan 12, 2021

Nice.
/lgtm

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

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.

5 participants