Use go-getter with secrets as well (#560)

* Use go-getter with secrets as well

Signed-off-by: Quan TRAN <account@itscaro.me>
This commit is contained in:
Quan TRAN
2022-12-09 07:46:28 +08:00
committed by GitHub
parent f7b3fb4432
commit 398c812e49
9 changed files with 202 additions and 28 deletions
+10 -7
View File
@@ -1,9 +1,12 @@
package envvar
const DisableInsecureFeatures = "HELMFILE_DISABLE_INSECURE_FEATURES"
const SkipInsecureTemplateFunctions = "HELMFILE_SKIP_INSECURE_TEMPLATE_FUNCTIONS"
const Experimental = "HELMFILE_EXPERIMENTAL" // environment variable for experimental features, expecting "true" lower case
const Environment = "HELMFILE_ENVIRONMENT"
const TempDir = "HELMFILE_TEMPDIR"
const Helm3 = "HELMFILE_HELM3"
const UpgradeNoticeDisabled = "HELMFILE_UPGRADE_NOTICE_DISABLED"
const (
DisableInsecureFeatures = "HELMFILE_DISABLE_INSECURE_FEATURES"
DisableRunnerUniqueID = "HELMFILE_DISABLE_RUNNER_UNIQUE_ID"
SkipInsecureTemplateFunctions = "HELMFILE_SKIP_INSECURE_TEMPLATE_FUNCTIONS"
Experimental = "HELMFILE_EXPERIMENTAL" // environment variable for experimental features, expecting "true" lower case
Environment = "HELMFILE_ENVIRONMENT"
TempDir = "HELMFILE_TEMPDIR"
Helm3 = "HELMFILE_HELM3"
UpgradeNoticeDisabled = "HELMFILE_UPGRADE_NOTICE_DISABLED"
)
+13 -2
View File
@@ -13,6 +13,8 @@ import (
"syscall"
"go.uber.org/zap"
"github.com/helmfile/helmfile/pkg/envvar"
)
// Runner interface for shell commands
@@ -68,9 +70,18 @@ func Output(c *exec.Cmd, logWriterGenerators ...*logWriterGenerator) ([]byte, er
var logWriters []io.Writer
id := newExecutionID()
var id string
if os.Getenv(envvar.DisableRunnerUniqueID) == "" {
id = newExecutionID()
}
path := filepath.Base(c.Path)
for _, g := range logWriterGenerators {
logPrefix := fmt.Sprintf("%s:%s> ", filepath.Base(c.Path), id)
var logPrefix string
if id == "" {
logPrefix = fmt.Sprintf("%s> ", path)
} else {
logPrefix = fmt.Sprintf("%s:%s> ", path, id)
}
logWriters = append(logWriters, g.Writer(logPrefix))
}
+12 -12
View File
@@ -60,7 +60,7 @@ func (r *Remote) Unmarshal(src string, dst interface{}) error {
ext := filepath.Ext(file)
{
r.Logger.Debugf("unmarshalling %s", string(bytes))
r.Logger.Debugf("remote> unmarshalling %s", string(bytes))
var err error
switch ext {
@@ -70,7 +70,7 @@ func (r *Remote) Unmarshal(src string, dst interface{}) error {
err = yaml.Unmarshal(bytes, dst)
}
r.Logger.Debugf("unmarshalled to %v", dst)
r.Logger.Debugf("remote> unmarshalled to %v", dst)
if err != nil {
return err
@@ -172,12 +172,12 @@ func (r *Remote) Fetch(goGetterSrc string, cacheDirOpt ...string) (string, error
srcDir := fmt.Sprintf("%s://%s%s", u.Scheme, u.Host, u.Dir)
file := u.File
r.Logger.Debugf("getter: %s", u.Getter)
r.Logger.Debugf("scheme: %s", u.Scheme)
r.Logger.Debugf("user: %s", u.User)
r.Logger.Debugf("host: %s", u.Host)
r.Logger.Debugf("dir: %s", u.Dir)
r.Logger.Debugf("file: %s", u.File)
r.Logger.Debugf("remote> getter: %s", u.Getter)
r.Logger.Debugf("remote> scheme: %s", u.Scheme)
r.Logger.Debugf("remote> user: %s", u.User)
r.Logger.Debugf("remote> host: %s", u.Host)
r.Logger.Debugf("remote> dir: %s", u.Dir)
r.Logger.Debugf("remote> file: %s", u.File)
// This should be shared across variant commands, so that they can share cache for the shared imports
cacheBaseDir := ""
@@ -211,9 +211,9 @@ func (r *Remote) Fetch(goGetterSrc string, cacheDirOpt ...string) (string, error
// e.g. os.CacheDir()/helmfile/https_github_com_cloudposse_helmfiles_git.ref=0.xx.0
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)
r.Logger.Debugf("remote> home: %s", r.Home)
r.Logger.Debugf("remote> getter dest: %s", getterDst)
r.Logger.Debugf("remote> cached dir: %s", cacheDirPath)
{
if r.fs.FileExistsAt(cacheDirPath) {
@@ -241,7 +241,7 @@ func (r *Remote) Fetch(goGetterSrc string, cacheDirOpt ...string) (string, error
getterSrc = u.Getter + "::" + getterSrc
}
r.Logger.Debugf("downloading %s to %s", getterSrc, getterDst)
r.Logger.Debugf("remote> downloading %s to %s", getterSrc, getterDst)
if err := r.Getter.Get(r.Home, getterSrc, cacheDirPath); err != nil {
rmerr := os.RemoveAll(cacheDirPath)
+7 -1
View File
@@ -293,9 +293,15 @@ func (c *StateCreator) scatterGatherEnvSecretFiles(st *HelmState, envSecretFiles
},
func(id int) {
for secret := range secrets {
urlOrPath := secret.path
localPath, err := c.remote.Locate(urlOrPath)
if err == nil {
urlOrPath = localPath
}
release := &ReleaseSpec{}
flags := st.appendConnectionFlags([]string{}, helm, release)
decFile, err := helm.DecryptSecret(st.createHelmContext(release, 0), secret.path, flags...)
decFile, err := helm.DecryptSecret(st.createHelmContext(release, 0), urlOrPath, flags...)
if err != nil {
results <- secretResult{secret.id, nil, err, secret.path}
continue