|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "io/ioutil" |
| 5 | + "os" |
| 6 | + "os/exec" |
| 7 | + "strconv" |
| 8 | +) |
| 9 | + |
| 10 | +func getRelease(release, namespace string) ([]byte, error) { |
| 11 | + args := []string{"get", "manifest", release} |
| 12 | + if namespace != "" { |
| 13 | + args = append(args, "--namespace", namespace) |
| 14 | + } |
| 15 | + cmd := exec.Command(os.Getenv("HELM_BIN"), args...) |
| 16 | + return cmd.Output() |
| 17 | +} |
| 18 | + |
| 19 | +func getHooks(release, namespace string) ([]byte, error) { |
| 20 | + args := []string{"get", "hooks", release} |
| 21 | + if namespace != "" { |
| 22 | + args = append(args, "--namespace", namespace) |
| 23 | + } |
| 24 | + cmd := exec.Command(os.Getenv("HELM_BIN"), args...) |
| 25 | + return cmd.Output() |
| 26 | +} |
| 27 | + |
| 28 | +func getRevision(release string, revision int, namespace string) ([]byte, error) { |
| 29 | + args := []string{"get", "manifest", release, "--revision", strconv.Itoa(revision)} |
| 30 | + if namespace != "" { |
| 31 | + args = append(args, "--namespace", namespace) |
| 32 | + } |
| 33 | + cmd := exec.Command(os.Getenv("HELM_BIN"), args...) |
| 34 | + return cmd.Output() |
| 35 | +} |
| 36 | + |
| 37 | +func getChart(release, namespace string) (string, error) { |
| 38 | + args := []string{"get", release, "--template", "{{.Release.Chart.Name}}"} |
| 39 | + if namespace != "" { |
| 40 | + args = append(args, "--namespace", namespace) |
| 41 | + } |
| 42 | + cmd := exec.Command(os.Getenv("HELM_BIN"), args...) |
| 43 | + out, err := cmd.Output() |
| 44 | + if err != nil { |
| 45 | + return "", err |
| 46 | + } |
| 47 | + return string(out), nil |
| 48 | +} |
| 49 | + |
| 50 | +func (d *diffCmd) template() ([]byte, error) { |
| 51 | + flags := []string{} |
| 52 | + if d.devel { |
| 53 | + flags = append(flags, "--devel") |
| 54 | + } |
| 55 | + if d.noHooks { |
| 56 | + flags = append(flags, "--no-hooks") |
| 57 | + } |
| 58 | + if d.chartVersion != "" { |
| 59 | + flags = append(flags, "--version", d.chartVersion) |
| 60 | + } |
| 61 | + if d.namespace != "" { |
| 62 | + flags = append(flags, "--namespace", d.namespace) |
| 63 | + } |
| 64 | + if !d.resetValues { |
| 65 | + if d.reuseValues { |
| 66 | + tmpfile, err := ioutil.TempFile("", "existing-values") |
| 67 | + if err != nil { |
| 68 | + return nil, err |
| 69 | + } |
| 70 | + defer os.Remove(tmpfile.Name()) |
| 71 | + flags = append(flags, "--values", tmpfile.Name()) |
| 72 | + } |
| 73 | + for _, value := range d.values { |
| 74 | + flags = append(flags, "--set", value) |
| 75 | + } |
| 76 | + for _, stringValue := range d.stringValues { |
| 77 | + flags = append(flags, "--set-string", stringValue) |
| 78 | + } |
| 79 | + for _, valueFile := range d.valueFiles { |
| 80 | + flags = append(flags, "--values", valueFile) |
| 81 | + } |
| 82 | + for _, fileValue := range d.fileValues { |
| 83 | + flags = append(flags, "--set-file", fileValue) |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + args := []string{"template", d.release, d.chart} |
| 88 | + args = append(args, flags...) |
| 89 | + cmd := exec.Command(os.Getenv("HELM_BIN"), args...) |
| 90 | + return cmd.Output() |
| 91 | +} |
| 92 | + |
| 93 | +func (d *diffCmd) existingValues(f *os.File) error { |
| 94 | + cmd := exec.Command(os.Getenv("HELM_BIN"), "get", "values", d.release, "--all") |
| 95 | + defer f.Close() |
| 96 | + cmd.Stdout = f |
| 97 | + return cmd.Run() |
| 98 | +} |
0 commit comments