-
Notifications
You must be signed in to change notification settings - Fork 212
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
Conversation
porter create **[bundle-name]**
porter create **[bundle-name]**
porter create [bundle-name]
Signed-off-by: Sanskar Bhushan <[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]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
42f2dcd
to
f7f2395
Compare
Signed-off-by: Ludvig Liljenberg <[email protected]>
There was a problem hiding this 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! 👍🏻
There was a problem hiding this 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.
pkg/porter/create.go
Outdated
} | ||
|
||
var err error | ||
if bundleName == "" { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
_, err := os.Stat(bundleName) | ||
if err != nil && errors.Is(err, os.ErrNotExist) { | ||
err = os.Mkdir(bundleName, os.ModePerm) | ||
if err != nil { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
}
}
pkg/porter/create.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
content = []byte(strings.ReplaceAll(string(content), "porter-hello", bundleName)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
a59b9e8
to
8c35a0c
Compare
Signed-off-by: Ludvig Liljenberg <[email protected]>
8c35a0c
to
7fa75da
Compare
Signed-off-by: Ludvig Liljenberg <[email protected]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
a3a2db1
to
f5c75d2
Compare
Signed-off-by: Ludvig Liljenberg <[email protected]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run porter-integration |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return p.copyAllTemplatesExceptPorterYaml(destinationDir) | |
// pass in current directory | |
return p.copyAllTemplatesExceptPorterYaml(".") |
There was a problem hiding this 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
What does this change
Takes over inactive PR #2778.
porter create
now accepts an optional parameter[bundle-name]
. A directorybundle-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 tobundle-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
Reviewer Checklist