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

Add KubeVirt driver & tests #1394

Merged
merged 6 commits into from
Jan 23, 2020
Merged

Add KubeVirt driver & tests #1394

merged 6 commits into from
Jan 23, 2020

Conversation

Eis-D-Z
Copy link
Contributor

@Eis-D-Z Eis-D-Z commented Dec 23, 2019

KubeVirt driver

Description

Kubevirt driver with initial support for the k8s/KubeVirt add-on.

Can list, start, stop, destroy kubevirt type vm's from a kubernetes cluster.

Can create a Persistent Volume Claim with the assumption that the Persistent Volume will be created dynamically by Kubernetes, so a relevant storage class that allows for such provisioning must be declared. (You can list storage classes to view them)

Can create a vm with a docker image with embedded disk as image, and as many persistent volume claims as desired.

  • Network support is limited to 'pod' with 'bridge' or 'masquearde' type interfaces.
  • From the supported disk types of KubeVirt, containerDisk is used for the image, while only persistentVolumeClaims can be added as disks. Disk types can either be "disk" or "lun" and the supported bus are "virtio", "sata" and "scsi".

Status

  • working driver, can be further extended to include more features, needs docstrings
  • Note: Many features of the driver are logically more suited to be in the Kubernetes container driver, please keep this in consideration in the review

Checklist (tick everything that applies)

  • Code linting (required, can be done after the PR checks)
  • Documentation
  • Tests
  • ICLA (required for bigger changes)

@Kami
Copy link
Member

Kami commented Dec 23, 2019

Thanks for the contribution.

