Skip to content

Commit

Permalink
Explicitly disable upgrade when not install
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob LeGrone <git@jacob.work>
  • Loading branch information
jlegrone committed Mar 12, 2019
1 parent 4040e6d commit 841c540
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*C
}
}

isLint := strings.Contains(cmd.Use, "lint")
isInstall := strings.Contains(cmd.Use, "install")

cfg := &Configuration{}
if err := v.Unmarshal(cfg); err != nil {
return nil, errors.Wrap(err, "Error unmarshaling configuration")
Expand All @@ -111,11 +114,13 @@ func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*C
return nil, errors.New("specifying '--namespace' without '--release-label' is not allowed")
}

// Disable upgrade (this does some expensive dependency building on previous revisions)
// when neither "install" nor "lint-and-install" have not been specified.
cfg.Upgrade = isInstall && cfg.Upgrade
if (cfg.TargetBranch == "" || cfg.Remote == "") && cfg.Upgrade {
return nil, errors.New("specifying '--upgrade=true' without '--target-branch' or '--remote', is not allowed")
}

isLint := strings.Contains(cmd.Use, "lint")
chartYamlSchemaPath := cfg.ChartYamlSchema
if chartYamlSchemaPath == "" {
var err error
Expand Down
4 changes: 3 additions & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func TestUnmarshalJson(t *testing.T) {
}

func loadAndAssertConfigFromFile(t *testing.T, configFile string) {
cfg, _ := LoadConfiguration(configFile, &cobra.Command{}, true)
cfg, _ := LoadConfiguration(configFile, &cobra.Command{
Use: "install",
}, true)

require.Equal(t, "origin", cfg.Remote)
require.Equal(t, "master", cfg.TargetBranch)
Expand Down

0 comments on commit 841c540

Please sign in to comment.