add runinfo

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2024-06-02 15:03:54 +08:00
parent 61b4199c80
commit 2ebdf9a37c
3 changed files with 68 additions and 60 deletions
+21 -19
View File
@@ -142,7 +142,9 @@ func (a *App) Repos(c ReposConfigProvider) error {
// TODO: Remove this function once Helmfile v0.x
func (a *App) DeprecatedSyncCharts(c DeprecatedChartsConfigProvider) error {
return a.ForEachState(func(run *Run) (_ bool, errs []error) {
err := run.withPreparedCharts("charts", state.ChartPrepareOptions{
err := run.withPreparedCharts(state.RunInfo{
SubCommand: "charts",
}, state.ChartPrepareOptions{
SkipRepos: true,
SkipDeps: true,
Concurrency: 2,
@@ -174,7 +176,7 @@ func (a *App) Diff(c DiffConfigProvider) error {
includeCRDs := !c.SkipCRDs()
prepErr := run.withPreparedCharts("diff", state.ChartPrepareOptions{
prepErr := run.withPreparedCharts(state.RunInfo{SubCommand: "diff"}, state.ChartPrepareOptions{
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
IncludeCRDs: &includeCRDs,
@@ -239,7 +241,7 @@ func (a *App) Template(c TemplateConfigProvider) error {
// Live output should never be enabled for the "template" subcommand to avoid breaking `helmfile template | kubectl apply -f -`
run.helm.SetEnableLiveOutput(false)
prepErr := run.withPreparedCharts("template", state.ChartPrepareOptions{
prepErr := run.withPreparedCharts(state.RunInfo{SubCommand: "template"}, state.ChartPrepareOptions{
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
IncludeCRDs: &includeCRDs,
@@ -262,7 +264,7 @@ func (a *App) Template(c TemplateConfigProvider) error {
func (a *App) WriteValues(c WriteValuesConfigProvider) error {
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
prepErr := run.withPreparedCharts("write-values", state.ChartPrepareOptions{
prepErr := run.withPreparedCharts(state.RunInfo{SubCommand: "write-values"}, state.ChartPrepareOptions{
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
SkipCleanup: c.SkipCleanup(),
@@ -312,7 +314,7 @@ func (a *App) Lint(c LintConfigProvider) error {
var lintErrs []error
// `helm lint` on helm v2 and v3 does not support remote charts, that we need to set `forceDownload=true` here
prepErr := run.withPreparedCharts("lint", state.ChartPrepareOptions{
prepErr := run.withPreparedCharts(state.RunInfo{SubCommand: "lint"}, state.ChartPrepareOptions{
ForceDownload: true,
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
@@ -347,7 +349,7 @@ func (a *App) Lint(c LintConfigProvider) error {
func (a *App) Fetch(c FetchConfigProvider) error {
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
prepErr := run.withPreparedCharts("pull", state.ChartPrepareOptions{
prepErr := run.withPreparedCharts(state.RunInfo{SubCommand: "pull"}, state.ChartPrepareOptions{
ForceDownload: true,
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
@@ -369,7 +371,7 @@ func (a *App) Sync(c SyncConfigProvider) error {
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
includeCRDs := !c.SkipCRDs()
prepErr := run.withPreparedCharts("sync", state.ChartPrepareOptions{
prepErr := run.withPreparedCharts(state.RunInfo{SubCommand: "sync"}, state.ChartPrepareOptions{
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
Wait: c.Wait(),
@@ -402,7 +404,7 @@ func (a *App) Apply(c ApplyConfigProvider) error {
err := a.ForEachState(func(run *Run) (ok bool, errs []error) {
includeCRDs := !c.SkipCRDs()
prepErr := run.withPreparedCharts("apply", state.ChartPrepareOptions{
prepErr := run.withPreparedCharts(state.RunInfo{SubCommand: "apply"}, state.ChartPrepareOptions{
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
Wait: c.Wait(),
@@ -444,7 +446,7 @@ func (a *App) Apply(c ApplyConfigProvider) error {
func (a *App) Status(c StatusesConfigProvider) error {
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
err := run.withPreparedCharts("status", state.ChartPrepareOptions{
err := run.withPreparedCharts(state.RunInfo{SubCommand: "status"}, state.ChartPrepareOptions{
SkipRepos: true,
SkipDeps: true,
Concurrency: c.Concurrency(),
@@ -464,7 +466,7 @@ func (a *App) Status(c StatusesConfigProvider) error {
func (a *App) Delete(c DeleteConfigProvider) error {
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
if !c.SkipCharts() {
err := run.withPreparedCharts("delete", state.ChartPrepareOptions{
err := run.withPreparedCharts(state.RunInfo{SubCommand: "delete"}, state.ChartPrepareOptions{
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
Concurrency: c.Concurrency(),
@@ -487,7 +489,7 @@ func (a *App) Delete(c DeleteConfigProvider) error {
func (a *App) Destroy(c DestroyConfigProvider) error {
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
if !c.SkipCharts() {
err := run.withPreparedCharts("destroy", state.ChartPrepareOptions{
err := run.withPreparedCharts(state.RunInfo{SubCommand: "destroy"}, state.ChartPrepareOptions{
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
Concurrency: c.Concurrency(),
@@ -514,7 +516,7 @@ func (a *App) Test(c TestConfigProvider) error {
"or set helm.sh/hook-delete-policy\n")
}
err := run.withPreparedCharts("test", state.ChartPrepareOptions{
err := run.withPreparedCharts(state.RunInfo{SubCommand: "test"}, state.ChartPrepareOptions{
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
Concurrency: c.Concurrency(),
@@ -533,7 +535,7 @@ func (a *App) Test(c TestConfigProvider) error {
func (a *App) PrintDAGState(c DAGConfigProvider) error {
var err error
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
err = run.withPreparedCharts("show-dag", state.ChartPrepareOptions{
err = run.withPreparedCharts(state.RunInfo{SubCommand: "show-dag"}, state.ChartPrepareOptions{
SkipRepos: true,
SkipDeps: true,
Concurrency: 2,
@@ -549,7 +551,7 @@ func (a *App) PrintDAGState(c DAGConfigProvider) error {
func (a *App) PrintState(c StateConfigProvider) error {
return a.ForEachState(func(run *Run) (_ bool, errs []error) {
err := run.withPreparedCharts("build", state.ChartPrepareOptions{
err := run.withPreparedCharts(state.RunInfo{SubCommand: "build"}, state.ChartPrepareOptions{
SkipRepos: true,
SkipDeps: true,
Concurrency: 2,
@@ -621,7 +623,7 @@ func (a *App) ListReleases(c ListConfigProvider) error {
var err error
if !c.SkipCharts() {
err = run.withPreparedCharts("list", state.ChartPrepareOptions{
err = run.withPreparedCharts(state.RunInfo{SubCommand: "list"}, state.ChartPrepareOptions{
SkipRepos: true,
SkipDeps: true,
Concurrency: 2,
@@ -1480,7 +1482,7 @@ Do you really want to apply?
if _, preapplyErrors := withDAG(st, helm, a.Logger, state.PlanOptions{Purpose: "invoking preapply hooks for", Reverse: true, SelectedReleases: toApplyWithNeeds, SkipNeeds: true}, a.WrapWithoutSelector(func(subst *state.HelmState, helm helmexec.Interface) []error {
for _, r := range subst.Releases {
release := r
if _, err := st.TriggerPreapplyEvent(&release, "apply"); err != nil {
if _, err := st.TriggerPreapplyEvent(&release, state.RunInfo{SubCommand: "apply"}); err != nil {
return []error{err}
}
}
@@ -1552,7 +1554,7 @@ Do you really want to apply?
for id := range releasesWithNoChange {
r := releasesWithNoChange[id]
if _, err := st.TriggerCleanupEvent(&r, "apply"); err != nil {
if _, err := st.TriggerCleanupEvent(&r, state.RunInfo{SubCommand: "apply"}); err != nil {
a.Logger.Warnf("warn: %v\n", err)
}
}
@@ -1601,7 +1603,7 @@ func (a *App) delete(r *Run, purge bool, c DestroyConfigProvider) (bool, []error
for id := range releasesWithNoChange {
r := releasesWithNoChange[id]
if _, err := st.TriggerCleanupEvent(&r, "delete"); err != nil {
if _, err := st.TriggerCleanupEvent(&r, state.RunInfo{SubCommand: "delete"}); err != nil {
a.Logger.Warnf("warn: %v\n", err)
}
}
@@ -1848,7 +1850,7 @@ func (a *App) sync(r *Run, c SyncConfigProvider) (bool, []error) {
for id := range releasesWithNoChange {
r := releasesWithNoChange[id]
if _, err := st.TriggerCleanupEvent(&r, "sync"); err != nil {
if _, err := st.TriggerCleanupEvent(&r, state.RunInfo{SubCommand: "sync"}); err != nil {
a.Logger.Warnf("warn: %v\n", err)
}
}
+4 -4
View File
@@ -39,7 +39,7 @@ func (r *Run) askForConfirmation(msg string) bool {
return AskForConfirmation(msg)
}
func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepareOptions, f func()) error {
func (r *Run) withPreparedCharts(helmfileRunInfo state.RunInfo, opts state.ChartPrepareOptions, f func()) error {
if r.ReleaseToChart != nil {
panic("Run.PrepareCharts can be called only once")
}
@@ -67,13 +67,13 @@ func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepare
fmt.Printf("Charts will be downloaded to: %s\n", dir)
}
if _, err := r.state.TriggerGlobalPrepareEvent(helmfileCommand); err != nil {
if _, err := r.state.TriggerGlobalPrepareEvent(helmfileRunInfo); err != nil {
return err
}
concurrency := opts.Concurrency
releaseToChart, errs := r.state.PrepareCharts(r.helm, dir, concurrency, helmfileCommand, opts)
releaseToChart, errs := r.state.PrepareCharts(r.helm, dir, concurrency, helmfileRunInfo, opts)
if len(errs) > 0 {
return fmt.Errorf("%v", errs)
@@ -98,7 +98,7 @@ func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepare
f()
_, err := r.state.TriggerGlobalCleanupEvent(helmfileCommand)
_, err := r.state.TriggerGlobalCleanupEvent(helmfileRunInfo)
return err
}