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

Allow Breaking Configuration Inheritance #326 #339

Merged
merged 23 commits into from
Apr 21, 2022

Conversation

ep-linden
Copy link
Contributor

With the hierarchical inheritance structure in GitLabForm V2, users cannot break the inheritance. To see a better example of this use case please see Issue #326.

To break inheritance, the merge_configs needs to know what to not include. The two recursive functions will search and replace the sections where inheritance is broken.
The merge_configs function was previously not checking if the break-inheritance flag is set at the proper level. The validation function validates if the break-inheritance flag is set at the top-level setting of the provided configuration. The validation function will quit the program if users set the break-inheritance flag improperly. To identify the setting levels more_general_config and more_specific_config refer to,  pass keyworded arguments to merge_configs.
@ep-linden ep-linden marked this pull request as draft February 23, 2022 19:16
@ep-linden
Copy link
Contributor Author

ep-linden commented Feb 23, 2022

@gdubicki @amimas @jccl

@codecov
Copy link

codecov bot commented Feb 24, 2022

Codecov Report

Merging #339 (f0895b6) into main (edd6258) will decrease coverage by 1.02%.
The diff coverage is 87.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #339      +/-   ##
==========================================
- Coverage   80.83%   79.81%   -1.03%     
==========================================
  Files          63       63              
  Lines        2385     2432      +47     
==========================================
+ Hits         1928     1941      +13     
- Misses        457      491      +34     
Impacted Files Coverage Δ
gitlabform/__init__.py 100.00% <ø> (ø)
gitlabform/configuration/groups.py 96.00% <75.00%> (-4.00%) ⬇️
gitlabform/configuration/core.py 71.66% <87.09%> (+5.00%) ⬆️
gitlabform/configuration/projects_and_groups.py 100.00% <100.00%> (ø)
gitlabform/core.py 62.33% <100.00%> (ø)
gitlabform/processors/util/branch_protector.py 64.84% <0.00%> (-10.16%) ⬇️
gitlabform/processors/single_entity_processor.py 83.87% <0.00%> (-9.68%) ⬇️
gitlabform/gitlab/projects.py 50.00% <0.00%> (-5.15%) ⬇️
gitlabform/gitlab/branches.py 83.82% <0.00%> (-2.95%) ⬇️
gitlabform/gitlab/core.py 90.76% <0.00%> (-1.54%) ⬇️
... and 1 more

@ep-linden
Copy link
Contributor Author

ep-linden commented Feb 25, 2022

@gdubicki Please let us know if you have another implementation in mind.

Since the validation function is seperated out, the call to the validation can be done in the wrapper classes, which reduces the complexity of the merge configs function.
The functionality of the merge configs function was out of scope, which made calling the function unclear and the implementation details unclear. By separating the validation function out, it clarified each functions purpose and scope.
@ep-linden
Copy link
Contributor Author

I did 10 dry runs each: with my changes and without my changes. The times are not that different. It was 4.85 seconds with my changes and 4.80 seconds without my changes.

If you have any thoughts or ideas regarding the implementation that would be great.

@gdubicki

Copy link
Member

@gdubicki gdubicki left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, @ep-linden! Sorry if the review is premature as the PR is still in Draft. I wanted to give you some feedback though.

The great thing is that your tests show that it works! 🥳

The slightly worse is that I only scraped over the surface and have pretty trivial comments for you now. Unfortunately I don't understand your core code (yet) so I don't have comments about the logic. :(

Do you plan to change it?

gitlabform/configuration/projects_and_groups.py Outdated Show resolved Hide resolved
gitlabform/configuration/core.py Outdated Show resolved Hide resolved
gitlabform/configuration/core.py Outdated Show resolved Hide resolved
gitlabform/configuration/core.py Show resolved Hide resolved
gitlabform/configuration/core.py Outdated Show resolved Hide resolved
gitlabform/configuration/core.py Outdated Show resolved Hide resolved
@ep-linden
Copy link
Contributor Author

@gdubicki I think the logic will more or less be the same. I will provide a high-level overview of my logic to hopefully help you easily understand the code.

The validate_break_inheritance_flag function checks if the inheritance-break-flag is not set at the incorrect level (topmost level). If the flag exists, then the parent config can't be empty nor can it exist in the common level.

The merge_configs function creates a merged config like it was done before. Then the break_inheritancce helper function checks if the flag is set. If the flag is set then it calls the replace_config_sections function to replace the merged section with the specific config, so this is where I'm doing the overriding.

Hopefully, this made it clearer.

@gdubicki
Copy link
Member

If you want to discuss this more synchronously over chat @ep-linden @amimas @jccl, then please use https://join.slack.com/t/gitlabform/shared_invite/zt-164l3iwxd-hLqZX7v0AU4RsvVajYFtYQ link to join gitlabform's Slack. :)

@gdubicki gdubicki marked this pull request as ready for review April 21, 2022 07:40
@gdubicki gdubicki merged commit 73c9256 into gitlabform:main Apr 21, 2022
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.

None yet

2 participants