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

feat(parser): support ref-tags with default values #13

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

MatteoVoges
Copy link

@MatteoVoges MatteoVoges commented Mar 22, 2023

Proposed Changes

  • Added support for specifying default values for non existing keys / dictionary-paths
  • Extended functionality to support a reference-tag as default value, e.g. ${spec:value||${default:value||another-default}}
  • Use || as delimiter, because it fits well in the kapitan ecosystem

Examples

parameters:
  existing:
    key: myvalue

  foo: ${non:existing:key||bar} # --> bar (default value)
  mykey: ${existing:key||bar} # --> myvalue (value exists)
parameters:
  defaults:  
    default1: myDefault

  spec:
    spec1: ${not:existing||${defaults:default1}} # --> myDefault (tag in default-value exists)
    spec2: ${not:existing||${defaults:notfound||fallback}} # --> fallback (tag in default-value not exists, default gets taken) 

Breaking changes

  • You should not have the || - delimiter in your yaml-keys anymore!

To Do

  • Add tests
  • Add documentation (also in kapitan docs)
    @ademariag Where should this be done?

Contributed by

Now you can write '${my:tag|default}'. if 'my:tag' could not resolved, the default  value gets taken.

Breaking Changes:
Now you can't have the '|' - pipe symbol in your ref-tags anymore
feat(parser): support ref-tags with default values
this fits better with the kapitan ecosystem and reduces cases where a single pipe would break
@MatteoVoges
Copy link
Author

This is a replacement for #11 , because of bad references on the branch

@ademariag
Copy link

@MatteoVoges for now add it here: https://github.com/kapicorp/reclass/blob/develop/README-extensions.rst

@ademariag ademariag self-requested a review March 23, 2023 10:04
@gburiola
Copy link

  • Very good work. Please also add the 4 cases from your examples above to the tests

@MatteoVoges MatteoVoges requested a review from ademariag March 27, 2023 16:18
@MatteoVoges
Copy link
Author

  • Very good work. Please also add the 4 cases from your examples above to the tests

Thank you, it was quite hard to find the correct spot where the tests need to go, because the nested interpolation logic doesn't happen in the modules where the feature comes to action... But I think its fine to do it in the parameters tests

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.

3 participants