From 65d404b276c09392b2187bb8ae59b9bce40a4de4 Mon Sep 17 00:00:00 2001 From: KUOKA Yusuke Date: Tue, 11 Jun 2019 14:28:50 +0900 Subject: [PATCH] feat: `helmfile -f ` (#670) Extends the remote-helmfile feature to also work when loading the first state file. This should be useful for people who wants to give helmfile a try without ever opening `$EDITOR`. --- pkg/app/app.go | 30 +++++++++++++----------------- pkg/remote/remote.go | 4 ++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index 15116e59..6f05e459 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -306,13 +306,6 @@ func (a *App) visitStates(fileOrDir string, defOpts LoadOpts, converge func(*sta optsForNestedState.Selectors = m.Selectors } - path, err := a.remote.Locate(m.Path) - if err != nil { - return appError(fmt.Sprintf("in .helmfiles[%d]", i), err) - } - - m.Path = path - if err := a.visitStates(m.Path, optsForNestedState, converge); err != nil { switch err.(type) { case *NoMatchingHelmfileError: @@ -384,11 +377,9 @@ func (a *App) VisitDesiredStatesWithReleasesFiltered(fileOrDir string, converge opts.Environment.OverrideValues = envvals } - var dir string - if a.directoryExistsAt(fileOrDir) { - dir = fileOrDir - } else { - dir = filepath.Dir(fileOrDir) + dir, err := a.getwd() + if err != nil { + return err } getter := &remote.GoGetter{Logger: a.Logger} @@ -404,7 +395,7 @@ func (a *App) VisitDesiredStatesWithReleasesFiltered(fileOrDir string, converge a.remote = remote - err := a.visitStates(fileOrDir, opts, func(st *state.HelmState, helm helmexec.Interface) (bool, []error) { + return a.visitStates(fileOrDir, opts, func(st *state.HelmState, helm helmexec.Interface) (bool, []error) { if len(st.Selectors) > 0 { err := st.FilterReleases() if err != nil { @@ -440,10 +431,6 @@ func (a *App) VisitDesiredStatesWithReleasesFiltered(fileOrDir string, converge return processed, errs }) - if err != nil { - return err - } - return nil } func (a *App) findStateFilesInAbsPaths(specifiedPath string) ([]string, error) { @@ -463,6 +450,15 @@ func (a *App) findStateFilesInAbsPaths(specifiedPath string) ([]string, error) { } func (a *App) findDesiredStateFiles(specifiedPath string) ([]string, error) { + path, err := a.remote.Locate(specifiedPath) + if err != nil { + return nil, fmt.Errorf("locate: %v", err) + } + if specifiedPath != path { + a.Logger.Debugf("fetched remote \"%s\" to local cache \"%s\" and loading the latter...", specifiedPath, path) + } + specifiedPath = path + var helmfileDir string if specifiedPath != "" { if a.fileExistsAt(specifiedPath) { diff --git a/pkg/remote/remote.go b/pkg/remote/remote.go index 2d42ee1a..a0e13e69 100644 --- a/pkg/remote/remote.go +++ b/pkg/remote/remote.go @@ -179,6 +179,10 @@ func (r *Remote) Fetch(goGetterSrc string) (string, error) { cacheDirPath := filepath.Join(r.Home, getterDst) + r.Logger.Debugf("home: %s", r.Home) + r.Logger.Debugf("getter dest: %s", getterDst) + r.Logger.Debugf("cached dir: %s", cacheDirPath) + { if r.FileExists(cacheDirPath) { return "", fmt.Errorf("%s is not directory. please remove it so that variant could use it for dependency caching", getterDst)