Since this is a larger contribution, can you please also work on signing an ICLA (https://libcloud.readthedocs.io/en/latest/development.html#contributing-bigger-changes)?

proxy_url = kwargs.pop('proxy_url', http_proxy_url_env)

self._setup_verify()
self._setup_ca_cert()

LibcloudBaseConnection.__init__(self)

self.session.timeout = kwargs.pop('timeout', 60)
Copy link
Member

Choose a reason for hiding this comment

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

Does this change the default requests timeout behavior?

If so, we should probably only set that attribute if timeout is explicitly specified (for backward compatibility reasons and to make sure it doesn't negatively affect long running and streaming connections)?

Copy link
Member

Choose a reason for hiding this comment

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

EDIT: Never mind, I see you just moved this statement a couple of lines above, please ignore my comment.

@@ -0,0 +1,996 @@
"""
Copy link
Member

Choose a reason for hiding this comment

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

Please add a missing Apache 2.0 license header to the new Python files.


class KubeVirtNode(Node):

def start_node(self):
Copy link
Member

Choose a reason for hiding this comment

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

This was changed recently (#1375) so this custom node class shouldn't be needed anymore.


if ca_cert:
self.connection.connection.ca_cert = ca_cert
else:
Copy link
Member

Choose a reason for hiding this comment

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

Since ca_cert is set to None by default it might not be a bad idea to emit a warning if ca cert is not used that server SSL certificate won't be validated against the CA cert.

And when the documentation is added, it would also be good to point that out there.

self.connection.secret = secret
self.connection.key = key

def list_nodes(self, namespace=None):
Copy link
Member

Choose a reason for hiding this comment

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

namespace argument is unique to this driver and not part of the standard API so please prefix it with ex_.


return vms

def get_node(self, id=None, name=None):
Copy link
Member

Choose a reason for hiding this comment

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

This method is not part of the standard API so please prefix the method name with ex_.

except StopIteration:
raise ValueError("Node does not exist")

def ex_start_node(self, node):
Copy link
Member

Choose a reason for hiding this comment

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

This method name can now be changed to start_node() (see #1375 for details).

except Exception as exc:
raise

def ex_stop_node(self, node):
Copy link
Member

Choose a reason for hiding this comment

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

This method name can now be changed to stop_node() (see #1375 for details).

raise

# only has container disk support atm with no persistency
def create_node(self, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Please explicitly declare all the supported arguments (we just did **kwargs misuse cleanup in #1389).

this name and atm it cannot be changed after it is set.
:type name: ``str``

:param namespace: The namespace where the VM will live.
Copy link
Member

Choose a reason for hiding this comment

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

All the arguments which are not part of the standard API should be prefixed with ex_ (namespace, memory, cpu, disks, network).

:param size: An int of the ammount of gigabytes desired
:type size: `int`

:param namespace: The namespace where the claim will live
Copy link
Member

Choose a reason for hiding this comment

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

Please prefix non standard arguments with ex_ (namespace, storageClassName, accessMode, matchlabels).

except Exception as exc:
raise

def attach_volume(self, volume, ex_node, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure the method signature matches the base API one and that the non standard arguments are prefixed with ex_.

Base signature looks like this:

def attach_volume(self, node, volume, device=None):

So node argument needs to be first, etc.

except Exception as exc:
raise

def detach_volume(self, volume, ex_node):
Copy link
Member

Choose a reason for hiding this comment

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

Same here - base API method only takes volume argument. If node argument is also needed, it should be left as as is (prefixed with ex_ since it's indeed not a standard argument).

except Exception as exc:
raise

def list_persistent_volume_claims(self, namespace="default"):
Copy link
Member

Choose a reason for hiding this comment

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

Please prefix this method with ex_ since is not part of the standard API.

pvcs = [item['metadata']['name'] for item in result['items']]
return pvcs

def list_storage_classes(self):
Copy link
Member

Choose a reason for hiding this comment

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

Please prefix this method with ex_ since is not part of the standard API.

@Kami
Copy link
Member

Kami commented Dec 24, 2019

Thanks for the contribution and nice work 👍

I've added some comments, most of them are related to making sure the driver complies with the "standard" Libcloud compute API (aka making sure non standard arguments and method names are prefixed with ex_).

@Kami
Copy link
Member

Kami commented Jan 14, 2020

@Eis-D-Z LXD driver has been merged, can you please also sync this branch with latest trunk and address the PR comments when you get a chance so this PR can be merged as well.

Thanks.

@Eis-D-Z
Copy link
Contributor Author

Eis-D-Z commented Jan 16, 2020

Hello, Kami.
Thank you for the comments. I have added some more functionality and rectified many of the things you pointed out. In the next days I will push the final version.

@Eis-D-Z
Copy link
Contributor Author

Eis-D-Z commented Jan 23, 2020

Fixed all the commented segments and did a wrong push which I undid subsequently.
Thank you for your patience!

@Kami
Copy link
Member

Kami commented Jan 23, 2020

Thanks for addressing the comments.

There were still some issues I fixed (abf36eb, d1b28ad, 4ad7558).

Next time please make sure the CI / build passes.

@codecov-io
Copy link

Codecov Report

Merging #1394 into trunk will decrease coverage by 0.44%.
The diff coverage is 34.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##            trunk    #1394      +/-   ##
==========================================
- Coverage   86.46%   86.02%   -0.45%     
==========================================
  Files         366      368       +2     
  Lines       76799    77449     +650     
  Branches     7529     7658     +129     
==========================================
+ Hits        66404    66622     +218     
- Misses       7527     7922     +395     
- Partials     2868     2905      +37
Impacted Files Coverage Δ
libcloud/compute/providers.py 87.5% <ø> (ø) ⬆️
libcloud/compute/types.py 98.88% <100%> (ø) ⬆️
libcloud/http.py 91.17% <100%> (ø) ⬆️
libcloud/compute/drivers/kubevirt.py 26.41% <26.41%> (ø)
libcloud/test/compute/test_kubevirt.py 66.66% <66.66%> (ø)
libcloud/container/drivers/kubernetes.py 73.94% <66.66%> (-0.22%) ⬇️
libcloud/common/gandi_live.py 95.23% <0%> (-4.77%) ⬇️
libcloud/test/dns/test_gandi_live.py 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a63b90e...b10ab0e. Read the comment docs.

@Kami Kami merged commit 8e96172 into apache:trunk Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants