-
Notifications
You must be signed in to change notification settings - Fork 208
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
Feat: bundle outputs #438
Feat: bundle outputs #438
Conversation
de619e6
to
759d16d
Compare
In the most recent commit, I went ahead and added the cli commands mentioned/proposed in #344 (comment) |
Putting into 'ready for review' while I finish up unit tests... |
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.
I'm not done with the review but wanted to get you thinking about maybe moving the command into a different spot.
cmd/porter/outputs.go
Outdated
|
||
func buildOutputsCommand(p *porter.Porter) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "outputs", |
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.
I think that this would be better not as a standalone command but as a task-based command that is used to inspect an installed bundle.
So instead of having porter outputs -b bundle name
(which is off anyway because we are actually working with claim names right?), what if we had a command that let you look at an installed bundle and also had it dig deeper into additional available into (like outputs) if the bundle had it?
Maybe something like this:
$ porter bundles list
NAME CREATED MODIFIED LAST ACTION LAST STATUS
mysql 2019-06-24 2019-06-24 install success
$ porter bundle show mysql
Name mysql
Created 2019-06-24
Modified 2019-06-24
Last Action install
Last Status success
Outputs
=====================================================================
Name Type Value
-----------+--------+--------------------------------------------------------+
hostName String wpmysql
port Integer 5423
clientCert String /Users/carolynvs/.porter/outputs/.../mysql/clientCert
clientCert is writeOnly so we don't display it. Find some logic for not dumping sensitive or giant info
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.
Roger; I can switch tactics and implement porter bundle show [NAME]
to show bundle/claim deets, including outputs.
Should we leave this PR with that command or do we also want a solution/command for getting a particular output value? (Perhaps to merely echo/print or perhaps to send to a file, etc.)
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.
If someone wants to just get a single output value, I would encourage them to use the --output json and then use jq or something to grab what they need. Maybe we can start with that for now and see if people want a more specialize command like porter bundle output list/show
to work directly with outputs. We may never need to implement it, depending on lack of asks/feedback.
How does that sound?
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.
That sounds good to me. My only question revolves around the case when an actual output value is large (think: kubeconfig file) while listing. Shall we just default to truncating all values at a certain character limit when printing via default/table and print the entire value if the printing option is otherwise (yaml or json)?
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.
Let's start with truncating at certain number of characters and see how well that works.
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.
Ok, updated to limit cli scope to just the porter bundle show
command. Please take a look when convenient.
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 PR will also need to update the base porters schema template to include the outputs section
fa0cae3
to
03d18f8
Compare
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.
Still working through the PR. Looking good but thought that I'd give some more feedback while I keep reviewing.
uninstall: | ||
- kubernetes: | ||
description: "Uninstall Hello World" | ||
manifests: |
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.
nice catch! 😅
pkg/cnab/provider/duffle.go
Outdated
) | ||
|
||
type Provider interface { |
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 interface is defined in the package that uses it (not the packge that implements it) which is a bit of a "go ism". So you should remove this interface declaration here, and move FetchClaim
to pkg/porter/cnab.go CNABProvider
@@ -34,5 +43,41 @@ func (d *Duffle) newDriver(driverName string) (driver.Driver, error) { | |||
configurable.SetConfig(driverCfg) | |||
} | |||
|
|||
// If docker driver, setup host bind mount for outputs | |||
// TODO: separate function/add tests | |||
if dockerish, ok := driverImpl.(*duffledriver.DockerDriver); ok { |
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.
It would be nice to see this logic separated into a function (like pkg/cnab/provider/credentials.go loadCredentials
).
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.
Separated, though unfortunately we can't yet test as thoroughly as we'd wish (no access yet to the docker driver configuration options... TODO note added.)
pkg/cnab/provider/duffle.go
Outdated
|
||
// Create outputs sub-directory using the bundle name | ||
bundleOutputsDir := filepath.Join(outputsDir, claimName) | ||
err = d.FileSystem.MkdirAll(bundleOutputsDir, 0755) |
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.
I think the permissions on that folder may be wrong, because it lets anyone on the machine read outputs created by the bundle. Let's do a sweep on permissions in a separate issue. I'll make one so that we can use a variable for this stuff going forward.
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.
I've changed to os.ModePerm
for now... w/ intentions to follow-up across codebase in issue you've mentioned...
pkg/cnab/provider/duffle.go
Outdated
return driverImpl, err | ||
} | ||
|
||
func (d *Duffle) FetchClaim(name string) (*claim.Claim, 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.
👍
pkg/cnab/provider/helpers.go
Outdated
} | ||
|
||
type TestStore struct { | ||
backingStore map[string][]byte |
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.
I feel bad because you implemented all of this but I'm pretty sure we could have also used afero here and not written a test backing store at all. It would be an afero in memory file system from the test context (which we got from the constructor of the TestDuffle) and then the existing crud claim store.
I think that would be preferable to reimplementing another claim store? Let me know i you'd like to collaborate quick on how to use afero to do that.
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.
Oops! Good call; using afero was the way to go. This file has since been removed.
return errors.New("output name is required") | ||
} | ||
|
||
// TODO: Validate inline Schema |
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.
Haha, yeah that's a big task on our plate in general for CNAB 1.0 no need to tackle it as part of this PR. 😀
pkg/porter/build.go
Outdated
return errors.Wrap(err, "unable to get outputs directory") | ||
} | ||
|
||
err = p.FileSystem.MkdirAll(outputsDir, 0755) |
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.
I'm a bit unsure of the code's intent right here? This function is meant to create files on the local file system in pwd/.cnab in preparation before building the invocation image.
If we need to make the outputs directory ahead of time, then the code should be doing this:
p.FileSystem.MkdirAll(filepath.Join(build.LOCAL_APP, "outputs"), 0755)
Otherwise if your intent was to make sure the outputs directory in PORTER_HOME exists before the bundle is run (which is what this code is doing), then it's in the wrong spot. It should be located in maybe pkg/porter/options.go applyDefaultOptions
or really a new function that is executed in each function before calling the cnab provider functions for install/upgrade/etc.
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.
You know, I think we're okay with not ensuring the outputs directory exists before a bundle is run. The logic around setting up the volume mount (if driver is the default Docker driver) is sufficient (will create ${PORTER_HOME}/outputs
if it doesn't already exist, in addition to the <claim name>
subdir.)
So, I've removed for now.
pkg/porter/list.go
Outdated
@@ -40,6 +40,8 @@ func (l CondensedClaimList) Less(i, j int) bool { | |||
|
|||
// ListBundles lists installed bundles using the printer.Format provided | |||
func (p *Porter) ListBundles(opts printer.PrintOptions) error { | |||
// TODO: supply cnab.Provider interface as second arg, use to access ClaimStore |
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.
Once you move FetchClaim
like I suggested above, then you will immediate have access to it, because CNABProvider is already on the Porter receiver here.
03d18f8
to
cbe30f3
Compare
Ok, latest commits are up intending to address all feedback. Lemme know if there are any outstanding items; otherwise I/we can squash commits and merge when ready. |
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 is good to merge. You've got a ton of commits but I wasn't sure if you wanted to do one big squash or an artisanal rebase. Up to you, feel free to merge at will! 👍
This PR adds:
outputs
section in a porter manifest (Note: the current implementation requires a mixin-specific step/action output to be declared before it can be exposed/used as a bundle-level output.)/cnab/app/outputs
in the execution environment, per the CNAB Spec (outputs are currently written only when added under the newoutputs
section and the optionalapplyTo
specification doesn't conflict)$PORTER_HOME/outputs/<bundle name>
directory, assuming the default Docker driver is being usedporter bundle show
to list a bundle's claim and outputsTODO:
run.go