Skip to content

Commit

Permalink
feat(helm): add ability for --dry-run to do lookup functions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tapaskapadia committed Jan 30, 2023
1 parent 25ac62e commit f9e54b6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions cmd/helm/install.go
Expand Up @@ -262,7 +262,7 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options

client.Namespace = settings.Namespace()

// validate dry-run-option flag value is one of the allowed values
// Validate DryRunOption member is one of the allowed values
if err := validateDryRunOptionFlag(client.DryRunOption); err != nil {
return nil, err
}
Expand Down Expand Up @@ -309,7 +309,7 @@ func compInstall(args []string, toComplete string, client *action.Install) ([]st
}

func validateDryRunOptionFlag(dryRunOptionFlagValue string) error {
// validate dry-run-option flag value with set of allowed value
// Validate dry-run flag value with a set of allowed value
allowedDryRunValues := []string{"false", "true", "none", "client", "server"}
isAllowed := false
for _, v := range allowedDryRunValues {
Expand All @@ -319,7 +319,7 @@ func validateDryRunOptionFlag(dryRunOptionFlagValue string) error {
}
}
if !isAllowed {
return errors.New("Invalid dry-run flag. Flag must one of the following: false, true, none, client, sever")
return errors.New("Invalid dry-run flag. Flag must one of the following: false, true, none, client, server")
}
return nil
}
2 changes: 1 addition & 1 deletion cmd/helm/upgrade.go
Expand Up @@ -139,7 +139,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
if err != nil {
return err
}
// validate dry-run flag value is one of the allowed values
// Validate dry-run flag value is one of the allowed values
if err := validateDryRunOptionFlag(client.DryRunOption); err != nil {
return err
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/action/action.go
Expand Up @@ -120,11 +120,9 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values chartutil.Valu
var files map[string]string
var err2 error

// A `helm template` should not talk to the remote cluster. However, commands
// with the flag `--dry-run-option` with the value of false, none, or sever
// or with the flag `--dry-run` with the value of false should try to interact with the cluster.
// It may break in interesting and exotic ways because other data (e.g. discovery)
// is mocked.
// A `helm template` should not talk to the remote cluster. However, commands with the flag
//`--dry-run` with the value of `false`, `none`, or `server` should try to interact with the cluster.
// It may break in interesting and exotic ways because other data (e.g. discovery) is mocked.
if interactWithRemote && cfg.RESTClientGetter != nil {
restConfig, err := cfg.RESTClientGetter.ToRESTConfig()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/action/install.go
Expand Up @@ -204,13 +204,12 @@ func (i *Install) RunWithContext(ctx context.Context, chrt *chart.Chart, vals ma
return nil, err
}

// determine dry run behavior
// Determine dry run behavior
if i.DryRun || i.DryRunOption == "client" || i.DryRunOption == "server" || i.DryRunOption == "true" {
i.DryRun = true
}

var interactWithRemote bool
// `helm template` is the only command that Install.APIVersions field will not be nil.
if !i.DryRun || i.DryRunOption == "server" {
interactWithRemote = true
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/action/upgrade.go
Expand Up @@ -141,7 +141,7 @@ func (u *Upgrade) RunWithContext(ctx context.Context, name string, chart *chart.
return nil, errors.Errorf("release name is invalid: %s", name)
}

// determine dry run behavior
// Determine dry run behavior
if u.DryRun || u.DryRunOption == "client" || u.DryRunOption == "server" || u.DryRunOption == "true" {
u.DryRun = true
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func (u *Upgrade) prepareUpgrade(name string, chart *chart.Chart, vals map[strin
return nil, nil, err
}

// determine whether or not to interact with remote
// Determine whether or not to interact with remote
var interactWithRemote bool
if !u.DryRun || u.DryRunOption == "server" {
interactWithRemote = true
Expand Down

0 comments on commit f9e54b6

Please sign in to comment.