feat: postsync hooks (#601)

`postsync` events are triggered after each release is applied to the cluster in `helmfile sync` or `helmfile apply`.

This should be a best hook to notify only after each sync failed or succeeded. This can be used for running operations like patching K8s resources managed by helm, but that should be the last-resort. Maybe you should fork/update the chart, or submit a feature request to add `replicated/ship` integration to `helmfile` in that case :)

Resolves #599
This commit is contained in:
KUOKA Yusuke 2019-05-16 21:24:16 +09:00 committed by GitHub
parent 0104c91fce
commit 0534117b62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -714,8 +714,9 @@ Once `events` are triggered, associated `hooks` are executed, by running the `co
Currently supported `events` are:
- `prepare`
- `cleanup`
- `presync`
- `postsync`
- `cleanup`
Hooks associated to `prepare` events are triggered after each release in your helmfile is loaded from YAML, before execution.
@ -723,6 +724,8 @@ Hooks associated to `cleanup` events are triggered after each release is process
Hooks associated to `presync` events are triggered before each release is applied to the remote cluster. This is the ideal event to execute any commands that may mutate the cluster state as it will not be run for read-only operations like `lint`, `diff` or `template`.
Hooks associated to `postsync` events are triggered after each release is applied to the remote cluster. This is the ideal event to execute any commands that may mutate the cluster state as it will not be run for read-only operations like `lint`, `diff` or `template`.
The following is an example hook that just prints the contextual information provided to hook:
```

View File

@ -374,7 +374,11 @@ func (st *HelmState) SyncReleases(affectedReleases *AffectedReleases, helm helme
results <- syncResult{errors: []*ReleaseError{relErr}}
}
if _, err := st.triggerCleanupEvent(prep.release, "sync"); err != nil {
if _, err := st.triggerPostsyncEvent(release, "sync"); err != nil {
st.logger.Warnf("warn: %v\n", err)
}
if _, err := st.triggerCleanupEvent(release, "sync"); err != nil {
st.logger.Warnf("warn: %v\n", err)
}
}
@ -938,6 +942,10 @@ func (st *HelmState) triggerPresyncEvent(r *ReleaseSpec, helmfileCommand string)
return st.triggerReleaseEvent("presync", r, helmfileCommand)
}
func (st *HelmState) triggerPostsyncEvent(r *ReleaseSpec, helmfileCommand string) (bool, error) {
return st.triggerReleaseEvent("postsync", r, helmfileCommand)
}
func (st *HelmState) triggerReleaseEvent(evt string, r *ReleaseSpec, helmfileCmd string) (bool, error) {
bus := &event.Bus{
Hooks: r.Hooks,