From 7ae632d26d81abda1e06fe178c26532b4be0ddfd Mon Sep 17 00:00:00 2001 From: REDDY PRASAD Date: Wed, 19 Aug 2020 00:59:24 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Skip=20bundle=20defaults=20if=20?= =?UTF-8?q?--tag=20passed=20(#1199)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 💅 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 --- pkg/porter/cnab.go | 11 ++++++++--- pkg/porter/lifecycle.go | 11 +++++++---- pkg/porter/lifecycle_test.go | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/pkg/porter/cnab.go b/pkg/porter/cnab.go index ef0733906..9f136dd13 100644 --- a/pkg/porter/cnab.go +++ b/pkg/porter/cnab.go @@ -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 { @@ -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 diff --git a/pkg/porter/lifecycle.go b/pkg/porter/lifecycle.go index 9537c52dc..9fde16cbd 100644 --- a/pkg/porter/lifecycle.go +++ b/pkg/porter/lifecycle.go @@ -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 } diff --git a/pkg/porter/lifecycle_test.go b/pkg/porter/lifecycle_test.go index 7f0a02591..cb947a363 100644 --- a/pkg/porter/lifecycle_test.go +++ b/pkg/porter/lifecycle_test.go @@ -1,6 +1,8 @@ package porter import ( + "os" + "path" "path/filepath" "testing" @@ -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)