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

Enhances how we're handling sourcing #162

Merged
merged 2 commits into from Feb 13, 2019

Conversation

jeremyrickard
Copy link
Contributor

This PR updates how we handle slice elements for doing parameter/credential/ouput sourcing.
We probably should think about revisiting the entire process for this in the future.

In summary, we are using reflectwalk to handle walking the manifest. This involves handling a couple
call backs, notably "SliceElement" and "MapElement". The Slice Element assumed that it would see something
of the form source: <x.y.z> as a string. In reality, if that's not wrapped in quote, Go and YAML see that
as a Map, but the map callback doesn't get called to handle that. This was resulting in the block not getting
rewritten and the exec mixin was exploding (probably any would have). This PR updates the logic of the slice elem processing to check and see if it's a map and handle it in a similar manner to a top level map entry in the yaml.

Closes: #158

@ghost ghost assigned jeremyrickard Feb 13, 2019
@ghost ghost added the review label Feb 13, 2019
…put sourcing

This PR updates how we handle slice elements for doing parameter/credential/ouput sourcing.
We probably should think about revisitng the entire process for this in the future.

In summary, we are using reflectwalk to handle walking the manifest. This involves handling a couple
call backs, notably "SliceElement" and "MapElement". The Slice Element assumed that it would see something
of the form source: <x.y.z> as a string. In reality, if that's not wrapped in quote, Go and YAML see that
as a Map, but the map callback doesn't get called to handle that. This was resulting in the block not getting
rewritten and the exec mixin was exploding (probably any would have). This PR updates the logic of the slice elem
processing to check and see if it's a map and handle it in a similar manner to a top level map entry in the yaml.

Closes: getporter#158
carolynvs
carolynvs previously approved these changes Feb 13, 2019
// command: bash
// arguments:
// - -c
// - "source: bundle.parameters.command"
Copy link
Member

Choose a reason for hiding this comment

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

I don't want to make this harder, because I agree that we need to rethink how we do sourcing anyway. But when I look at the two here,

  • "source: bundle.parameters.command"
  • source: bundle.parameters.command

My reaction is that the first one shouldn't even be parsed by porter and should be ignored really. It's only the second that matches how source works everywhere else.

Does that simplify this PR? If so, can we nix the first case "source as a string"? If it makes it harder, then leave it as it. 😀

if sk.Kind() == reflect.Interface {
sk = sk.Elem()
}
//if the key is a string, and the string is source, then we should try
Copy link
Member

Choose a reason for hiding this comment

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

Like if we stop supporting - "source: bundle...." does this entire block go away?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the opposite. This got added to support the other case where there are no quotes.

This is the part that handles the quotes:

v, ok := val.Interface().(string)
	if ok {
		//if the array entry is a string that matches source:...., we should replace it
		re := regexp.MustCompile("source:\\s?(.*)")
		matches := re.FindStringSubmatch(v)
		if len(matches) > 0 {
			source := matches[1]
			r, err := m.resolveValue(source)
			if err != nil {
				return errors.Wrap(err, "unable to source value")
			}
			val.Set(reflect.ValueOf(r))
		}
	}

Copy link
Member

Choose a reason for hiding this comment

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

Oh noes, I've been found out. I have a really hard time reading this reflection code.

I'm ok merging this as-is. Up to you if you think we can just remove the "source: bundle...." case and make things simpler or not.

command: bash
arguments:
- -c
- source: bundle.parameters.command
Copy link
Member

Choose a reason for hiding this comment

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

This looks natural to me, based on how we do source elsewhere.

Ok I've said it 3 ways. I'll stop now. 😇

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, to support this form, the change i added is needed. Both this and "source:...." are valid YAML, so I think we should support both for right now.

We should probably fix this in general though..but also:

arguments: 
   - asdadadad
   - {bundle.params.blah}

will probably have similar stupid YAML processing outcomes for example, that block above gets turned into:

args: 
  - blah
  - 
    bundle.parameters.blah: ~

by a validator, which is even worse. I think in that case it might require quotes to make things simpler.

Copy link
Member

Choose a reason for hiding this comment

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

rawr 🦁 Ok I see why this is hard.

I say ship it and then reasses later.

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.

Oops I mean to comment, not approve

@carolynvs carolynvs dismissed their stale review February 13, 2019 22:03

wanted to just commnet

command: bash
arguments:
- -c
- source: bundle.parameters.command
Copy link
Member

Choose a reason for hiding this comment

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

rawr 🦁 Ok I see why this is hard.

I say ship it and then reasses later.

@carolynvs carolynvs merged commit a2196ba into getporter:master Feb 13, 2019
@ghost ghost removed the review label Feb 13, 2019
nunix added a commit to nunix/wslcnab that referenced this pull request Feb 19, 2019
- added bundle variables (after porter [PR #162](getporter/porter#162)
- full path to commands used
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.

None yet

2 participants