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

Merged
merged 6 commits into from
Mar 31, 2025

Conversation

erikced
Copy link
Contributor

@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 supported 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
Contributor 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.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, you're right, it would be empty here. 🤷🏻‍♀️ Not needed, but not harmful (yet) I assume

@kichristensen
Copy link
Contributor

@erikced Thanks for the PR. This is not the part the I'm most familiar with, maybe @schristoff has some more insights. But I have a few questions.
Will the old complex "stringified" parameters still work, when passing them through the commandline? And what will be the expected way to pass complex types from the command line?
It would be great if you also could update the documentation to describe this functionality?
To make me more certain that this works end-to-end I would really like to see a simple integration test or two for covering this change, would that be possible?

erikced added 3 commits March 18, 2025 14:11
Add integration test vaidating parameter value conversions for
command line params, "stringified" params in a parameter set and native
params in a parameter set.

Signed-off-by: Erik Cederberg <[email protected]>
Signed-off-by: Erik Cederberg <[email protected]>
@erikced
Copy link
Contributor Author

erikced commented Mar 18, 2025

Will the old complex "stringified" parameters still work, when passing them through the commandline? And what will be the expected way to pass complex types from the command line?

This MR should not change anything related to command line parameter usage. --param passes everything along as a string and string values do not even reach unmarshalRawValue so neither behavior nor the expected way to pass complex params on the command line has changed.

It would be great if you also could update the documentation to describe this functionality?

Added missing documentation of the updated format.

To make me more certain that this works end-to-end I would really like to see a simple integration test or two for covering this change, would that be possible?

I have added an integration test validating the handling of parameter set / command line parameter to finalized parameter. It is not a full integration test though, please let me know if you think it is sufficient or if a full e2e test is required.

@erikced erikced force-pushed the complex-parameter-values branch from 2c732b3 to eea2a17 Compare March 27, 2025 14:40
@kichristensen
Copy link
Contributor

@erikced Looks good to me. Am I correct when I think the new format will technically also work in version 1.0.1 of the parameter file, but it will fail schema validation if it is validated?

@erikced
Copy link
Contributor Author

erikced commented Mar 28, 2025

@erikced Looks good to me. Am I correct when I think the new format will technically also work in version 1.0.1 of the parameter file, but it will fail schema validation if it is validated?

@kichristensen yes, that should be the case.

As a side note, I am unsure whether the version should be 1.1.0 or 1.0.2, from a semver-like perspective it should probably be 1.1.0 since it is an extension of the functionality and not a patch (whatever that may be for a document) but other document versioning standards would probably treat it as 1.0.2 since all valid 1.0.0/1.0.1 documents are still valid.

@schristoff
Copy link
Member

I like 1.1.0 👍

@schristoff schristoff merged commit 2dad515 into getporter:main Mar 31, 2025
44 of 45 checks passed
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
3 participants