-
Notifications
You must be signed in to change notification settings - Fork 104
Refactor inventory plugin #217
Refactor inventory plugin #217
Conversation
Codecov Report
@@ Coverage Diff @@
## main #217 +/- ##
=======================================
Coverage 23.17% 23.17%
=======================================
Files 1 1
Lines 151 151
Branches 24 24
=======================================
Hits 35 35
Misses 111 111
Partials 5 5 Continue to review full report at Codecov.
|
plugins/inventory/k8s.py
Outdated
| return host.replace('https://', '').replace('http://', '').replace('.', '-').replace(':', '_') | ||
|
|
||
| @staticmethod | ||
| def sanitize(name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a function called _sanitize_group_name. Can we use this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, yeah we can definitely use that
|
I like:
And I have never used those features (and have only tested the inventory plugin once anyways), but if we merge those changes, we will need to bump to a 2.0.0 version. We could merge the rest of the changes in 1.x, I think—and then maybe you can move those other two changes to a PR that we could put in a 2.0.0 milestone? |
636c4f2 to
e15ac6d
Compare
|
@fabianvf I agree about the group renaming and have to wonder if many at all where using the parts you touched. A breaking change is a breaking change that I'm going to attach this one to the 2.0 project. |
plugins/inventory/k8s.py
Outdated
| resource = client.resources.get(api_version=item['api_version'], kind=item['kind']) | ||
| instances = resource.get(namespace=namespace) | ||
| except Exception: | ||
| # TODO Could be expected due to RBAC or odd cluster, maybe should log a warning or something? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geerlingguy do you know what the typical warning approach for inventory plugins is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That I do not; you'd have to get @Akasurde's input, I have never built an inventory plugin (yet—I'm going to work on getting one merged for DigitalOcean soon).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use strict parameter and depend upon strictness (strict: true) we take action.
like -
if strict:
raise AnsibleError("Could not...
else:
display.warning("Could not...
You can find the example https://github.com/ansible-collections/vmware/blob/341c3375941d3119a61c10359c85a4caa8082e18/plugins/inventory/vmware_vm_inventory.py#L446 and https://github.com/ansible-collections/vmware/blob/341c3375941d3119a61c10359c85a4caa8082e18/plugins/inventory/vmware_vm_inventory.py#L807
plugins/inventory/k8s.py
Outdated
| description: | ||
| - Fetch containers and services for one or more clusters | ||
| - Fetch containers in pods for one or more clusters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a change in functionality or is this a correction to the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a change in functionality; this PR would limit the scope of the inventory plugin to something that's more practical in real-world use, but because it changes the behavior and removes a feature, that should probably be put into a 2.x.
f81f418 to
fff40ef
Compare
|
recheck |
c3c056e to
0accff9
Compare
- No longer adds services to lists of hosts - Group names are now sanitized - Removed the `*_pods` groups, as pods are the only valid hosts anyway - Add new groups for Deployments, Daemonsets and StatefulSets, allowing easy access to pods that are created by those resources
d89948c to
9f51454
Compare
9f51454 to
efa80d3
Compare
efa80d3 to
bafc601
Compare
| result['method'] = 'create' | ||
| return result | ||
|
|
||
| def extract_selectors(self, instance): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method don't use self, can we convert it in a function and add test-coverage?
goneri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but I still need to test the code.
|
I don't feel we have enough feedback on the validity or necessity of this plugin. I'd like to see us hold up on this until we get that for or against it's continued inclusion. |
|
This repository does not accept pull requests, see the README for details. |
SUMMARY
Inventory plugin only adds valid hosts and groups
*_podsgroups, as pods are the only valid hosts anywayeasy access to pods that are created by those resources
ISSUE TYPE
COMPONENT NAME
plugins/inventory/k8s.py
ADDITIONAL INFORMATION
Technically modifying the group names to be valid could be considered a breaking change, though it's probably a bug that they weren't in the first place.