82 Commits

Author SHA1 Message Date
Felix Matouschek
effb8140b6 chore(formatting): Run make format
Black changed it's mind about whitespace in some files.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2026-01-19 12:08:43 +01:00
kubevirt-bot
9c1ab01ba4 Merge pull request #180 from 0xFelix/running-run-strategy
fix(kubevirt_vm): Allow switching between running and run_strategy
2025-04-29 12:02:27 +02:00
kubevirt-bot
8596655ac6 Merge pull request #178 from 0xFelix/hidden_fields
feat(modules): Add hidden_fields argument
2025-04-29 11:52:25 +02:00
Felix Matouschek
aeb98d241c fix(kubevirt_vm): Allow switching between running and run_strategy
Allow switching between running and run_strategy by always clearing the
other value. E.g. if run_strategy was provided then running set to None
to clear it or vice versa.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2025-04-28 17:21:52 +02:00
Felix Matouschek
4a8b4ead2f feat(inventory): Use OCP projects if available
If no namespaces were specified in the inventory config try to get all
available namespaces by trying to list OCP projects first. If the resource
was not found (no OCP cluster) fall back to regular namespaces.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2025-04-28 15:45:38 +02:00
Felix Matouschek
117694ab1e fix(changed): Fix change detection temporarily
Fix the change detection of kubernetes.core temporarily by monkey
patching the service.diff_objects function. This fix should be removed
once it was merged into kubernetes.core. A dummy _patch_diff_objects
function is introduced to satisfy ansible linters.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2025-04-28 15:06:22 +02:00
Felix Matouschek
a9d7fa22aa feat(modules): Add hidden_fields argument
Add the hidden_fields argument to kubevirt_vm and kubevirt_{vm,vmi}_info
which allows to hide and ignore certain fields in the returned definition
of a VM or VMI. By default this argument is set to ignore changes to the
kubemacpool.io/transaction-timestamp annotation and managed fields, which
may change at any time and cause the modules to return a changed status
although nothing has changed other than their values.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2025-04-28 14:39:42 +02:00
Felix Matouschek
93473cdd47 fix: Ensure compatibility with ansible-core >= 2.19
ansible-core 2.19 changes the way templates are trusted and provides a
new way of patching module args in unit tests.

With this commit the following changes are made to ensure compatibility
with ansible-core >= 2.19:

- Mark inputs to composable as trusted to align with the new template
  trust model.
- Utilize the updated method for patching module arguments in unit tests
  if available.
- Replace direct access to the self._cache attribute with the inventory's
  cache property.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2025-04-23 11:25:51 +02:00
Felix Matouschek
da8e04243b feat(inventory): Add unset_ansible_port option
This adds the unset_ansible_port option to the inventory, which allows to
control if the value of ansible_port should be unset if no non-default
value was found.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2025-04-08 16:38:50 +02:00
Felix Matouschek
17ddb44b8a feat(inventory): Lookup winrm services for Windows hosts
This feature adds looking up winrm services and tries to populate the
ansible_host and ansible_port variables with the values from a
found service for the host. It looks up both winrm HTTP and HTTPS
services and prefers HTTPS if it found both for a given host.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2025-04-03 15:24:34 +02:00
Felix Matouschek
e98d9a48bd feat: Add kubevirt_vmi_info module
Add the kubevirt_vmi_info module which allows to fetch information about
VirtualMachineInstance(s).

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-08-19 08:22:24 +02:00
Felix Matouschek
cd270e271b cleanup(info): Extract execute_module
Extract the execute_module function from the kubevirt_vm_info module to
make it available for other modules.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-08-19 08:22:02 +02:00
Felix Matouschek
c1f651d972 feat(kubevirt_vm): Add support for RunStrategy
This change adds support for setting the RunStrategy of a VM.

Depending on the value set the wait condition for the VM is adjusted.
For the values Always, RerunOnFailure or Once the wait condition will
wait for the VM to run and be ready. For the value Halted the wait
condition will wait for the VM to not exist. For the value Manual
the wait condition is not set.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-16 10:20:09 +02:00
Felix Matouschek
7495c34766 cleanup,doc(inventory): Add missing docstring
Add missing docstring for the _connections_compatibility method.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-12 11:09:23 +02:00
Felix Matouschek
9029574f7c cleanup(inventory): Mark methods as private
Mark all methods of the inventory which should be private with a underscore
prefix in their name.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-12 11:09:23 +02:00
Felix Matouschek
060ac97b68 fix(inventory): Fix inventory source caching
Fix inventory source caching by separating the fetching of objects and
populating the inventory. This way objects can be fetched from the K8S
API or from a configured cached and the cache related parameters on the
plugin now actually work.

