mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-19 11:07:24 +02:00
@@ -18,12 +18,10 @@ func (context *HelmContext) GetTillerlessArgs(helm *execer) []string {
|
||||
if context.Tillerless && !helm.IsHelm3() {
|
||||
if context.TillerNamespace != "" {
|
||||
return []string{"tiller", "run", context.TillerNamespace, "--", helm.helmBinary}
|
||||
} else {
|
||||
return []string{"tiller", "run", "--", helm.helmBinary}
|
||||
}
|
||||
} else {
|
||||
return []string{}
|
||||
return []string{"tiller", "run", "--", helm.helmBinary}
|
||||
}
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (context *HelmContext) getTillerlessEnv() map[string]string {
|
||||
@@ -41,7 +39,6 @@ func (context *HelmContext) getTillerlessEnv() map[string]string {
|
||||
}
|
||||
}
|
||||
return result
|
||||
} else {
|
||||
return map[string]string{}
|
||||
}
|
||||
return map[string]string{}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ func TestGetTillerlessArgs(t *testing.T) {
|
||||
version: *sr,
|
||||
}
|
||||
require.Equalf(t, test.expected, hc.GetTillerlessArgs(he), "expected result %s, received result %s", test.expected, hc.GetTillerlessArgs(he))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +96,5 @@ func TestGetTillerlessEnv(t *testing.T) {
|
||||
t.Setenv(kubeconfigEnv, test.kubeconfig)
|
||||
result := hc.getTillerlessEnv()
|
||||
require.Equalf(t, test.expected, result, "expected result %s, received result %s", test.expected, result)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+20
-20
@@ -74,7 +74,6 @@ func parseHelmVersion(versionStr string) (semver.Version, error) {
|
||||
}
|
||||
|
||||
func getHelmVersion(helmBinary string, runner Runner) (semver.Version, error) {
|
||||
|
||||
// Autodetect from `helm version`
|
||||
outBytes, err := runner.Execute(helmBinary, []string{"version", "--client", "--short"}, nil)
|
||||
if err != nil {
|
||||
@@ -84,15 +83,16 @@ func getHelmVersion(helmBinary string, runner Runner) (semver.Version, error) {
|
||||
return parseHelmVersion(string(outBytes))
|
||||
}
|
||||
|
||||
func redactedUrl(chart string) string {
|
||||
chartUrl, err := url.ParseRequestURI(chart)
|
||||
func redactedURL(chart string) string {
|
||||
chartURL, err := url.ParseRequestURI(chart)
|
||||
if err != nil {
|
||||
return chart
|
||||
}
|
||||
return chartUrl.Redacted()
|
||||
return chartURL.Redacted()
|
||||
}
|
||||
|
||||
// New for running helm commands
|
||||
// nolint: golint
|
||||
func New(helmBinary string, logger *zap.SugaredLogger, kubeContext string, runner Runner) *execer {
|
||||
// TODO: proper error handling
|
||||
version, err := getHelmVersion(helmBinary, runner)
|
||||
@@ -206,7 +206,7 @@ func (helm *execer) UpdateDeps(chart string) error {
|
||||
}
|
||||
|
||||
func (helm *execer) SyncRelease(context HelmContext, name, chart string, flags ...string) error {
|
||||
helm.logger.Infof("Upgrading release=%v, chart=%v", name, redactedUrl(chart))
|
||||
helm.logger.Infof("Upgrading release=%v, chart=%v", name, redactedURL(chart))
|
||||
preArgs := context.GetTillerlessArgs(helm)
|
||||
env := context.getTillerlessEnv()
|
||||
|
||||
@@ -270,7 +270,6 @@ func (helm *execer) DecryptSecret(context HelmContext, name string, flags ...str
|
||||
|
||||
// Cache miss
|
||||
if !ok {
|
||||
|
||||
secret = &decryptedSecret{}
|
||||
helm.decryptedSecrets[absPath] = secret
|
||||
|
||||
@@ -288,7 +287,6 @@ func (helm *execer) DecryptSecret(context HelmContext, name string, flags ...str
|
||||
}
|
||||
|
||||
secret.bytes = secretBytes
|
||||
|
||||
} else {
|
||||
// Cache hit
|
||||
helm.logger.Debugf("Found secret in cache %v", absPath)
|
||||
@@ -312,7 +310,9 @@ func (helm *execer) DecryptSecret(context HelmContext, name string, flags ...str
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer tmpFile.Close()
|
||||
defer func() {
|
||||
_ = tmpFile.Close()
|
||||
}()
|
||||
|
||||
_, err = tmpFile.Write(content)
|
||||
if err != nil {
|
||||
@@ -334,7 +334,7 @@ func (helm *execer) DecryptSecret(context HelmContext, name string, flags ...str
|
||||
}
|
||||
|
||||
func (helm *execer) TemplateRelease(name string, chart string, flags ...string) error {
|
||||
helm.logger.Infof("Templating release=%v, chart=%v", name, redactedUrl(chart))
|
||||
helm.logger.Infof("Templating release=%v, chart=%v", name, redactedURL(chart))
|
||||
var args []string
|
||||
if helm.IsHelm3() {
|
||||
args = []string{"template", name, chart}
|
||||
@@ -373,9 +373,9 @@ func (helm *execer) TemplateRelease(name string, chart string, flags ...string)
|
||||
|
||||
func (helm *execer) DiffRelease(context HelmContext, name, chart string, suppressDiff bool, flags ...string) error {
|
||||
if context.Writer != nil {
|
||||
fmt.Fprintf(context.Writer, "Comparing release=%v, chart=%v\n", name, redactedUrl(chart))
|
||||
fmt.Fprintf(context.Writer, "Comparing release=%v, chart=%v\n", name, redactedURL(chart))
|
||||
} else {
|
||||
helm.logger.Infof("Comparing release=%v, chart=%v", name, redactedUrl(chart))
|
||||
helm.logger.Infof("Comparing release=%v, chart=%v", name, redactedURL(chart))
|
||||
}
|
||||
preArgs := context.GetTillerlessArgs(helm)
|
||||
env := context.getTillerlessEnv()
|
||||
@@ -390,14 +390,12 @@ func (helm *execer) DiffRelease(context HelmContext, name, chart string, suppres
|
||||
}
|
||||
}
|
||||
if detailedExitcodeEnabled {
|
||||
switch e := err.(type) {
|
||||
case ExitError:
|
||||
if e.ExitStatus() == 2 {
|
||||
if !(suppressDiff) {
|
||||
helm.write(context.Writer, out)
|
||||
}
|
||||
return err
|
||||
e, ok := err.(ExitError)
|
||||
if ok && e.ExitStatus() == 2 {
|
||||
if !(suppressDiff) {
|
||||
helm.write(context.Writer, out)
|
||||
}
|
||||
return err
|
||||
}
|
||||
} else if !(suppressDiff) {
|
||||
helm.write(context.Writer, out)
|
||||
@@ -413,7 +411,7 @@ func (helm *execer) Lint(name, chart string, flags ...string) error {
|
||||
}
|
||||
|
||||
func (helm *execer) Fetch(chart string, flags ...string) error {
|
||||
helm.logger.Infof("Fetching %v", redactedUrl(chart))
|
||||
helm.logger.Infof("Fetching %v", redactedURL(chart))
|
||||
out, err := helm.exec(append([]string{"fetch", chart}, flags...), map[string]string{})
|
||||
helm.info(out)
|
||||
return err
|
||||
@@ -432,7 +430,9 @@ func (helm *execer) ChartPull(chart string, flags ...string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer func() {
|
||||
_ = os.RemoveAll(tempDir)
|
||||
}()
|
||||
helmArgs = []string{"fetch", ociChartURL, "--version", ociChartTag, "--destination", tempDir}
|
||||
} else {
|
||||
helmArgs = []string{"chart", "pull", chart}
|
||||
|
||||
@@ -32,6 +32,7 @@ func (mock *mockRunner) Execute(cmd string, args []string, env map[string]string
|
||||
return mock.output, mock.err
|
||||
}
|
||||
|
||||
// nolint: golint
|
||||
func MockExecer(logger *zap.SugaredLogger, kubeContext string) *execer {
|
||||
execer := New("helm", logger, kubeContext, &mockRunner{})
|
||||
return execer
|
||||
@@ -816,14 +817,14 @@ func Test_GetVersion(t *testing.T) {
|
||||
helm := New("helm", NewLogger(os.Stdout, "info"), "dev", &helm2Runner)
|
||||
ver := helm.GetVersion()
|
||||
if ver.Major != 2 || ver.Minor != 16 || ver.Patch != 1 {
|
||||
t.Error(fmt.Sprintf("helmexec.GetVersion - did not detect correct Helm2 version; it was: %+v", ver))
|
||||
t.Errorf("helmexec.GetVersion - did not detect correct Helm2 version; it was: %+v", ver)
|
||||
}
|
||||
|
||||
helm3Runner := mockRunner{output: []byte("v3.2.4+ge29ce2a\n")}
|
||||
helm = New("helm", NewLogger(os.Stdout, "info"), "dev", &helm3Runner)
|
||||
ver = helm.GetVersion()
|
||||
if ver.Major != 3 || ver.Minor != 2 || ver.Patch != 4 {
|
||||
t.Error(fmt.Sprintf("helmexec.GetVersion - did not detect correct Helm3 version; it was: %+v", ver))
|
||||
t.Errorf("helmexec.GetVersion - did not detect correct Helm3 version; it was: %+v", ver)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
package helmexec
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type logWriterGenerator struct {
|
||||
|
||||
Reference in New Issue
Block a user