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 a porter explain command #646

Merged
merged 3 commits into from
Sep 26, 2019

Conversation

jeremyrickard
Copy link
Contributor

@jeremyrickard jeremyrickard commented Sep 24, 2019

Closes:

What does this change

This PR adds a new explain command that prints usage information for a bundle! Long gone are the days of trying to figure out how to use the bundle by running install until it works!

$ porter explain --tag jeremyrickard/porter-do-bundle:v0.4.1
Name: spring-music
Description: Run the Spring Music Service on Kubernetes and Digital Ocean PostgreSQL
Version: 0.4.1

Credentials:
+------------------+--------------------------------+----------+
|       NAME       |          DESCRIPTION           | REQUIRED |
+------------------+--------------------------------+----------+
| kubeconfig       | Kube config file with          | false    |
|                  | permissions to deploy app      |          |
| do_access_token  | Access Token for Digital Ocean | false    |
|                  | Account                        |          |
| do_spaces_key    | DO Spaces API Key              | false    |
| do_spaces_secret | DO Spaces API Secret           | false    |
+------------------+--------------------------------+----------+

Parameters:
+---------------+--------------------------------+---------+-------------------+----------+-------------+
|     NAME      |          DESCRIPTION           |  TYPE   |      DEFAULT      | REQUIRED | APPLIES TO  |
+---------------+--------------------------------+---------+-------------------+----------+-------------+
| node_count    | Number of database nodes       | integer | 1                 | false    | All Actions |
| porter-debug  | Print debug information from   | boolean | false             | false    | All Actions |
|               | Porter when executing the      |         |                   |          |             |
|               | bundle                         |         |                   |          |             |
| region        | Region to create Database and  | string  | nyc3              | false    | All Actions |
|               | DO Space                       |         |                   |          |             |
| space_name    | Name for DO Space              | string  | jrrportertest     | false    | All Actions |
| database_name | Name of database to create     | string  | jrrportertest     | false    | All Actions |
| helm_release  | Helm release name              | string  | spring-music-helm | false    | All Actions |
| namespace     | Namespace to install Spring    | string  | default           | false    | All Actions |
|               | Music app                      |         |                   |          |             |
+---------------+--------------------------------+---------+-------------------+----------+-------------+

Outputs:
+------------+--------------------------------+--------+-------------+
|    NAME    |          DESCRIPTION           |  TYPE  | APPLIES TO  |
+------------+--------------------------------+--------+-------------+
| service_ip | IP Address assigned to the     | string | All Actions |
|            | Load Balancer                  |        |             |
+------------+--------------------------------+--------+-------------+

No custom actions defined

This also provides support for json and yaml output.

An implementation note: I defined "Printable" types for this that only expose some of the fields of each type AND remove the omitempty on the json/yaml tags. I felt it was important to show values, even when they'd be omitted because they were "empty" (i.e. false...).

What issue does it fix

Closes #635

If there is not an existing issue, please make sure we have context on why this change is needed. See our Contributing Guide for examples of when an existing issue isn't necessary.

Notes for the reviewer

  • I added a new explain.go file, because bundle is getting rather large and I think I'd eventually like to explode this command more and support like an "explain" command on parameters or outputs themselves, like print the JSON schema in a useful format so you could leverage that info when crafting parameters.

Checklist

  • Unit Tests
  • Documentation

This PR adds a new `explain` command that prints usage information
for a bundle

Closes: getporter#635
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.

Only one real code change question; other comment just a thought/brainstorm. Otherwise, LGTM!

if err != nil {
return err
}
err = p.ensureLocalBundleIsUpToDate(o.bundleFileOptions)
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking this call is not necessary, right? (Would re-build if bundle differed/out-of-date with local manifest.)

Copy link
Member

@vdice vdice Sep 24, 2019

Choose a reason for hiding this comment

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

Actually, even though perhaps a main use case would be to explain a remote bundle, I can also see a use case for explaining a local bundle... in that scenario, we would want to ensure it'd be up-to-date. Therefore, seems we'd want to keep this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we for sure want to be able to use this on canonical JSON bundle files that are supper hard to read or a porter.yaml that people might have shared with others.


