-
Notifications
You must be signed in to change notification settings - Fork 208
Add configurations for Event watcher #1399
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
|
| replacements: | ||
| - file: app2/.pipe.yaml | ||
| yamlField: $.spec.input.helmChart.version | ||
| labels: |
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.
nit: Moving this labels to just above replacements.
pkg/config/piped.go
Outdated
| } | ||
|
|
||
| type PipedEventWatcher struct { | ||
| // Interval to fetch the latest event and compare it with one defined in replacement files. |
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.
"defined in EventWatcher config files."
pkg/config/piped.go
Outdated
|
|
||
| // Validate checks if: | ||
| // - empty repo ids exist | ||
| // - duplicated repository settings exist |
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.
nit: The detailed comments can be moved inside the function, right next to its code.
// Validate the existence of repo ID.
...
// Validate something else
...
pkg/config/piped.go
Outdated
| // - 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++ { |
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.
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"` |
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.
nit: Moving this to just after the Name?
I mean we have 2 parts: conditions for matching: name and labels and actions: replacements
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 don't exactly get what you said. Sorry but could you show me some examples of that?
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 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.
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 makes sense! I placed the Label field at the end because this is optional, but putting after Name is more readable in such case.
pkg/config/event_watcher.go
Outdated
|
|
||
| // 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. |
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.
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.
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.
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".
pkg/config/event_watcher.go
Outdated
| 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. |
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.
nit: "new event matches"
pkg/config/event_watcher.go
Outdated
|
|
||
| func (s *EventWatcherSpec) Validate() error { | ||
| if len(s.Events) == 0 { | ||
| return ErrNotFound |
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.
Events are required?
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 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 👍
|
The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use Details1. Support JSONField to replace values in json formatThis 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 formatThis 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 sameThis was created by todo plugin since "TODO:" was found in bca01b2 when #1399 was merged. cc: @nakabonne. |
|
@nghialv Thank you for your polite review. Fixed them. |
|
Code coverage for golang is
|
|
Nice. |
|
🚀 |
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?: