-
Notifications
You must be signed in to change notification settings - Fork 197
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -546,6 +546,24 @@ func (m *Manifest) SliceElem(index int, val reflect.Value) error { | |
return nil | ||
} | ||
|
||
// There are two cases possible in the YAML. The first is when the element in the slice is a string. That might look like: | ||
// install: | ||
// - description: "Install Hello World" | ||
// exec: | ||
// command: bash | ||
// arguments: | ||
// - -c | ||
// - "source: bundle.parameters.command" | ||
// The second case is when the declaration interpreted to represent a Map. This is the case when there are no quotes: | ||
// install: | ||
// - description: "Install Hello World" | ||
// exec: | ||
// command: bash | ||
// arguments: | ||
// - -c | ||
// - source: bundle.parameters.command | ||
// Branching logic below first checks the easy case (a string) then falls through into the case where we have a map with a single key. | ||
// This is fairly similar to how we process map elements, but the replacement is done differently. | ||
v, ok := val.Interface().(string) | ||
if ok { | ||
//if the array entry is a string that matches source:...., we should replace it | ||
|
@@ -559,6 +577,34 @@ func (m *Manifest) SliceElem(index int, val reflect.Value) error { | |
} | ||
val.Set(reflect.ValueOf(r)) | ||
} | ||
} else { | ||
v := val | ||
if val.Kind() == reflect.Interface { | ||
val = val.Elem() | ||
} | ||
if kind := val.Kind(); kind == reflect.Map { | ||
if len(val.MapKeys()) == 1 { | ||
sk := val.MapKeys()[0] | ||
if sk.Kind() == reflect.Interface { | ||
sk = sk.Elem() | ||
} | ||
//if the key is a string, and the string is source, then we should try | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like if we stop supporting There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
//and replace this | ||
if sk.Kind() == reflect.String && sk.String() == "source" { | ||
kv := val.MapIndex(sk) | ||
if kv.Kind() == reflect.Interface { | ||
kv = kv.Elem() | ||
value := kv.String() | ||
replacement, err := m.resolveValue(value) | ||
if err != nil { | ||
errors.Wrap(err, fmt.Sprintf("unable to resolve value for key: %s", value)) | ||
} | ||
v.Set(reflect.ValueOf(replacement)) | ||
} | ||
} | ||
} | ||
} // it's not a map, we shouldn't try and process it. | ||
|
||
} | ||
return nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
mixins: | ||
- exec | ||
|
||
name: HELLO | ||
version: 0.1.0 | ||
description: "An example Porter configuration" | ||
invocationImage: jeremyrickard/porter-hello:latest | ||
|
||
parameters: | ||
- name: command | ||
type: string | ||
default: "echo Hello World" | ||
|
||
install: | ||
- description: "Install Hello World" | ||
exec: | ||
command: bash | ||
arguments: | ||
- -c | ||
- source: bundle.parameters.command | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 😇 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
|
||
uninstall: | ||
- description: "Uninstall Hello World" | ||
exec: | ||
command: bash | ||
arguments: | ||
- -c | ||
- echo Goodbye World |
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 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,
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. 😀