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(inventory): introduce OmegaConf as optional inventory backend #995

Closed
wants to merge 42 commits into from

Conversation

MatteoVoges
Copy link
Contributor

@MatteoVoges MatteoVoges commented Apr 27, 2023

Fixes #990

Proposed Changes

  • introduces OmegaConf as new backend
  • working branches are kapicorp/nexenio-dev, neXenio/dev
  • see docs for all features and changes: docs/pages/inventory/omegaconf.md

To do

  • Documentation
  • Tests
  • useful logging for debugging
  • useful error handling with hints how to fix
  • Feature TODO:
    • OmegaConf can detect duplicate keys that are redundantly defined
    • make migrate as command, not flag
    • migrate should detect resolvers and don't migrate them
    • migrate should convert keys with . to using the access resolver
    • user_resolver_path should be controlled by a flag
    • support global_inventory in multiprocessing
    • performance: hash and cache classes / targets and store them

Contributed by

@MatteoVoges MatteoVoges added feature documentation Anything related to documentation testing_needed needs some more testing to triage, or for issue solution dependencies Pull requests that update a dependency file labels Apr 27, 2023
@MatteoVoges MatteoVoges self-assigned this Apr 27, 2023
@ramaro
Copy link
Member

ramaro commented Apr 27, 2023

@MatteoVoges this is very exciting, thanks! Will review in the new couple of days.

@MatteoVoges
Copy link
Contributor Author

Note: the tests are failing because of the changes made in #993
Fix for that exists already in #994

@gburiola
Copy link
Contributor

gburiola commented May 1, 2023

This is very exciting indeed. I haven't heard of OmegaConf before. Great find!!

reclass is great but after you use it for a while you find lots of small things that could be improved and it's a bit sad that it's not longer being maintained. So having an alternative is great.

However, reclass is everywhere in the kapitan code. So my suggestion is to open a separate PR where you just make kapitan code more generic and ready to accept a different type of inventory, without adding OmegaConf just yet. For example the changes you have in this PR to rename inventory_reclass to get_inventory. I think it's simpler to review and ensure it's backward compatible.

I believe there are lots of other places (in addition to inventory_reclass function) that needs to be adjusted.

For example:

  • kapitan searchvar
  • kapitan lint

@MatteoVoges
Copy link
Contributor Author

MatteoVoges commented May 3, 2023

However, reclass is everywhere in the kapitan code. So my suggestion is to open a separate PR where you just make kapitan code more generic and ready to accept a different type of inventory, without adding OmegaConf just yet. For example the changes you have in this PR to rename inventory_reclass to get_inventory. I think it's simpler to review and ensure it's backward compatible.

Yeah, I will do that. But I leave the changes in here as well, to see the full view of the change.
I don't know how we want to support several inventories. With this pr, we can toggle between OmegaConf and reclass by setting the flag --omegaconf or not. If we have several options, should each backend get their own toggle flag? Or maybe a specification flag would make sense, like --inv=MyInv or --inv=OmegaConf.

@MatteoVoges MatteoVoges marked this pull request as draft May 19, 2023 15:41
@MatteoVoges
Copy link
Contributor Author

There is some error in the OmegaConf.merge() function, because it doesn't support merging of list objects. This is fixed in omry/omegaconf#1082 , but we have to wait until the next release, to use the feature

@MatteoVoges
Copy link
Contributor Author

Since the list merge in Omegaconf now works, I included the module locally and was able to test it successfully. Migrating the inventory only works with ruamel.yaml at the moment, as this is the only way to preserve comments. Also the local module has to be replaced by the PyPi module again, if it is released.

If you compile the inventory this is the only change: (examples/kubernetes/compiled/minikube-nginx-helm/nginx-deploy.sh)

- KUBECTL="kubectl -n None" #(2)!
+ KUBECTL="kubectl -n minikube-nginx-helm" #(2)!

So the namespace is now correct. I think that this change was even a bug in reclass and so this is fixed now. But maybe it could be intentional...

@MatteoVoges MatteoVoges marked this pull request as ready for review July 5, 2023 16:48
@MatteoVoges
Copy link
Contributor Author

@ademariag @ramaro
Most of the development is finished and ready to merge now. However there are tests and documentation missing. I will add them, if we agree on a final first-version of omegaconf, because then I don't have to rewrite everything 😄
I would present you the current state of the inventory in the next work group meeting with some examples.
What do you think about this?

@@ -51,6 +51,7 @@ jsonschema = "^4.17.3"
kadet = "^0.2.2"
python-gnupg = "^0.4.7"
pyyaml = "^6.0"
omegaconf = { git = "https://github.com/neXenio/omegaconf.git", branch = "dev" }
Copy link
Member

Choose a reason for hiding this comment

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

why do we have to use dev branch?

args = list(cached.args.values())[0]
use_omegaconf = args.omegaconf
try:
migrate_omegaconf = args.migrate
Copy link
Member

Choose a reason for hiding this comment

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

not really use why we need to do this inside a try?

Copy link
Contributor

Choose a reason for hiding this comment

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

use perhaps:

migrate_omegaconf = args.get("migrate", False)

Comment on lines +338 to +349
# inv_start = time.time()
inv = inventory_omegaconf(inventory_path, ignore_class_notfound, targets)
# logger.info("REAL_TIME (%.2fs)", time.time() - inv_start)
except Exception as e:
if not migrate_omegaconf:
logger.warning("Make sure to migrate your inventory using --migrate")
raise InventoryError(e)
else:
logger.debug("Using reclass as inventory backend")
# inv_start = time.time()
inv = inventory_reclass(inventory_path, ignore_class_notfound)
# logger.info("REAL_TIME (%.2fs)", time.time() - inv_start)
Copy link
Member

Choose a reason for hiding this comment

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

can we remove the commented code?

@@ -0,0 +1,163 @@
#!/usr/bin/env python3

# Copyright 2023 nexenio
Copy link
Member

Choose a reason for hiding this comment

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

unfortunately we need to remove this. We need this instead:


# Copyright 2023 The Kapitan Authors
# SPDX-FileCopyrightText: 2020 The Kapitan Authors <kapitan-admins@googlegroups.com>
#
# SPDX-License-Identifier: Apache-2.0

@@ -0,0 +1,198 @@
#!/usr/bin/env python3

# Copyright 2023 nexenio
Copy link
Member

Choose a reason for hiding this comment

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

same copyright msg here too


pull_oc:
rm -rf omegaconf
git clone --branch 1080-add-list-deep-merging https://github.com/nexenio/omegaconf.git oc
Copy link
Contributor

Choose a reason for hiding this comment

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

@MatteoVoges this is not needed anymore now that it has been merged right?

Copy link
Contributor Author

@MatteoVoges MatteoVoges left a comment

Choose a reason for hiding this comment

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

Hey @ramaro and @ademariag ,
This is an outdated version of the implementation. I'm now working on a nexenio/dev branch to work more independently, because some of my PR's depend on each other and we at nexenio wanted to have a kapitan branch with all of my (upcoming) features.
Of course I will continue sending parts to this upstream, but I think this will happen less frequently.

I can show you my progress on friday and then you can review it properly.

@MatteoVoges MatteoVoges marked this pull request as draft September 1, 2023 15:15
@MatteoVoges MatteoVoges deleted the pluggable-inventory branch October 30, 2023 17:07
@MatteoVoges MatteoVoges restored the pluggable-inventory branch January 17, 2024 08:45
@MatteoVoges MatteoVoges reopened this Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file documentation Anything related to documentation feature testing_needed needs some more testing to triage, or for issue solution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide an alternative backend for the inventory
4 participants