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

add optional [bundle-name] for porter create [bundle-name] #2892

Merged
merged 13 commits into from
Sep 6, 2023

Conversation

ludfjig
Copy link
Contributor

@ludfjig ludfjig commented Sep 1, 2023

What does this change

Takes over inactive PR #2778.

porter create now accepts an optional parameter [bundle-name]. A directory bundle-name will be created if it doesn't already exist, and the bundle will be created in there. The bundle name in porter.yaml will also be set to bundle-name.

I think we should consider making this argument required instead of optional even though it's a user facing change, see #2778 (comment). It's also what helm does.

Would appreciate feedback on how to word the command help text, I wasn't able to put it as succinctly as I wanted, and also want to mention that a directory will be created.

What issue does it fix

Closes #2772

Checklist

  • Did you write tests?
  • Did you write documentation?
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
  • If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️

Reviewer Checklist

  • Comment with /azp run test-porter-release if a magefile or build script was modified
  • Comment with /azp run porter-integration if it's a non-trivial PR

pkg/porter/create.go Outdated Show resolved Hide resolved
@ludfjig ludfjig marked this pull request as ready for review September 1, 2023 23:21
@ludfjig ludfjig changed the title adding functionality to port create in a specified directory add optional [bundle-name] for porter create **[bundle-name]** Sep 1, 2023
@ludfjig ludfjig changed the title add optional [bundle-name] for porter create **[bundle-name]** add optional [bundle-name] for porter create [bundle-name] Sep 1, 2023
sbdtu5498 and others added 6 commits September 5, 2023 10:20
Signed-off-by: Ludvig Liljenberg <[email protected]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
cmd/porter/bundle.go Outdated Show resolved Hide resolved
pkg/porter/create.go Outdated Show resolved Hide resolved
Copy link
Member

@schristoff schristoff left a comment

Choose a reason for hiding this comment

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

Looking good so far! 👍🏻

Copy link
Member

@troy0820 troy0820 left a comment

Choose a reason for hiding this comment

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

Couple of nits and some changes needed but this looking good.

}

var err error
if bundleName == "" {
Copy link
Member

Choose a reason for hiding this comment

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

Your logic is repeating itself if it falls through the bundleName case being empty. Returning early with nil would make this check implicit if it isn’t filled out here.

The logic is the same in both cases it’s just where it gets executed. This can make it easier to understand and less things to write.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hopefully this is addressed now that it's 2 different functions

pkg/porter/create.go Outdated Show resolved Hide resolved
_, err := os.Stat(bundleName)
if err != nil && errors.Is(err, os.ErrNotExist) {
err = os.Mkdir(bundleName, os.ModePerm)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Your error is not nil so you don’t have to check it again. Your logic above can be changed to check if it is nil and the. Check if it is the error you are looking for. If it is still nil, you can fall through to the not nil case and not re check the error.

Copy link
Member

Choose a reason for hiding this comment

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

This applies to line 23

Copy link
Contributor Author

Choose a reason for hiding this comment

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

something like this?

	if err != nil {
		if errors.Is(err, os.ErrNotExist) {
			err = os.MkdirAll(dir, os.ModePerm)
		}
		if err != nil {
			return fmt.Errorf("failed to create directory for bundle: %w", err)
		}
	}

if err != nil {
return nil, err
}
content = []byte(strings.ReplaceAll(string(content), "porter-hello", bundleName))
Copy link
Member

Choose a reason for hiding this comment

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

Are we removing the porter-hello hardcoded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, the porter-hello will be replaced

@ludfjig ludfjig force-pushed the porter_create branch 2 times, most recently from a59b9e8 to 8c35a0c Compare September 5, 2023 21:38
Signed-off-by: Ludvig Liljenberg <[email protected]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
pkg/porter/create.go Outdated Show resolved Hide resolved
Signed-off-by: Ludvig Liljenberg <[email protected]>
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@schristoff
Copy link
Member

/azp run porter-integration

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Ludvig Liljenberg <[email protected]>
if err := p.CopyTemplate(p.Templates.GetManifest, filepath.Join(destinationDir, config.Name)); err != nil {
return err
}
return p.copyAllTemplatesExceptPorterYaml(destinationDir)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return p.copyAllTemplatesExceptPorterYaml(destinationDir)
// pass in current directory
return p.copyAllTemplatesExceptPorterYaml(".")

Copy link
Member

@schristoff schristoff left a comment

Choose a reason for hiding this comment

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

One last nit and we are good to go

@schristoff schristoff merged commit 235a441 into getporter:main Sep 6, 2023
16 checks passed
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 create command should create directory with bundle files included
4 participants