1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

k8s/oc plugins: fix 'ResourceField' is not JSON serializable (#46145)

Fixes #44408
This commit is contained in:
Pilou 2018-09-28 00:43:29 +02:00 committed by ansibot
parent 0dedfcd70f
commit 15d46ce428
2 changed files with 12 additions and 9 deletions

View file

@ -223,17 +223,18 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable, K8sAnsibleM
for pod in obj.items: for pod in obj.items:
pod_name = pod.metadata.name pod_name = pod.metadata.name
pod_groups = [] pod_groups = []
pod_labels = {} if not pod.metadata.labels else pod.metadata.labels pod_annotations = {} if not pod.metadata.annotations else dict(pod.metadata.annotations)
pod_annotations = {} if not pod.metadata.annotations else pod.metadata.annotations
if pod.metadata.labels: if pod.metadata.labels:
pod_labels = pod.metadata.labels
# create a group for each label_value # create a group for each label_value
for key, value in pod.metadata.labels: for key, value in pod.metadata.labels:
group_name = 'label_{0}_{1}'.format(key, value) group_name = 'label_{0}_{1}'.format(key, value)
if group_name not in pod_groups: if group_name not in pod_groups:
pod_groups.append(group_name) pod_groups.append(group_name)
self.inventory.add_group(group_name) self.inventory.add_group(group_name)
pod_labels = dict(pod.metadata.labels)
else:
pod_labels = {}
for container in pod.status.containerStatuses: for container in pod.status.containerStatuses:
# add each pod_container to the namespace group, and to each label_value group # add each pod_container to the namespace group, and to each label_value group
@ -294,8 +295,8 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable, K8sAnsibleM
for service in obj.items: for service in obj.items:
service_name = service.metadata.name service_name = service.metadata.name
service_labels = {} if not service.metadata.labels else service.metadata.labels service_labels = {} if not service.metadata.labels else dict(service.metadata.labels)
service_annotations = {} if not service.metadata.annotations else service.metadata.annotations service_annotations = {} if not service.metadata.annotations else dict(service.metadata.annotations)
self.inventory.add_host(service_name) self.inventory.add_host(service_name)
@ -344,7 +345,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable, K8sAnsibleM
self.inventory.set_variable(service_name, 'load_balancer_ip', self.inventory.set_variable(service_name, 'load_balancer_ip',
service.spec.loadBalancerIP) service.spec.loadBalancerIP)
if service.spec.selector: if service.spec.selector:
self.inventory.set_variable(service_name, 'selector', service.spec.selector) self.inventory.set_variable(service_name, 'selector', dict(service.spec.selector))
if hasattr(service.status.loadBalancer, 'ingress') and service.status.loadBalancer.ingress: if hasattr(service.status.loadBalancer, 'ingress') and service.status.loadBalancer.ingress:
load_balancer = [{'hostname': ingress.hostname, load_balancer = [{'hostname': ingress.hostname,

View file

@ -159,8 +159,7 @@ class InventoryModule(K8sInventoryModule):
self.inventory.add_child(namespace_group, namespace_routes_group) self.inventory.add_child(namespace_group, namespace_routes_group)
for route in obj.items: for route in obj.items:
route_name = route.metadata.name route_name = route.metadata.name
route_labels = {} if not route.metadata.labels else route.metadata.labels route_annotations = {} if not route.metadata.annotations else dict(route.metadata.annotations)
route_annotations = {} if not route.metadata.annotations else route.metadata.annotations
self.inventory.add_host(route_name) self.inventory.add_host(route_name)
@ -170,6 +169,9 @@ class InventoryModule(K8sInventoryModule):
group_name = 'label_{0}_{1}'.format(key, value) group_name = 'label_{0}_{1}'.format(key, value)
self.inventory.add_group(group_name) self.inventory.add_group(group_name)
self.inventory.add_child(group_name, route_name) self.inventory.add_child(group_name, route_name)
route_labels = dict(route.metadata.labels)
else:
route_labels = {}
self.inventory.add_child(namespace_routes_group, route_name) self.inventory.add_child(namespace_routes_group, route_name)
@ -189,4 +191,4 @@ class InventoryModule(K8sInventoryModule):
self.inventory.set_variable(route_name, 'path', route.spec.path) self.inventory.set_variable(route_name, 'path', route.spec.path)
if hasattr(route.spec.port, 'targetPort') and route.spec.port.targetPort: if hasattr(route.spec.port, 'targetPort') and route.spec.port.targetPort:
self.inventory.set_variable(route_name, 'port', route.spec.port) self.inventory.set_variable(route_name, 'port', dict(route.spec.port))