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

feat(*): add logic to resolve/interpolate output values in a Porter manifest #840

Merged
merged 6 commits into from
Jan 14, 2020

Conversation

vdice
Copy link
Member

@vdice vdice commented Dec 19, 2019

What does this change

Note: Do not merge yet - Blocked by/Depends on cnabio/cnab-spec#300

  • Adds logic to enable using bundle output values in a Porter manifest via the supported templating language
  • As an example, {{ bundle.outputs.foo }} can now be used in a step for action next, which will pull foo's value from the claim, assuming the action that produced the current claim (say, install) produced an output of foo.

One caveat here is that currently, until work is done to address #836, interpolation of these values will only be possible if the previous action supplied the output needed. Otherwise, outputs don't yet span more than one action if the actions spanned don't also produce the same output.

What issue does it fix

Closes #834

Notes for the reviewer

Checklist

  • Unit Tests
  • Documentation
    • Documentation Not Impacted

Sorry, something went wrong.

@carolynvs
Copy link
Member

carolynvs commented Jan 3, 2020

I haven't reviewed this yet but one thing that is important to note about this change is that it creates bundles that can only be run by Porter because it relies upon the client injecting claim data into the runtime at a specific point /cnab/claim.json which isn't part of the spec yet. I don't think that has changed yet upstream, right?

What is our thoughts/policy for changes like this? Is it okay as a prototype that we then use to get an upstream spec change in? But we make sure to document it as experimental which may be removed once the spec is finalized? Or do we want to avoid doing this like this and always do spec first so that we don't make "porter only bundles" even for experimental stuff? We kind of have this as well with dependencies, though I think the other clients respect the spec around required custom extensions, and refuse to try to run those bundles that need dependency support.

cc @jeremyrickard

@vdice
Copy link
Member Author

vdice commented Jan 3, 2020

Good point @carolynvs . While mounting the claim to /cnab/claim.json is proposed in the spec in cnabio/cnab-spec#300, it hasn't yet gained consensus and/or merged. For this particular case, should we just consider this PR blocked until 300 is merged?

@carolynvs
Copy link
Member

My vote is to follow/block on the spec and only make things that are porter only (like dependencies) when we are really prototyping something new and easy to warn people is experimental. This is so subtly different that no one would expect it to not work with other tools.

@vdice
Copy link
Member Author

vdice commented Jan 6, 2020

@carolynvs now that cnabio/cnab-spec#300 is merged, this should be ready for review.

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.

I'm having trouble telling if this preserved the existing functionality of how {{ bundle.outputs.NAME }} worked. Where a step within an action can produce an output and the next step within that action can consume it using bundle.outputs.NAME.

I was expecting to see resolveOutputs first look in the step outputs (bun.outputs) and then fallback to the output value from the claim. Did I miss this part in the code?

// e.g. via {{ bundle.outputs.foo }}
// It looks up the claim for the value written by the last action and, if exists, returns this value
func (m *RuntimeManifest) resolveOutput(output manifest.OutputDefinition) (string, error) {
if m.Action != manifest.ActionInstall {
Copy link
Member

Choose a reason for hiding this comment

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

I believe we have upcoming work to support running stateless custom actions before install is executes, i.e. without a claim. I suggest changing this to check if the claim is present, and if not, skip without relying on the action.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call. Will update to check if the claim is present, as suggested.

@vdice
Copy link
Member Author

vdice commented Jan 7, 2020

I was expecting to see resolveOutputs first look in the step outputs (bun.outputs) and then fallback to the output value from the claim. Did I miss this part in the code?

Indeed, I'm adding this now. Working on integration test coverage for these two cases (step-level and bundle-level outputs).

@vdice vdice force-pushed the feat/resolve-outputs branch from 1614e99 to 8bc2b15 Compare January 8, 2020 20:58
@vdice
Copy link
Member Author

vdice commented Jan 8, 2020

Ok @carolynvs , this is back and ready for re-review when convenient. Thanks!

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

I'll leave it to you to merge in case you wanted to address the nit or not

return m.outputs[output.Name], nil
}

if claimBytes, err := m.FileSystem.ReadFile(config.ClaimFilepath); 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.

nit: How about we make a new function loadClaim and then run it from Validate (which is called once before any steps are run). Then we don't reparse the claim for each output reference.

Copy link
Member Author

Choose a reason for hiding this comment

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

Definitely, good thinking. This logic has been revised appropriately.

m.sensitiveValues = append(m.sensitiveValues, output)
// Iterate through the runtime manifest's step outputs and mask by default
for _, stepOutput := range m.outputs {
// TODO: check if output declared sensitive or not; currently we default always sensitive
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to create a follow-up issue to track this todo?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call; I created #855 and added a link below this comment.

@vdice vdice force-pushed the feat/resolve-outputs branch from a9f795a to 209e760 Compare January 14, 2020 15:28
@vdice vdice force-pushed the feat/resolve-outputs branch from 209e760 to d24d773 Compare January 14, 2020 16:18
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.

Yay! 🚢 while it's 🔥

@vdice vdice merged commit 25a89dd into getporter:master Jan 14, 2020
@vdice vdice deleted the feat/resolve-outputs branch January 14, 2020 16:37
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.

output from previous action cannot be used
2 participants