Skip to content

Commit

Permalink
πŸ› Skip bundle defaults if --tag passed (#1199)
Browse files Browse the repository at this point in the history
* πŸ’… Don't worry about porter.yaml if --tag passed

* βœ… Add unit test

* ✏️ Update comment

* πŸ™πŸΌ Hope this make tests pass. tests run slowly in local

* πŸ‘ŒπŸΌ Incorporate review feedback

* πŸ“ Don't think this make makes sense anymore

* πŸ› Fix test case

* πŸ“ Improve code comments
  • Loading branch information
dev-drprasad committed Aug 18, 2020
1 parent ed1e19f commit 7ae632d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
11 changes: 8 additions & 3 deletions pkg/porter/cnab.go
Expand Up @@ -34,6 +34,9 @@ type bundleFileOptions struct {

// RelocationMapping is the path to the relocation-mapping.json file, if one exists. Populated only for published bundles
RelocationMapping string

// TagSet indicates whether a bundle tag is present, to determine whether or not to default bundle files
TagSet bool
}

func (o *bundleFileOptions) Validate(cxt *context.Context) error {
Expand All @@ -42,9 +45,11 @@ func (o *bundleFileOptions) Validate(cxt *context.Context) error {
return err
}

err = o.defaultBundleFiles(cxt)
if err != nil {
return err
if !o.TagSet {
err = o.defaultBundleFiles(cxt)
if err != nil {
return err
}
}

return err
Expand Down
11 changes: 7 additions & 4 deletions pkg/porter/lifecycle.go
Expand Up @@ -12,18 +12,21 @@ type BundleLifecycleOpts struct {
}

func (o *BundleLifecycleOpts) Validate(args []string, porter *Porter) error {
err := o.sharedOptions.Validate(args, porter)
if err != nil {
return err
}

if o.Tag != "" {
// Ignore anything set based on the bundle directory we are in, go off of the tag
o.File = ""
o.CNABFile = ""
o.TagSet = true

return o.validateTag()
}

err := o.sharedOptions.Validate(args, porter)
if err != nil {
return err
}

return nil
}

Expand Down
21 changes: 21 additions & 0 deletions pkg/porter/lifecycle_test.go
@@ -1,6 +1,8 @@
package porter

import (
"os"
"path"
"path/filepath"
"testing"

Expand Down Expand Up @@ -160,6 +162,25 @@ func TestBundleLifecycleOpts_ToActionArgs(t *testing.T) {
})
}

func TestManifestIgnoredWithTag(t *testing.T) {
p := NewTestPorter(t)
t.Run("ignore manifest in cwd if tag present", func(t *testing.T) {
opts := BundleLifecycleOpts{}
opts.Tag = "deislabs/kubekahn:latest"

wd, _ := os.Getwd()
// `path.Join(wd...` -> makes cnab.go#defaultBundleFiles#manifestExists `true`
// Only when `manifestExists` eq to `true`, default bundle logic will run
p.TestConfig.TestContext.AddTestFileContents([]byte(""), path.Join(wd, config.Name))
// When execution reach to `readFromFile`, manifest file path will be lost.
// So, had to use root manifest file also for error simuation purpose
p.TestConfig.TestContext.AddTestFileContents([]byte(""), config.Name)

err := opts.Validate(nil, p.Porter)
require.NoError(t, err, "Validate failed")
})
}

func TestInstallFromTag_ManageFromClaim(t *testing.T) {
p := NewTestPorter(t)

Expand Down

0 comments on commit 7ae632d

Please sign in to comment.