Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Remove the strict flag #615

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion internal/commands/cnab.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin
if err := mergeBundleParameters(installation,
withFileParameters(paramsOpts.parametersFiles),
withCommandLineParameters(paramsOpts.overrides),
withStrictMode(paramsOpts.strictMode),
); err != nil {
return nil, nil, nil, err
}
Expand Down
1 change: 0 additions & 1 deletion internal/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func runInstall(dockerCli command.Cli, appname string, opts installOptions) erro
withCommandLineParameters(opts.overrides),
withOrchestratorParameters(opts.orchestrator, opts.kubeNamespace),
withSendRegistryAuth(opts.sendRegistryAuth),
withStrictMode(opts.strictMode),
); err != nil {
return err
}
Expand Down
16 changes: 3 additions & 13 deletions internal/commands/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import (
)

type mergeBundleConfig struct {
bundle *bundle.Bundle
params map[string]string
strictMode bool
stderr io.Writer
bundle *bundle.Bundle
params map[string]string
stderr io.Writer
}

type mergeBundleOpt func(c *mergeBundleConfig) error
Expand Down Expand Up @@ -78,12 +77,6 @@ func withErrorWriter(w io.Writer) mergeBundleOpt {
}
}

func withStrictMode(strict bool) mergeBundleOpt {
return func(c *mergeBundleConfig) error {
c.strictMode = strict
return nil
}
}
func mergeBundleParameters(installation *store.Installation, ops ...mergeBundleOpt) error {
bndl := installation.Bundle
if installation.Parameters == nil {
Expand Down Expand Up @@ -116,9 +109,6 @@ func matchAndMergeParametersDefinition(currentValues map[string]interface{}, cfg
for k, v := range cfg.params {
param, ok := cfg.bundle.Parameters[k]
if !ok {
if cfg.strictMode {
return nil, fmt.Errorf("parameter %q is not defined in the bundle", k)
}
fmt.Fprintf(cfg.stderr, "Warning: parameter %q is not defined in the bundle\n", k)
continue
}
Expand Down
12 changes: 9 additions & 3 deletions internal/commands/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,21 @@ func TestMergeBundleParameters(t *testing.T) {
assert.Assert(t, strings.Contains(buf.String(), "is not defined in the bundle"))
})

t.Run("Undefined parameter with strict mode is rejected", func(t *testing.T) {
t.Run("Warn on undefined parameter", func(t *testing.T) {
withUndefined := func(c *mergeBundleConfig) error {
c.params["param"] = "1"
return nil
}
w := bytes.NewBuffer(nil)
withStdErr := func(c *mergeBundleConfig) error {
c.stderr = w
return nil
}
bundle := prepareBundle()
i := &store.Installation{Claim: claim.Claim{Bundle: bundle}}
err := mergeBundleParameters(i, withUndefined, withStrictMode(true))
assert.ErrorContains(t, err, "is not defined in the bundle")
err := mergeBundleParameters(i, withUndefined, withStdErr)
assert.NilError(t, err)
assert.Equal(t, w.String(), "Warning: parameter \"param\" is not defined in the bundle\n")
})

t.Run("Invalid type is rejected", func(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions internal/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ func prepareBundleStore() (store.BundleStore, error) {
type parametersOptions struct {
parametersFiles []string
overrides []string
strictMode bool
}

func (o *parametersOptions) addFlags(flags *pflag.FlagSet) {
flags.StringArrayVar(&o.parametersFiles, "parameters-file", []string{}, "Override parameters file")
flags.StringArrayVarP(&o.overrides, "set", "s", []string{}, "Override parameter value")
flags.BoolVar(&o.strictMode, "strict", false, "Fail when a paramater is undefined instead of displaying a warning")
}

type credentialOptions struct {
Expand Down
1 change: 0 additions & 1 deletion internal/commands/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func runUpgrade(dockerCli command.Cli, installationName string, opts upgradeOpti
withFileParameters(opts.parametersFiles),
withCommandLineParameters(opts.overrides),
withSendRegistryAuth(opts.sendRegistryAuth),
withStrictMode(opts.strictMode),
); err != nil {
return err
}
Expand Down