feat(helm): add ability for --dry-run to do lookup functions

When a helm command is run with the --dry-run flag, it will try to connect to the cluster
if the value is 'server' to be able to render lookup functions.
Closes #8137

Signed-off-by: Tapas Kapadia <tapaskapadia10@gmail.com>
pull/9426/head
Tapas Kapadia 3 years ago
parent 51281c195a
commit 4d67dfabaa

@ -263,7 +263,7 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options
client.Namespace = settings.Namespace() client.Namespace = settings.Namespace()
// validate dry-run flag value is one of the allowed values // validate dry-run flag value is one of the allowed values
if err := validateDryRunFlag(client); err != nil { if err := validateDryRunFlag(client.DryRun); err != nil {
return nil, err return nil, err
} }
@ -308,12 +308,12 @@ func compInstall(args []string, toComplete string, client *action.Install) ([]st
return nil, cobra.ShellCompDirectiveNoFileComp return nil, cobra.ShellCompDirectiveNoFileComp
} }
func validateDryRunFlag(client *action.Install) error { func validateDryRunFlag(dryRunFlagValue string) error {
// validate dry-run flag value with set of allowed value // validate dry-run flag value with set of allowed value
allowedDryRunValues := []string{"false", "true", "none", "client", "server"} allowedDryRunValues := []string{"false", "true", "none", "client", "server"}
isAllowed := false isAllowed := false
for _, v := range allowedDryRunValues { for _, v := range allowedDryRunValues {
if client.DryRun == v { if dryRunFlagValue == v {
isAllowed = true isAllowed = true
break break
} }

@ -120,11 +120,6 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
instClient.Description = client.Description instClient.Description = client.Description
instClient.DependencyUpdate = client.DependencyUpdate instClient.DependencyUpdate = client.DependencyUpdate
// validate dry-run flag value is one of the allowed values
if err := validateDryRunFlag(instClient); err != nil {
return err
}
rel, err := runInstall(args, instClient, valueOpts, out) rel, err := runInstall(args, instClient, valueOpts, out)
if err != nil { if err != nil {
return err return err
@ -144,6 +139,10 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
if err != nil { if err != nil {
return err return err
} }
// validate dry-run flag value is one of the allowed values
if err := validateDryRunFlag(client.DryRun); err != nil {
return err
}
p := getter.All(settings) p := getter.All(settings)
vals, err := valueOpts.MergeValues(p) vals, err := valueOpts.MergeValues(p)

@ -125,7 +125,7 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values chartutil.Valu
// This enables the ability to render 'lookup' functions. // This enables the ability to render 'lookup' functions.
// It may break in interesting and exotic ways because other data (e.g. discovery) // It may break in interesting and exotic ways because other data (e.g. discovery)
// is mocked. // is mocked.
if (dryRun == "server" || dryRun == "none" || dryRun == "false") && cfg.RESTClientGetter != nil { if (dryRun == "server" || dryRun == "none" || dryRun == "false") && cfg.RESTClientGetter != nil {
restConfig, err := cfg.RESTClientGetter.ToRESTConfig() restConfig, err := cfg.RESTClientGetter.ToRESTConfig()
if err != nil { if err != nil {
return hs, b, "", err return hs, b, "", err

@ -154,7 +154,7 @@ func (u *Upgrade) RunWithContext(ctx context.Context, name string, chart *chart.
return res, err return res, err
} }
// Do not update for dry runs // Do not update for dry runs
if u.DryRun == "none" || u.DryRun == "false" { if u.DryRun == "none" || u.DryRun == "false" {
u.cfg.Log("updating status for upgraded release for %s", name) u.cfg.Log("updating status for upgraded release for %s", name)
if err := u.cfg.Releases.Update(upgradedRelease); err != nil { if err := u.cfg.Releases.Update(upgradedRelease); err != nil {
return res, err return res, err

Loading…
Cancel
Save