The inventory source cache was tested with the ansible.builtin.jsonfile
cache plugin and 100k hosts (~2G JSON file). Though it took a noticeable
amount of time for the inventory plugin to run it worked fine and no
failures could be observed.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-12 10:32:24 +02:00
Felix Matouschek
a228fe2c26 cleanup(inventory): Rename default hostname method
Rename method get_default_host_name to get_default_hostname.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-11 15:28:32 +02:00
Felix Matouschek
c4570b2089 cleanup(inventory): Use dicts where possible
Use dicts instead of ResourceFields where possible to allow
easier serialization/deserialization of objects fetched from the K8S
API.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-11 12:07:09 +02:00
Felix Matouschek
033f373c94 fix(inventory): Align versions for connections compatibility
Align the version in which backwards compatibility for the connections
parameter will be removed.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-11 12:07:09 +02:00
Felix Matouschek
fd9c30103d cleanup(inventory): Drop support for multiple connections
The support for connections to multiple clusters in the inventory
plugin is dropped to better align with user expectations and how other
inventories work. If inventories of multiple clusters are needed the
inventory can be run multiple times with different configurations.
This also helps to clean up the code and make it simpler.

For now this adds a compatibility helper so that configurations with a
single connection entry remain supported and a warning is emitted.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-10 15:32:40 +02:00
Felix Matouschek
2e9d6cec15 cleanup(kubevirt_auth_options): Remove incorrect statement
Remove incorrect statement about a feature being added in a certain
version.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-10 15:32:40 +02:00
Felix Matouschek
463142c280 chore: Prepare release 1.5.0
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-10 14:21:34 +02:00
Felix Matouschek
ff6a067c84 feat(inventory): Deprecate connections parameter
Deprecate the connections parameter of the inventory plugin. For now
this adds only a warning message while keeping the functionality.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-10 13:45:11 +02:00
kubevirt-bot
f6a43206a6 Merge pull request #114 from 0xFelix/vm-vmi-2
feat,test(inventory): Support listing stopped VMs and major rework of unit tests
2024-07-03 16:24:57 +02:00
Felix Matouschek
a94eda613f feat(inventory): Support stopped VMs
This enables the inventory to list stopped VMs by refactoring
the add_from_namespace method. The method is now looking up the related
VM and VMIs for a host and adds all status attributes of both objects
to the host's vars. To distinguish the origin of vars an appropriate
prefix (vm_ or vmi_) is applied to their name. The inventory now supports
hosts comprising just a VM (stopped), just a VMI or both.

This changes some of the hostvars previously reported by the inventory
plugin:

Dropped:
- object_type
- cluster_name

Now prefixed with vm_ or vmi_ according to the origin:
- labels
- annotations
- resource_version
- uid

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-03 16:04:47 +02:00
Felix Matouschek
c096f069e3 cleanup(kubevirt_vm): Drop dependency on Jinja2
Drop the dependency on Jinja2 in the kubevirt_vm module by using dicts
to construct a VM instead of rendering jinja templates internally.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-03 14:40:50 +02:00
Felix Matouschek
8ae9a395e9 cleanup(inventory): Consolidate fetching resources with K8SClient
This consolidates fetching of resources with K8SClient by introducing
the get_resources method, which is can be called by getters for certain
kinds of objects.

The former get_vmis_for_namespace method, which contains the main logic
of the inventory is renamed to populate_inventory_from_namespace.

This refactors the following getters:

- get_available_namespaces
- get_ssh_services_for_namespace

This introduces the following getters:

- get_vms_for_namespace (to be used in the following commit)
- get_vmis_for_namespace

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:56:04 +02:00
Felix Matouschek
01a0e535e2 cleanup(inventory): Move set_composable_vars to bottom of file
This suits the control flow a bit better and helps refactoring the
inventory plugin.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:56:04 +02:00
Felix Matouschek
63a03d75b2 cleanup(inventory): Rename GetVmiOptions to InventoryOptions
... and ensure base_domain is always initialized with the cluster
domain. This is done in preparation for a major refactoring of the
inventory plugin.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:56:04 +02:00
Felix Matouschek
241ca75b28 cleanup(inventory): Make methods more robust
Make the logic in the following methods more robust and add type hints
where appropriate.

