Closed svteb closed 2 months ago
Can the architecture be made more future-proof towards possible future config versions?
Additionally, how about error handling? Like non-supported config keys on input? Maybe other error conditions?
Additionally, how about error handling? Like non-supported config keys on input? Maybe other error conditions?
I believe that this is out of scope of this ticket. These could all be considered validation.
To my knowledge the v1 config does not have a validator that we could reuse to verify the input data, but considering that all the sample/example cnfs are currently (hopefully) deployable I do not find it necessary to verify the input data. Afterall they will all be replaced in step 3 of #2120 epic.
As for the output validation, that also probably does not fall in scope of this ticket as that should be included in #2129 which is the main parser for v2. The current flow of the program for v2 config should be something like this:
./cnf-testsuite cnf_setup config.yml
As for error handling, the current format of "key" => @old_config["key"]?.as_s
assures that if some key is not present its value will be stored as nil (which is inconsequential as the v2 class will also have nil values). Non-supported config keys are not recognized by the transformer because it looks only for the valid keys. In case of nested keys, I first check for existence of their parent. There should not be any conditions under which an error is given.
Input validation: I simply don't find this necessary, do we really want to spend time on validating the v1 config if we intend to replace it in the next couple of weeks and the testsuite worked without it for some time now?
Can the architecture be made more future-proof towards possible future config versions?
- Identify source version of the confing on the input
- Have possibility to tell which config version one needs to transform to (perhaps with hardcoded config version actually used by the testsuite as a constant somewhere)
- Make an easy way for future introduction of config v3.0 and newer, with possibility to transform from 1.0 and 2.0
This is a valid point, I will attempt to generalize the process/add more private functions.
Short summary of what was attempted during implementation and the solution:
I made multiple attempts at creating a generic solution that would allow for future extendibility, these have unfortunately hit some really hard roadblocks. The outline for a generic solution encompassed these properties:
The approaches: Rule sets The advanced approach would allow for rules like these to be defined:
[:container_names, :rolling_version_upgrade] -> [:common_parameters, :container_names, :rolling_version_upgrade]
[:helm_repo_name] -> [:deployments, :helm_charts, :helm_repo_name]
...
These would be easy to write, specifying where some prior key path should lead in the new config. The problems that come with this approach are numerous:
key_repeats = true
. But that would bloat the rules quite a bit and could be hard to understand for future users.A simplified approach is to hard-code what variable should be assigned where, i.e. common_params["white_list_container_names"] = @old_config.white_list_container_names.to_s
. This does not look as pretty but the jump from specific solution to a generic one is too vast.
Transformations
As things stand the third option is the only one that does not impose on other parts of the codebase and is relatively readable/short. While it does not grant an easy way for future users to transform to a new config, the construction of new transformation rule set should not take too long.
@martin-mat @kosstennbl @barmull ready for review.
Re-created from different branch as #2147
Description
The transformer transforms the old config according to the structure proposed in #2129.
Notes
config_v1.cr
../cnf-testsuite transform_config OLD_FILE_PATH NEW_FILE_PATH
ConfigTransformer
class found inconfig_transformer.cr
automatically detects the version of the old config and transforms it to the latest version (currently only v1 -> v2), but allows for future extendibility.transform
function is called which does the actual transformation in code (through use of Hashes and YAML::Any).transform
function uses the appropriate transformation rules (V1ToV2Transformation class
inv1_to_v2_transformation.cr
file)hash_to_yaml_any
andremove_nil_values
have been added (Transformation class
intransformation.cr
file), these convert the underlying hashes and arrays to theYAML::Any
type and remove any nil branches so they don't clutter the final output.serialize_to_string
andserialize_to_file
functions.Issues:
Refs: #2130
How has this been tested:
Types of changes:
Checklist:
Documentation
Code Review
Issue