params := map[string]PrintableParameter{}
for p, v := range bun.Parameters {
def, ok := bun.Definitions[v.Definition]
Copy link
Member

Choose a reason for hiding this comment

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

Idea that this reminded me of whilst writin' similar code in Porter: We should add a helper func in cnab-go, GetDefinition(paramOrOutput) or some such (may need a function for each type), that'd return a parameter's/output's definition or return the corresponding error (not found/empty/etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That’s a good idea. Do you want to file an issue for it?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @vdice!

Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Looks great! Just some comments related to code consistency.

As a follow up, we should add this to the docs side bar
https://github.com/deislabs/porter/blob/7da5cffdf3581c27dfab03af88df2df005baa02d/docs/config.toml#L43-L47

cmd/porter/explain.go Outdated Show resolved Hide resolved
pkg/porter/explain.go Outdated Show resolved Hide resolved
pkg/porter/explain.go Show resolved Hide resolved
pkg/porter/explain.go Outdated Show resolved Hide resolved
pkg/porter/explain.go Outdated Show resolved Hide resolved
pkg/porter/explain.go Outdated Show resolved Hide resolved
@@ -0,0 +1,20 @@
Name: HELLO
Copy link
Member

Choose a reason for hiding this comment

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

🤩

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there supposed to be an emoji here? I see a square :/

Copy link
Member

Choose a reason for hiding this comment

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

Screen Shot 2019-09-26 at 2 13 01 PM

GITHUB Y U NO HAVE STARSTUCK EMOJI!

@jeremyrickard
Copy link
Contributor Author

Updated this to use our pkg/printer, new table format is thus:

$ porter explain --tag jeremyrickard/porter-do-bundle:v0.4.1
Name: spring-music
Description: Run the Spring Music Service on Kubernetes and Digital Ocean PostgreSQL
Version: 0.4.1

Credentials:
Name               Description                                       Required
do_access_token    Access Token for Digital Ocean Account            false
do_spaces_key      DO Spaces API Key                                 false
do_spaces_secret   DO Spaces API Secret                              false
kubeconfig         Kube config file with permissions to deploy app   false

Parameters:
Name            Description                                                     Type      Default             Required   Applies To
database_name   Name of database to create                                      string    jrrportertest       false      All Actions
helm_release    Helm release name                                               string    spring-music-helm   false      All Actions
namespace       Namespace to install Spring Music app                           string    default             false      All Actions
node_count      Number of database nodes                                        integer   1                   false      All Actions
porter-debug    Print debug information from Porter when executing the bundle   boolean   false               false      All Actions
region          Region to create Database and DO Space                          string    nyc3                false      All Actions
space_name      Name for DO Space                                               string    jrrportertest       false      All Actions

Outputs:
Name         Description                                Type     Applies To
service_ip   IP Address assigned to the Load Balancer   string   All Actions

No custom actions defined

Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@@ -221,7 +221,11 @@ defaultContentLanguage = "en"
identifier = "wiring"
weight = 303
parent = "authoring-bundles"

[[menu.main]]
Copy link
Member

Choose a reason for hiding this comment

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

oh my gosh! I hope you didn't think that I was trying to say that you should write net new docs! I mean that's great that you did, I was just saying that you should link to the autogenerated docs for porter explain from the nav. Sorry about that if I was unclear. No worries, we can add the link in a follow-up.

Screen Shot 2019-09-26 at 2 17 14 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh i thought i added that one too :) sorrrry.

@@ -13,6 +13,11 @@ invocationImage: deislabs/porter-kubernetes:latest
tag: deislabs/porter-kube-bundle:v0.1.0

install:
- exec:
Copy link
Member

Choose a reason for hiding this comment

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

Did you intend to add this permanently to the example? Or was this accidentally included from our debugging session last night?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

embarassed emoji.....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me go clean that up :)

@carolynvs carolynvs merged commit e70ea38 into getporter:master Sep 26, 2019
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.

[enhancement] Let's add a porter explain or porter inspect command
3 participants