Skip to content

Commit

Permalink
Merge pull request #314 from kpucynski/local-chart-fix
Browse files Browse the repository at this point in the history
Local chart usage fix
  • Loading branch information
luisdavim authored Oct 22, 2019
2 parents 445aa01 + e6209c0 commit 45cd028
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion decision_maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func diffRelease(r *release) string {
}

if exitCode, msg = cmd.exec(debug, verbose); exitCode != 0 {
logError("Command returned with exit code: " + string(exitCode) + ". And error message: " + msg)
logError(fmt.Sprintf("Command returned with exit code: %d. And error message: %s ", exitCode, msg))
} else {
if (verbose || showDiff) && msg != "" {
fmt.Println(msg)
Expand Down
2 changes: 1 addition & 1 deletion decision_maker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func Test_inspectUpgradeScenario(t *testing.T){
Name: "release1",
Namespace: "namespace",
Version: "1.0.0",
Chart: "/local/charts",
Chart: "./test_files/chart-test",
Enabled: true,
},
s: releaseState{
Expand Down
6 changes: 3 additions & 3 deletions helm_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,15 @@ func getChartVersion(r *release) (string, string) {
}

if exitCode, result := cmd.exec(debug, verbose); exitCode != 0 || strings.Contains(result, "No results found") {
return "", "ERROR: chart " + r.Chart + " with version " + r.Version + " is specified for " + "but version is not found in the defined repo."
return "", "ERROR: chart " + r.Chart + " with version " + r.Version + " is specified but not found in the helm repos."
} else {
versions := strings.Split(result, "\n")
if len(versions) < 2 {
return "", "ERROR: chart " + r.Chart + " with version " + r.Version + " is specified for " + "but version is not found in the defined repo."
return "", "ERROR: chart " + r.Chart + " with version " + r.Version + " is specified but not found in the helm repos (unrecognized helm output?)."
}
fields := strings.Split(versions[1], "\t")
if len(fields) != 4 {
return "", "ERROR: chart " + r.Chart + " with version " + r.Version + " is specified for " + "but version is not found in the defined repo."
return "", "ERROR: chart " + r.Chart + " with version " + r.Version + " is specified but not found in the helm repos (unrecognized helm output?)."
}
return strings.TrimSpace(fields[1]), ""
}
Expand Down
7 changes: 4 additions & 3 deletions helm_helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"
"testing"
"time"
Expand All @@ -16,7 +17,7 @@ func setupTestCase(t *testing.T) func(t *testing.T) {
Description: "creating an empty local chart directory",
}
if exitCode, msg := cmd.exec(debug, verbose); exitCode != 0 {
logError("Command returned with exit code: " + string(exitCode) + ". And error message: " + msg)
logError(fmt.Sprintf("Command returned with exit code: %d. And error message: %s ", exitCode, msg))
}

return func(t *testing.T) {
Expand Down Expand Up @@ -359,7 +360,7 @@ func Test_getChartVersion(t *testing.T) {
Name: "release1",
Namespace: "namespace",
Version: "1.0.0",
Chart: "/local/charts",
Chart: "./test_files/chart-test",
Enabled: true,
},
},
Expand Down Expand Up @@ -388,4 +389,4 @@ func Test_getChartVersion(t *testing.T) {
}
})
}
}
}
2 changes: 1 addition & 1 deletion plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (p plan) execPlan() {
if errorMsg = msg; !verbose {
errorMsg = strings.Split(msg, "---")[0]
}
logError("Command returned with exit code: " + string(exitCode) + ". And error message: " + errorMsg)
logError(fmt.Sprintf("Command returned with exit code: %d. And error message: %s ", exitCode, errorMsg))
} else {
log.Println(style.Cyan(msg))
if cmd.targetRelease != nil && !dryRun {
Expand Down
3 changes: 3 additions & 0 deletions test_files/chart-test/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apiVersion: v1
name: chart-test
version: 1.0.0
8 changes: 6 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,11 @@ func Indent(s, prefix string) string {

// isLocalChart checks if a chart specified in the DSF is a local directory or not
func isLocalChart(chart string) bool {
return filepath.IsAbs(chart)
_, err := os.Stat(chart)
if err == nil {
return true
}
return false
}

func generateCmdDescription(r *release, action string) string {
Expand All @@ -543,4 +547,4 @@ func generateDecisionMessage(r *release, message string, isTillerAware bool) str
return fmt.Sprintf(baseMessage + " %s", tillerNamespaceMsg)
}
return baseMessage
}
}

0 comments on commit 45cd028

Please sign in to comment.