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

use mustache to wire up params, creds, outputs #264

Merged
merged 7 commits into from
Apr 16, 2019

Conversation

jeremyrickard
Copy link
Contributor

@jeremyrickard jeremyrickard commented Apr 12, 2019

This PR changes how we wire params, credentials and outputs between steps. Instead of the previous "source:" bundle.x.y.z, now we use Mustache templates.

  • Introduce
  • Update docs
  • Fix e2e tests

Closes #161

@ghost ghost assigned jeremyrickard Apr 12, 2019
@ghost ghost added the review label Apr 12, 2019
@jeremyrickard jeremyrickard changed the title WIP: use mustache to wire up params, creds, outputs use mustache to wire up params, creds, outputs Apr 15, 2019
@jeremyrickard
Copy link
Contributor Author

@carolynvs @vdice take a look.

The only thing I'm kind of bummed about in this is that the mustache templates need to be quoted, otherwise the go marshalling isn't happy. Maybe we need to change how the marshalling works and only marshall the steps after they've been fully resolved? This seems like a big enough change to review on it's own though, tackle that in another refactor.

@carolynvs
Copy link
Member

I'm not sure I see how to resolve before we've parsed the file, but you are closer than I am to it for sure. Yeah let's go with this for now and iterate.

@jeremyrickard
Copy link
Contributor Author

I'm not sure I see how to resolve before we've parsed the file, but you are closer than I am to it for sure. Yeah let's go with this for now and iterate.

I was thinking more that we wouldn't fully try and rehydrate a struct with the yaml marsheller, but I don't know if that's possible. just thinking out loud

source: bundle.parameters.database-name
mysqlUser:
source: bundle.parameters.mysql-user
mysqlDatabase: "{{ bundle.parameters.database-name}}"
Copy link
Member

Choose a reason for hiding this comment

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

muy bien!

source: bundle.parameters.database-name
mysqlUser:
source: bundle.parameters.mysql-user
mysqlDatabase: {{ bundle.parameters.database-name }}
Copy link
Member

Choose a reason for hiding this comment

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

should these have quotes?

source: bundle.parameters.database-name
mysqlUser:
source: bundle.parameters.mysql-user
mysqlDatabase: {{ bundle.parameters.database-name }}
Copy link
Member

Choose a reason for hiding this comment

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

should these have quotes?

@@ -95,23 +95,18 @@ install:
key: mysql-password
- helm:
description: "Install Wordpress"
name:
source: bundle.parameters.wordpress-name
name: {{ bundle.parameters.wordpress-name }}
Copy link
Member

Choose a reason for hiding this comment

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

Seems like all the markdown files are missing quotes around the moustash template

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, I forgot to update them! Thanks for pointing that out.

@@ -29,7 +29,7 @@ You can also provide any other attributes, as specified by the CNAB [parameters]

## Wiring Parameters

Once a parameter has been declared in the `porter.yaml`, Porter provides a simple mechanism for specifying how the parameter value should be wired into the mixin. To reference a parameter in the bundle, you use a notation of the form `source: bundle.parameters.PARAM_NAME`. This can be used anywhere within step definition. For example, to use the `database_name` parameter defined above in the `set` block of the helm mixin:
Once a parameter has been declared in the `porter.yaml`, Porter provides a simple mechanism for specifying how the parameter value should be wired into the mixin. To reference a parameter in the bundle, you use a notation of the form `{{ bundle.parameters.PARAM_NAME }}`. This can be used anywhere within step definition. For example, to use the `database_name` parameter defined above in the `set` block of the helm mixin:
Copy link
Member

Choose a reason for hiding this comment

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

we should mention the surrounding quotes

data := make(map[string]interface{})
m.sensitiveValues = []string{}
bundle := make(map[string]interface{})
data["bundle"] = bundle
Copy link
Member

Choose a reason for hiding this comment

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

This is a question about mustache. Looks like we are building up a map that has keys for parameters, outputs, etc inside of it, then that's what the template is operating upon.

If we had a struct called "TemplateMagicPants" (or whatever) and it had fields for parameters, outputs, credentials, and everything else we needed, would that work too as input data to mustache? Or would that result in different syntax in the template?

This is just a question for me to understand mustache, not asking you to change anything. 😀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'd need to have a struct called TemplateMagicPants that had those, that lived in a map with the key bundle. Or another struct. It's walking what ever the template syntax is. I was trying to keep it mostly the same, and I think the comment from our Amazon friends used similar syntax.

I did find myself wondering what the point of the "bundle" is. everything is rooted off that....soooooo maybe just {{ parameters.x }} or {{ outputs.y }} or {{ credentials.z }} or {{ dependencies.x.y.z }}

I was thinking along these lines for the general refactor of "the manifest" from the running state of things, but here I didn't want to change the syntax of the template since we hadn't chatted about that. Happy to go either way, but I think my opinion is the "bundle" key is not really needed?

Copy link
Member

Choose a reason for hiding this comment

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

Let's not remove the bundle. prefix for now. I believe that it is important for both giving people a starting point in their heads for what to type, and also for the autocomplete to have something to go off of.

return nil, err
}
if param.Sensitive {
m.sensitiveValues = append(m.sensitiveValues, val)
Copy link
Member

Choose a reason for hiding this comment

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

This isn't on you, but the sensitive values stuff is in desperate need of a refactor so that it's not tied to the manifest like this. I can't wait for your work to split out the runtime from the manifest as I believe that's something we identified as being helpful in order to do the masking in a less obtrusive way going forward. 🤞

creds := make(map[string]interface{})
bundle["credentials"] = creds
for _, cred := range m.Credentials {
//pe := strings.ToUpper(cred.Name)
Copy link
Member

Choose a reason for hiding this comment

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

can we nuke this comment?

return nil, errors.New(fmt.Sprintf("no value found for source specification: %s", key))
payload, err := yaml.Marshal(step)
if err != nil {
return errors.Wrap(err, "unable to resolve step")
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 not sure wrapping all these various errors with the same error message is going to be helpful? Having a bit more context about what was going on may be useful when dealing with errors like "unable to resolve step: unexpected EOF", you know?

}
return replacement, nil
return yaml.Unmarshal([]byte(rendered), step)
Copy link
Member

Choose a reason for hiding this comment

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

this last error isn't being wrapped

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.

such quotes, much wow 🐶

@carolynvs
Copy link
Member

Merge at will

@jeremyrickard jeremyrickard merged commit 3db86bc into getporter:master Apr 16, 2019
@ghost ghost removed the review label Apr 16, 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.

Iterate on variable references
3 participants