mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-18 07:09:25 +02:00
Add global hooks (#1301)
Changes: * Add global hooks * Add top level hooks field to yaml spec * Add functions for global prepare and cleanup events * Call global prepare and cleanup events in withPreparedCharts function * Update README * Add helmfileCommand variable to withPreparedCharts Pass the information on what helmfileCommand has been run down from the top level functions through withReposAndPreparedCharts and withPreparedCharts.
This commit is contained in:
@@ -59,6 +59,9 @@ type HelmState struct {
|
||||
Selectors []string `yaml:"-"`
|
||||
ApiVersions []string `yaml:"apiVersions,omitempty"`
|
||||
|
||||
// Hooks is a list of extension points paired with operations, that are executed in specific points of the lifecycle of releases defined in helmfile
|
||||
Hooks []event.Hook `yaml:"hooks,omitempty"`
|
||||
|
||||
Templates map[string]TemplateSpec `yaml:"templates"`
|
||||
|
||||
Env environment.Environment `yaml:"-"`
|
||||
@@ -1441,6 +1444,30 @@ func (st *HelmState) PrepareReleases(helm helmexec.Interface, helmfileCommand st
|
||||
return nil
|
||||
}
|
||||
|
||||
func (st *HelmState) TriggerGlobalPrepareEvent(helmfileCommand string) (bool, error) {
|
||||
return st.triggerGlobalReleaseEvent("prepare", nil, helmfileCommand)
|
||||
}
|
||||
|
||||
func (st *HelmState) TriggerGlobalCleanupEvent(helmfileCommand string) (bool, error) {
|
||||
return st.triggerGlobalReleaseEvent("cleanup", nil, helmfileCommand)
|
||||
}
|
||||
|
||||
func (st *HelmState) triggerGlobalReleaseEvent(evt string, evtErr error, helmfileCmd string) (bool, error) {
|
||||
bus := &event.Bus{
|
||||
Hooks: st.Hooks,
|
||||
StateFilePath: st.FilePath,
|
||||
BasePath: st.basePath,
|
||||
Namespace: st.OverrideNamespace,
|
||||
Env: st.Env,
|
||||
Logger: st.logger,
|
||||
ReadFile: st.readFile,
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
"HelmfileCommand": helmfileCmd,
|
||||
}
|
||||
return bus.Trigger(evt, evtErr, data)
|
||||
}
|
||||
|
||||
func (st *HelmState) triggerPrepareEvent(r *ReleaseSpec, helmfileCommand string) (bool, error) {
|
||||
return st.triggerReleaseEvent("prepare", nil, r, helmfileCommand)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user