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

πŸ› Skip bundle defaults if --tag passed #1199

Merged
merged 8 commits into from Aug 18, 2020

Conversation

dev-drprasad
Copy link
Contributor

@dev-drprasad dev-drprasad commented Aug 5, 2020

What does this change

if --tag passed, porter still tries to validate local manifest file. This PR skips validating manifest file if --tag present

What issue does it fix

Closes #1180

Notes for the reviewer

N/A

Checklist

  • Unit Tests
  • Documentation - N/A
  • Schema (porter.yaml) - N/A

If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! πŸ™‡β€β™€οΈ

@dev-drprasad
Copy link
Contributor Author

In draft, cuz thinking of adding unit tests

@dev-drprasad dev-drprasad marked this pull request as ready for review August 17, 2020 14:54
@dev-drprasad dev-drprasad changed the title πŸ’… Don't worry about porter.yaml if --tag passed πŸ’… Don't worry about porter.yaml in cwd if --tag passed Aug 17, 2020
Copy link
Member

@vdice vdice left a comment

Choose a reason for hiding this comment

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

It looks like there are some test failures to investigate: https://dev.azure.com/deislabs/porter/_build/results?buildId=6704&view=results

I like how elegant the solution looks here, but it may need some adjustments? I sketched out another approach. Not sure if any of the ideas here are worth incorporating: https://github.com/deislabs/porter/compare/main...vdice:fix/defer-to-tag?expand=1

@vdice vdice self-assigned this Aug 17, 2020
@dev-drprasad
Copy link
Contributor Author

@vdice I feel, your solution directly convey the problem we're trying to solve. Let incorporate those changes only

@dev-drprasad dev-drprasad changed the title πŸ’… Don't worry about porter.yaml in cwd if --tag passed πŸ› Skip bundle defaults if --tag passed Aug 18, 2020
@@ -158,6 +160,18 @@ func TestBundleLifecycleOpts_ToActionArgs(t *testing.T) {
assert.Equal(t, opts.Name, args.Installation, "Claim not populated correctly")
assert.Equal(t, opts.RelocationMapping, args.RelocationMapping, "RelocationMapping not populated correctly")
})

t.Run("ignore manifest in cwd if tag present", func(t *testing.T) {
Copy link
Member

@vdice vdice Aug 18, 2020

Choose a reason for hiding this comment

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

Surprisingly, I couldn't get this test to fail when running against the current code on main (meaning, without the changes to cnab.go and lifecycle.go above). Maybe double-check my work.

I succeeded in getting it to fail when explicitly specifying opts.File = "porter.yaml" (and it didn't seem like the working dir logic was strictly necessary):

+++ b/pkg/porter/lifecycle_test.go
@@ -1,8 +1,6 @@
 package porter

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

@@ -164,13 +162,11 @@ func TestBundleLifecycleOpts_ToActionArgs(t *testing.T) {
        t.Run("ignore manifest in cwd if tag present", func(t *testing.T) {
                opts := BundleLifecycleOpts{}
                opts.Tag = "deislabs/kubekahn:latest"
+               opts.File = "porter.yaml"

-               // cnab.go#defaultBundleFiles uses `os.Getwd()`
-               wd, _ := os.Getwd()
-               p.TestConfig.TestContext.AddTestFileContents([]byte(""), path.Join(wd, "porter.yaml"))
+               p.TestConfig.TestContext.AddTestFileContents([]byte(""), "porter.yaml")
                err := opts.Validate(nil, p.Porter)
                require.NoError(t, err, "Validate failed")
-               p.TestConfig.TestContext.FileSystem.Remove(path.Join(wd, "porter.yaml"))
        })
 }

We don't necessarily need to go with the test mods above, but we should make sure that whatever test we have fails without the actual code changes elsewhere in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Surprisingly, I couldn't get this test to fail when running against the current code on main

My bad! Thanks for catching this. Test case indeed failing in my local with main branch. But the reason was something else and I thought test case working as expected πŸ€¦πŸ»β€β™‚οΈ

opts.File = ''porter.yaml" simulates explicitly passing of --file arg. I wanted to test default behaviour without passing --file arg

Comment on lines 173 to 177
p.TestConfig.TestContext.AddTestFileContents([]byte(""), path.Join(wd, config.Name))
// When execution reach to `readFromFile`, manifest file path will be lost.
// So, had to empty default manifest content also
// Below line makes manifest.go#readFromFile#exists true
p.TestConfig.TestContext.AddTestFileContents([]byte(""), config.Name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't make this test fail with main branch with just one empty manifest file.

defaultBundleFiles#manifestExists will be true only if I use path.Join(wd.... and we need it to execute bundle default logic.
But manifest.go#readFromFile func gets only filename (not complete path) and reads manifest file from root directory. So, I had to use root manifest file also

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. The in-line comments help! Thanks for updating.

Copy link
Member

@vdice vdice left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @dev-drprasad

@vdice vdice merged commit 7ae632d into getporter:main Aug 18, 2020
@dev-drprasad dev-drprasad deleted the tag-takes-precendence branch August 19, 2020 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Porter parses local porter.yaml even when using tag flag
2 participants