k8s/oc plugins: fix 'ResourceField' is not JSON serializable (#46145)
Fixes #44408
(cherry picked from commit 15d46ce428
)
This commit is contained in:
parent
6ba1330191
commit
aa1b00f7e9
1 changed files with 12 additions and 9 deletions
|
@ -114,17 +114,18 @@ class K8sInventoryHelper(K8sAnsibleMixin):
|
||||||
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
|
||||||
|
@ -184,8 +185,8 @@ class K8sInventoryHelper(K8sAnsibleMixin):
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
@ -234,7 +235,7 @@ class K8sInventoryHelper(K8sAnsibleMixin):
|
||||||
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,
|
||||||
|
@ -283,8 +284,7 @@ class OpenShiftInventoryHelper(K8sInventoryHelper):
|
||||||
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)
|
||||||
|
|
||||||
|
@ -294,6 +294,9 @@ class OpenShiftInventoryHelper(K8sInventoryHelper):
|
||||||
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)
|
||||||
|
|
||||||
|
@ -313,4 +316,4 @@ class OpenShiftInventoryHelper(K8sInventoryHelper):
|
||||||
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))
|
||||||
|
|
Loading…
Reference in a new issue