(context HelmContext, name, chart, namespace string, suppressDiff bool, flags ...string)
| 803 | } |
| 804 | |
| 805 | func (helm *execer) DiffRelease(context HelmContext, name, chart, namespace string, suppressDiff bool, flags ...string) error { |
| 806 | diffMsg := fmt.Sprintf("Comparing release=%v, chart=%v, namespace=%v\n", name, redactedURL(chart), namespace) |
| 807 | if context.Writer != nil && !suppressDiff { |
| 808 | _, _ = fmt.Fprint(context.Writer, diffMsg) |
| 809 | } else { |
| 810 | helm.logger.Info(diffMsg) |
| 811 | } |
| 812 | preArgs := make([]string, 0) |
| 813 | env := make(map[string]string) |
| 814 | var overrideEnableLiveOutput *bool = nil |
| 815 | if suppressDiff { |
| 816 | enableLiveOutput := false |
| 817 | overrideEnableLiveOutput = &enableLiveOutput |
| 818 | } |
| 819 | |
| 820 | // Issue #2280: In Helm 4, the --color flag is parsed by Helm before reaching the plugin, |
| 821 | // causing it to consume the next argument. Remove color flags and use HELM_DIFF_COLOR env var. |
| 822 | if helm.IsHelm4() { |
| 823 | flags = helm.filterColorFlagsForHelm4(flags, env) |
| 824 | } |
| 825 | |
| 826 | out, err := helm.exec(append(append(preArgs, "diff", "upgrade", "--allow-unreleased", name, chart), flags...), env, overrideEnableLiveOutput) |
| 827 | // Do our best to write STDOUT only when diff existed |
| 828 | // Unfortunately, this works only when you run helmfile with `--detailed-exitcode` |
| 829 | detailedExitcodeEnabled := false |
| 830 | for _, f := range flags { |
| 831 | if strings.Contains(f, "detailed-exitcode") { |
| 832 | detailedExitcodeEnabled = true |
| 833 | break |
| 834 | } |
| 835 | } |
| 836 | if detailedExitcodeEnabled { |
| 837 | e, ok := err.(ExitError) |
| 838 | if ok && e.ExitStatus() == 2 { |
| 839 | if !(suppressDiff) { |
| 840 | helm.write(context.Writer, out) |
| 841 | } |
| 842 | return err |
| 843 | } |
| 844 | } else if !(suppressDiff) { |
| 845 | helm.write(context.Writer, out) |
| 846 | } |
| 847 | return err |
| 848 | } |
| 849 | |
| 850 | // filterColorFlagsForHelm4 removes --color and --no-color flags from the flags slice |
| 851 | // and sets the HELM_DIFF_COLOR environment variable instead. |
nothing calls this directly
no test coverage detected