- get_host_from_service
- get_port_from_service
- is_windows
- setup
- fetch_objects
- set_ansible_host_and_port
- set_composable_vars

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:55:50 +02:00
Felix Matouschek
83bcffedd7 cleanup(inventory): Drop unneeded connection_plugin and transport
These two variables seem to be unused and removing them did not have any
effect.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:54:43 +02:00
Felix Matouschek
4b70e0471f cleanup(inventory): Apply pylint suggestions
Make pylint happy by applying some simple suggestions.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:54:43 +02:00
Felix Matouschek
5d31db3ea2 chore: Change license Apache 2.0
Change the license of the collection to Apache 2.0 to be compliant with
the CNCF licensing requirements.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-11 11:39:32 +02:00
Felix Matouschek
df629ac39e chore: Drop vendored document fragments
Drop the vendored document fragments from kubernetes.core to slightly
enhance the documented options and to allow changing the license of the
collection.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-11 11:39:21 +02:00
Felix Matouschek
a9c6296794 fix: Ensure compatibility with kubernetes.core >=3.10,<4.1.0
Ensure compatibility with kubernetes.core >=3.10,<4.1.0 by replacing
deprecated imports of HAS_K8S_MODULE_HELPER and k8s_import_exception.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-05-29 10:11:05 +02:00
kubevirt-bot
131aacec43 Merge pull request #95 from 0xFelix/improved-docs
Provide links for docsite and improve docs by adding markup
2024-05-17 11:26:25 +02:00
Javier Cano Cano
a1b0971b7f fix(kubevirt): fix inventory labels loop
Fix the for loop ranging over vmi labels. This loop is missing the
.items() statement, which it causes the following error:

```
for key, value in vmi.metadata.labels:
ValueError: too many values to unpack (expected 2)
```

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-05-15 16:23:45 +02:00
Javier Cano Cano
48b2a81679 fix(kubevirt): comment typo
Fix a small comment typo showing `LoadBalancer` instead of `NodePort`.

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-05-15 16:12:19 +02:00
Felix Matouschek
4851e5d20d docs: Improve docs by adding markup
Improve the generated documentations by adding Ansible documentation markup
where appropriate.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-05-08 11:06:57 +02:00
kubevirt-bot
13ceaf0f2d Merge pull request #91 from 0xFelix/wait-condition-info
feat(kubevirt_vm_info): Set wait_condition based on running
2024-04-25 14:06:24 +02:00
Felix Matouschek
71a88007fe feat(kubevirt_vm_info): Set wait_condition based on running
Add the running parameter to kubevirt_vm_info from which the
wait_condition is derived from when parameter wait is set to
yes.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-24 18:48:39 +02:00
Felix Matouschek
03fcea0072 Merge pull request #90 from 0xFelix/docs-connections
docs: Use proper type for connections parameter

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-24 16:32:57 +02:00
Felix Matouschek
86cee0172f fix(kubevirt_vm): Set wait_condition based on running
To properly wait for a state change in the kubevirt_vm module the
wait_condition needs to adapted to the state of running.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-24 14:53:41 +02:00
Felix Matouschek
b232464dbe docs: Use proper type for connections parameter
The connections parameter is of type list of dicts.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-24 13:47:55 +02:00
Felix Matouschek
e5edf072cc cleanup: Cleanup YAML passed to k8s module
Cleanup the YAML passed to the k8s module so it conforms to yaml output
you would expect from yaml.dump. Also refactor the tests to get rid of
duplicate definitions and make use of pytest.mark.parametrize and
yaml.dump.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-24 12:16:10 +02:00
Felix Matouschek
a3abcbedd4 feat: Set ansible_connection to winrm for Windows hosts
This changes the inventory plugin so that it sets the ansible_connection
to winrm if it detected a Windows host. If it did not detect a Windows
host the ansible_connection is no longer set, so Ansible falls back to
its default value of ssh. The detection of SSH services for hosts using
winrm is disabled.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-16 16:38:54 +02:00
Felix Matouschek
7c5de4adf9 cleanup: Run make format
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-16 16:38:54 +02:00
kubevirt-bot
b392d8077d Merge pull request #77 from l3acon/add-composite-vars
fix: add composite vars to inventory
2024-04-09 17:23:56 +02:00
matt
c058de50cd fix: add composite vars to inventory
Docs seem to indicate compose variables should work, but they aren't actually set.
Fix that by adding the composite variables to the inventory.

Signed-off-by: matt <l3acon@gmail.com>
2024-04-09 08:53:51 -06:00
Felix Matouschek
7dc7312a8b feat: Give secondary interfaces a higher priority over services
To give secondary interfaces a higher priority over services the use of
services is disabled if a network_name was provided.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-05 14:35:44 +02:00