Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(*): update parameter set logic to support file types #1137

Merged
merged 2 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions pkg/porter/cnab.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func (o *sharedOptions) Validate(args []string, p *Porter) error {
return err
}

err = p.applyDefaultOptions(o)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh sneaky, I like it! πŸ‘

if err != nil {
return err
}

err = o.validateParams(p)
if err != nil {
return err
Expand Down Expand Up @@ -235,13 +240,6 @@ func (o *sharedOptions) parseParams() error {
// parseParamSets parses the variable assignments in ParameterSets.
func (o *sharedOptions) parseParamSets(p *Porter) error {
if len(o.ParameterSets) > 0 {
// Load the manifest as it may be needed to determine if any
// parameters are of the Porter-exclusive type of 'file'
err := p.LoadManifestFrom(o.File)
if err != nil {
return err
}

parsed, err := p.loadParameterSets(o.ParameterSets)
if err != nil {
return errors.Wrapf(err, "unable to process provided parameter sets: %v", o.ParameterSets)
Expand Down
25 changes: 10 additions & 15 deletions pkg/porter/cnab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"get.porter.sh/porter/pkg/build"
"get.porter.sh/porter/pkg/config"
"get.porter.sh/porter/pkg/context"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -92,10 +91,6 @@ func TestSharedOptions_defaultDriver(t *testing.T) {

func TestParseParamSets_viaPathOrName(t *testing.T) {
p := NewTestPorter(t)
cxt := p.TestConfig.TestContext

// Add manifest used to parse parameter sets
cxt.AddTestFile("testdata/porter.yaml", config.Name)

p.TestParameters.TestSecrets.AddSecret("foo_secret", "foo_value")
p.TestParameters.TestSecrets.AddSecret("PARAM2_SECRET", "VALUE2")
Expand All @@ -107,12 +102,12 @@ func TestParseParamSets_viaPathOrName(t *testing.T) {
"HELLO_CUSTOM",
"/paramset.json",
},
bundleFileOptions: bundleFileOptions{
File: config.Name,
},
}

err := opts.parseParamSets(p.Porter)
err := opts.Validate([]string{}, p.Porter)
assert.NoError(t, err)

err = opts.parseParamSets(p.Porter)
assert.NoError(t, err)

wantParams := map[string]string{
Expand All @@ -124,23 +119,23 @@ func TestParseParamSets_viaPathOrName(t *testing.T) {

func TestParseParamSets_FileType(t *testing.T) {
p := NewTestPorter(t)
cxt := p.TestConfig.TestContext

// Add manifest used to parse parameter sets
cxt.AddTestFile("testdata/porter-with-file-param.yaml", config.Name)

p.TestConfig.TestContext.AddTestFile("testdata/porter-with-file-param.yaml", "porter.yaml")
p.TestConfig.TestContext.AddTestFile("testdata/paramset-with-file-param.json", "/paramset.json")

opts := sharedOptions{
ParameterSets: []string{
"/paramset.json",
},
bundleFileOptions: bundleFileOptions{
File: config.Name,
File: "porter.yaml",
},
}

err := opts.parseParamSets(p.Porter)
err := opts.Validate([]string{}, p.Porter)
assert.NoError(t, err)

err = opts.parseParamSets(p.Porter)
assert.NoError(t, err)

wantParams := map[string]string{
Expand Down
5 changes: 0 additions & 5 deletions pkg/porter/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ func (p *Porter) InstallBundle(opts InstallOptions) error {
return errors.Wrap(err, "unable to pull bundle before installation")
}

err = p.applyDefaultOptions(&opts.sharedOptions)
if err != nil {
return err
}

err = p.ensureLocalBundleIsUpToDate(opts.bundleFileOptions)
if err != nil {
return err
Expand Down
5 changes: 0 additions & 5 deletions pkg/porter/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ func (p *Porter) InvokeBundle(opts InvokeOptions) error {
return errors.Wrap(err, "unable to pull bundle before invoking the custom action")
}

err = p.applyDefaultOptions(&opts.sharedOptions)
if err != nil {
return err
}

err = p.ensureLocalBundleIsUpToDate(opts.bundleFileOptions)
if err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion pkg/porter/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package porter

import "get.porter.sh/porter/pkg/manifest"
import (
"get.porter.sh/porter/pkg/manifest"
)

// applyDefaultOptions applies more advanced defaults to the options
// based on values that beyond just what was supplied by the user
Expand Down
5 changes: 0 additions & 5 deletions pkg/porter/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ func (p *Porter) UninstallBundle(opts UninstallOptions) error {
return errors.Wrap(err, "unable to pull bundle before uninstall")
}

err = p.applyDefaultOptions(&opts.sharedOptions)
if err != nil {
return err
}

err = p.ensureLocalBundleIsUpToDate(opts.bundleFileOptions)
if err != nil {
return err
Expand Down
5 changes: 0 additions & 5 deletions pkg/porter/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ func (p *Porter) UpgradeBundle(opts UpgradeOptions) error {
return errors.Wrap(err, "unable to pull bundle before upgrade")
}

err = p.applyDefaultOptions(&opts.sharedOptions)
if err != nil {
return err
}

err = p.ensureLocalBundleIsUpToDate(opts.bundleFileOptions)
if err != nil {
return err
Expand Down