|
1 | 1 | package cmd
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "io/ioutil"
|
5 | 6 | "os"
|
6 | 7 | "os/exec"
|
| 8 | + "regexp" |
7 | 9 | "strconv"
|
8 | 10 | "strings"
|
| 11 | + |
| 12 | + "github.com/Masterminds/semver" |
| 13 | +) |
| 14 | + |
| 15 | +var ( |
| 16 | + helmVersionRE = regexp.MustCompile(`Version:\s*"([^"]+)"`) |
| 17 | + minHelmVersion = semver.MustParse("v3.1.0-rc.1") |
9 | 18 | )
|
10 | 19 |
|
| 20 | +func compatibleHelm3Version() error { |
| 21 | + cmd := exec.Command(os.Getenv("HELM_BIN"), "version") |
| 22 | + debugPrint("Executing %s", strings.Join(cmd.Args, " ")) |
| 23 | + output, err := cmd.CombinedOutput() |
| 24 | + if err != nil { |
| 25 | + return fmt.Errorf("Failed to run `%s version`: %v", os.Getenv("HELM_BIN"), err) |
| 26 | + } |
| 27 | + versionOutput := string(output) |
| 28 | + |
| 29 | + matches := helmVersionRE.FindStringSubmatch(versionOutput) |
| 30 | + if matches == nil { |
| 31 | + return fmt.Errorf("Failed to find version in output %#v", versionOutput) |
| 32 | + } |
| 33 | + helmVersion, err := semver.NewVersion(matches[1]) |
| 34 | + if err != nil { |
| 35 | + return fmt.Errorf("Failed to parse version %#v: %v", matches[1], err) |
| 36 | + } |
| 37 | + |
| 38 | + if minHelmVersion.GreaterThan(helmVersion) { |
| 39 | + return fmt.Errorf("helm diff upgrade requires at least helm version %s", minHelmVersion.String()) |
| 40 | + } |
| 41 | + return nil |
| 42 | + |
| 43 | +} |
11 | 44 | func getRelease(release, namespace string) ([]byte, error) {
|
12 | 45 | args := []string{"get", "manifest", release}
|
13 | 46 | if namespace != "" {
|
@@ -48,7 +81,7 @@ func getChart(release, namespace string) (string, error) {
|
48 | 81 | return string(out), nil
|
49 | 82 | }
|
50 | 83 |
|
51 |
| -func (d *diffCmd) template() ([]byte, error) { |
| 84 | +func (d *diffCmd) template(isUpgrade bool) ([]byte, error) { |
52 | 85 | flags := []string{}
|
53 | 86 | if d.devel {
|
54 | 87 | flags = append(flags, "--devel")
|
@@ -90,11 +123,10 @@ func (d *diffCmd) template() ([]byte, error) {
|
90 | 123 | flags = append(flags, "--set-file", fileValue)
|
91 | 124 | }
|
92 | 125 |
|
93 |
| - //This is a workaround until https://github.com/helm/helm/pull/6729 is released |
94 |
| - for _, apiVersion := range strings.Split(os.Getenv("HELM_TEMPLATE_API_VERSIONS"), ",") { |
95 |
| - if apiVersion != "" { |
96 |
| - flags = append(flags, "--api-versions", strings.TrimSpace(apiVersion)) |
97 |
| - } |
| 126 | + flags = append(flags, "--validate") |
| 127 | + |
| 128 | + if isUpgrade { |
| 129 | + flags = append(flags, "--is-upgrade") |
98 | 130 | }
|
99 | 131 |
|
100 | 132 | args := []string{"template", d.release, d.chart}
|
|
0 commit comments