apache / libcloud

Apache Libcloud is a Python library which hides differences between different cloud provider APIs and allows you to manage different cloud resources through a unified and easy to use API.
https://libcloud.apache.org
Apache License 2.0
2.03k stars 928 forks source link

Enhance `KubeVirtNodeDriver` Compute Driver #1983

Closed cdfmlr closed 2 weeks ago

cdfmlr commented 6 months ago

Enhance KubeVirtNodeDriver Compute Driver

Description

This pull request brings several improvements to the create_node method and related functions within the KubeVirtNodeDriver (libcloud/compute/drivers/kubevirt.py).

Features added to KubeVirtNodeDriver.create_node:

Fixes:

Other Changes:

Status

Checklist (tick everything that applies)

Kami commented 2 months ago

@cdfmlr Thanks for the contribution and good PR description.

I will have a look as soon as I get a chance. In the mean time, would you mind documenting breaking changes (disks, ports) in docs/upgrades_notes.rst?

cdfmlr commented 2 months ago

would you mind documenting breaking changes (disks, ports) in docs/upgrades_notes.rst?

Sure, I will add it recently.

codecov-commenter commented 2 months ago

Codecov Report

Attention: Patch coverage is 36.79245% with 134 lines in your changes are missing coverage. Please review.

Project coverage is 83.25%. Comparing base (6f1f83d) to head (0b07480).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## trunk #1983 +/- ## ========================================== - Coverage 83.26% 83.25% -0.00% ========================================== Files 353 353 Lines 81305 81445 +140 Branches 8565 8606 +41 ========================================== + Hits 67692 67807 +115 + Misses 10823 10814 -9 - Partials 2790 2824 +34 ``` | [Files](https://app.codecov.io/gh/apache/libcloud/pull/1983?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | |---|---|---| | [libcloud/test/compute/test\_kubevirt.py](https://app.codecov.io/gh/apache/libcloud/pull/1983?src=pr&el=tree&filepath=libcloud%2Ftest%2Fcompute%2Ftest_kubevirt.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bGliY2xvdWQvdGVzdC9jb21wdXRlL3Rlc3Rfa3ViZXZpcnQucHk=) | `71.43% <80.00%> (+4.76%)` | :arrow_up: | | [libcloud/compute/drivers/kubevirt.py](https://app.codecov.io/gh/apache/libcloud/pull/1983?src=pr&el=tree&filepath=libcloud%2Fcompute%2Fdrivers%2Fkubevirt.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bGliY2xvdWQvY29tcHV0ZS9kcml2ZXJzL2t1YmV2aXJ0LnB5) | `32.81% <32.29%> (+9.85%)` | :arrow_up: |
Kami commented 2 months ago

@cdfmlr Thanks.

I had a look again. It mostly looks good, but there are a couple of improvements which can be made:

cdfmlr commented 2 months ago

@Kami Thank you for the review. Indeed, the create_node() looks clumsy. I've actually started refactoring it, but recent higher priority tasks have delayed its completion.

Also, at the moment, I'm unable to add more test cases due to these priority. However, there are some existing test cases for _deep_merge_dict and _memory_in_MB that I believe were copied from our other projects. I plan to incorporate these tests soon.

Despite the problems with code readability and test coverage, we've been using this code in a production environment for several months. It has been performing well and handling a considerable number of situations that aren't covered by the test cases.

Kami commented 3 weeks ago

@cdfmlr Thanks.

Do you happen to have any ETA when you will be to add some more tests + refactor the code a bit? Since I'm planning to do a v3.9.0 release this week.

cdfmlr commented 2 weeks ago

@Kami sorry for my delay.

I have added more tests covering the helper functions (_deep_merge_dict and _memory_in_MB) and some typical unhappy code paths. The _create_node() method has been refactored into smaller functions as well. Meanwhile, a useful new feature to set cpu/mem requests and limits separately is introduced and tested.

Kami commented 2 weeks ago

@cdfmlr Thanks for adding those changes.

I added a couple of more comments. It's mostly a couple of small things, plus the potential security issue with possible YAML injection in case the pub key or password is supplied by the end user and not sanitized before being passed to the Libcloud code.

Kami commented 2 weeks ago

Merged into trunk. Thanks.