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

Support complex types as parameter set values #3340

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

erikced
Copy link

@erikced erikced commented Feb 21, 2025

What does this change

This change updates the parameter sets to support number, object, array and boolean values for value sources, e.g.

schemaType: ParameterSet
schemaVersion: 1.1.0
name:  my-params
parameters:
  - name: some-param
    source:
      value: 
        a: [1, 2, 3, 4]
        b: abcd
  - name: some-other-param
      source:
        value: true

so that the parameter set value can be of the same type as the bundle parameter.

Currently this is only supporter by manually converting the values to their JSON representation, which is less intuitive

  - name: some-param
    source: 
      value: '{"a": [1, 2, 3, 4], "b": "abcd"}'
  - name: some-other-param
      source:
        value: "true"

It is implemented by updating the unmarsalling code for Source so that when parameter with the value strategy is encountered and the hint is not a string, it is converted to its corresponding JSON string representation.

What issue does it fix

Closes #3331

Notes for the reviewer

Since the unmarshalling - and hence value transformation - is performed before the parameter set is stored in the parameter store the value stored will not necessarily match the input parameter set when running porter parameters apply, which might not be desirable(?). Even though porter will not itself write values that are not strings to the parameter store, it can read such values from the store as the BSON is converted to JSON and then unmarshalled in the same way as parameter sets from file.

Checklist

  • Did you write tests?
  • Did you write documentation?
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
  • If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️

- Add support for numbers, objects, arrays and booleans in parameter set
  `value` sources.
- Convert complex values to JSON string representation during parameter
  set unmarshalling.

Signed-off-by: Erik Cederberg <[email protected]>
if err != nil {
return err
}
s.Hint = value
} else {
s.Hint = fmt.Sprintf("%v", s.Hint)
Copy link
Author

@erikced erikced Feb 21, 2025

Choose a reason for hiding this comment

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

I am a bit confused by this, as the hint should be an empty string at this point? I left it in nonetheless.

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.

Parameter sets value only supports string type
1 participant