|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "fmt" |
5 | 6 | "io/ioutil" |
6 | 7 | "os" |
@@ -129,26 +130,63 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) { |
129 | 130 | flags = append(flags, "--set-file", fileValue) |
130 | 131 | } |
131 | 132 |
|
132 | | - if !d.disableValidation && !d.dryRun { |
133 | | - flags = append(flags, "--validate") |
134 | | - } |
135 | | - |
136 | | - if isUpgrade { |
137 | | - flags = append(flags, "--is-upgrade") |
138 | | - } |
139 | | - |
140 | 133 | if d.disableOpenAPIValidation { |
141 | 134 | flags = append(flags, "--disable-openapi-validation") |
142 | 135 | } |
143 | 136 |
|
144 | | - for _, a := range d.extraAPIs { |
145 | | - flags = append(flags, "--api-versions", a) |
| 137 | + var ( |
| 138 | + subcmd string |
| 139 | + filter func([]byte) []byte |
| 140 | + ) |
| 141 | + |
| 142 | + if d.useUpgradeDryRun { |
| 143 | + if d.dryRun { |
| 144 | + return nil, fmt.Errorf("`diff upgrade --dry-run` conflicts with HELM_DIFF_USE_UPGRADE_DRY_RUN_AS_TEMPLATE. Either remove --dry-run to enable cluster access, or unset HELM_DIFF_USE_UPGRADE_DRY_RUN_AS_TEMPLATE to make cluster access unnecessary") |
| 145 | + } |
| 146 | + |
| 147 | + flags = append(flags, "--dry-run") |
| 148 | + subcmd = "upgrade" |
| 149 | + filter = func(s []byte) []byte { |
| 150 | + if len(s) == 0 { |
| 151 | + return s |
| 152 | + } |
| 153 | + |
| 154 | + i := bytes.Index(s, []byte("MANIFEST:")) |
| 155 | + s = s[i:] |
| 156 | + i = bytes.Index(s, []byte("---")) |
| 157 | + s = s[i:] |
| 158 | + i = bytes.Index(s, []byte("\nNOTES:")) |
| 159 | + if i != -1 { |
| 160 | + s = s[:i+1] |
| 161 | + } |
| 162 | + return s |
| 163 | + } |
| 164 | + } else { |
| 165 | + if !d.disableValidation && !d.dryRun { |
| 166 | + flags = append(flags, "--validate") |
| 167 | + } |
| 168 | + |
| 169 | + if isUpgrade { |
| 170 | + flags = append(flags, "--is-upgrade") |
| 171 | + } |
| 172 | + |
| 173 | + for _, a := range d.extraAPIs { |
| 174 | + flags = append(flags, "--api-versions", a) |
| 175 | + } |
| 176 | + |
| 177 | + subcmd = "template" |
| 178 | + |
| 179 | + filter = func(s []byte) []byte { |
| 180 | + return s |
| 181 | + } |
146 | 182 | } |
147 | 183 |
|
148 | | - args := []string{"template", d.release, d.chart} |
| 184 | + args := []string{subcmd, d.release, d.chart} |
149 | 185 | args = append(args, flags...) |
| 186 | + |
150 | 187 | cmd := exec.Command(os.Getenv("HELM_BIN"), args...) |
151 | | - return outputWithRichError(cmd) |
| 188 | + out, err := outputWithRichError(cmd) |
| 189 | + return filter(out), err |
152 | 190 | } |
153 | 191 |
|
154 | 192 | func (d *diffCmd) writeExistingValues(f *os.File) error { |
|
0 commit comments