Signed-off-by: George Jenkins <gjenkins8@bloomberg.net>
pull/11744/head
George Jenkins 3 years ago
parent 2b5abfcc6b
commit 27c6a8c1cf

@ -122,7 +122,7 @@ To see the list of chart repositories, use 'helm repo list'. To search for
charts in a repository, use 'helm search'.
`
func determineInstallDryRunMode(dryRunModeFlag string) (*action.DryRunMode, error) {
func determineDryRunMode(dryRunModeFlag string) (*action.DryRunMode, error) {
switch dryRunModeFlag {
case "none":
case "false": // TODO: Remove "false" helm v4
@ -153,7 +153,7 @@ func newInstallCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
},
RunE: func(_ *cobra.Command, args []string) error {
dryRunMode, err := determineInstallDryRunMode(dryRunModeFlag)
dryRunMode, err := determineDryRunMode(dryRunModeFlag)
if err != nil {
return err
}

@ -72,6 +72,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
valueOpts := &values.Options{}
var outfmt output.Format
var createNamespace bool
var dryRunModeFlag string
cmd := &cobra.Command{
Use: "upgrade [RELEASE] [CHART]",
@ -106,6 +107,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
instClient.ChartPathOptions = client.ChartPathOptions
instClient.Force = client.Force
instClient.DryRun = client.DryRun
instClient.DryRunMode = client.DryRunMode
instClient.DisableHooks = client.DisableHooks
instClient.SkipCRDs = client.SkipCRDs
instClient.Timeout = client.Timeout
@ -214,7 +216,12 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
f.BoolVar(&createNamespace, "create-namespace", false, "if --install is set, create the release namespace if not present")
f.BoolVarP(&client.Install, "install", "i", false, "if a release by this name doesn't already exist, run an install")
f.BoolVar(&client.Devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored")
f.BoolVar(&client.DryRun, "dry-run", false, "simulate an upgrade")
f.StringVar(
&dryRunModeFlag,
"dry-run",
"none",
`simulate an install. Must be "none", "server", or "client". If client strategy, X. If server strategy, Y. For backwards compatibility, boolean values "true" and "false" are also accepted. "true" being a synonym for "client". "false" meaning disable dry-run`,
)
f.BoolVar(&client.Recreate, "recreate-pods", false, "performs pods restart for the resource if applicable")
f.MarkDeprecated("recreate-pods", "functionality will no longer be updated. Consult the documentation for other methods to recreate pods")
f.BoolVar(&client.Force, "force", false, "force resource updates through a replacement strategy")

@ -0,0 +1,9 @@
package action
type DryRunMode string
var (
DryRunModeNone DryRunMode = "none"
DryRunModeClient DryRunMode = "client"
DryRunModeServer DryRunMode = "server"
)

@ -62,14 +62,6 @@ const notesFileSuffix = "NOTES.txt"
const defaultDirectoryPermission = 0755
type DryRunMode string
var (
DryRunModeNone DryRunMode = "none"
DryRunModeClient DryRunMode = "client"
DryRunModeServer DryRunMode = "server"
)
// Install performs an installation operation.
type Install struct {
cfg *Configuration

@ -69,9 +69,14 @@ type Upgrade struct {
WaitForJobs bool
// DisableHooks disables hook processing if set to true.
DisableHooks bool
// DryRun controls whether the operation is prepared, but not executed.
// Deprecated: DryRun controls whether the operation is prepared, but not executed.
// If `true`, the upgrade is prepared but not performed.
DryRun bool
// DryRunMode controls whether the operation is prepared, but not executed.
// If set, the upgrade is prepared but not performed.
// For DryRunModeClient
// For DryRunModeServer
DryRunMode DryRunMode
// Force will, if set to `true`, ignore certain warnings and perform the upgrade anyway.
//
// This should be used with caution.
@ -153,7 +158,7 @@ func (u *Upgrade) RunWithContext(ctx context.Context, name string, chart *chart.
return res, err
}
if !u.DryRun {
if !u.isDryRun() {
u.cfg.Log("updating status for upgraded release for %s", name)
if err := u.cfg.Releases.Update(upgradedRelease); err != nil {
return res, err
@ -163,6 +168,23 @@ func (u *Upgrade) RunWithContext(ctx context.Context, name string, chart *chart.
return res, nil
}
func (u *Upgrade) isDryRun() bool {
if u.DryRunMode != "" {
switch u.DryRunMode {
case DryRunModeClient:
case DryRunModeServer:
return true
case DryRunModeNone:
return false
default:
panic("Invalid DryRun mode")
}
}
// Fallback to legacy
return u.DryRun
}
// prepareUpgrade builds an upgraded release for an upgrade operation.
func (u *Upgrade) prepareUpgrade(name string, chart *chart.Chart, vals map[string]interface{}) (*release.Release, *release.Release, error) {
if chart == nil {
@ -230,8 +252,9 @@ func (u *Upgrade) prepareUpgrade(name string, chart *chart.Chart, vals map[strin
if err != nil {
return nil, nil, err
}
// Interacts with cluster if possible
hooks, manifestDoc, notesTxt, err := u.cfg.renderResources(chart, valuesToRender, "", "", u.SubNotes, false, false, u.PostRenderer, true)
interactWithRemote := u.DryRunMode == DryRunModeServer
hooks, manifestDoc, notesTxt, err := u.cfg.renderResources(chart, valuesToRender, "", "", u.SubNotes, false, false, u.PostRenderer, interactWithRemote)
if err != nil {
return nil, nil, err
}
@ -309,7 +332,7 @@ func (u *Upgrade) performUpgrade(ctx context.Context, originalRelease, upgradedR
return nil
})
if u.DryRun {
if u.isDryRun() {
u.cfg.Log("dry run for %s", upgradedRelease.Name)
if len(u.Description) > 0 {
upgradedRelease.Info.Description = u.Description

Loading…
Cancel
Save