Defensively get node's provider ID
@@ -57,8 +57,7 @@ def sum_resources(self, *resource_dicts):
class KubernetesDeployment:
- def __init__(self, id, name, namespace, created_at,
- replicas, selector, extra=None):
+ def __init__(self, id, name, namespace, created_at, replicas, selector, extra=None):
self.id = id
self.name = name
self.namespace = namespace
@@ -68,8 +67,11 @@ class KubernetesDeployment:
self.extra = extra or {}
def __repr__(self):
- return ('<KubernetesDeployment name=%s namespace=%s replicas=%s>' %
- (self.name, self.namespace, self.replicas))
+ return "<KubernetesDeployment name=%s namespace=%s replicas=%s>" % (
+ self.name,
+ self.namespace,
+ self.replicas,
+ )
class KubernetesPod(object):
@@ -346,34 +348,36 @@ class KubernetesContainerDriver(KubernetesDriverMixin, ContainerDriver):
def ex_list_deployments(self):
items = self.connection.request(
- "/apis/apps/v1/deployments",
- enforce_unicode_response=True).object['items']
+ "/apis/apps/v1/deployments", enforce_unicode_response=True
+ ).object["items"]
return [self._to_deployment(item) for item in items]
def _to_deployment(self, data):
- id_ = data['metadata']['uid']
- name = data['metadata']['name']
- namespace = data['metadata']['namespace']
- created_at = data['metadata']['creationTimestamp']
- replicas = data['spec']['replicas']
- selector = data['spec']['selector']
+ id_ = data["metadata"]["uid"]
+ name = data["metadata"]["name"]
+ namespace = data["metadata"]["namespace"]
+ created_at = data["metadata"]["creationTimestamp"]
+ replicas = data["spec"]["replicas"]
+ selector = data["spec"]["selector"]
extra = {
- 'labels': data['metadata']['labels'],
- 'strategy': data['spec']['strategy']['type'],
- 'total_replicas': data['status']['replicas'],
- 'updated_replicas': data['status']['updatedReplicas'],
- 'ready_replicas': data['status']['readyReplicas'],
- 'available_replicas': data['status']['availableReplicas'],
- 'conditions': data['status']['conditions'],
+ "labels": data["metadata"]["labels"],
+ "strategy": data["spec"]["strategy"]["type"],
+ "total_replicas": data["status"]["replicas"],
+ "updated_replicas": data["status"]["updatedReplicas"],
+ "ready_replicas": data["status"]["readyReplicas"],
+ "available_replicas": data["status"]["availableReplicas"],
+ "conditions": data["status"]["conditions"],
}
- return KubernetesDeployment(id=id_,
+ return KubernetesDeployment(
+ id=id_,
name=name,
namespace=namespace,
created_at=created_at,
replicas=replicas,
selector=selector,
- extra=extra)
+ extra=extra,
+ )
def _to_node(self, data):
"""
@@ -404,7 +408,7 @@ class KubernetesContainerDriver(KubernetesDriverMixin, ContainerDriver):
extra = {"memory": memory, "cpu": cpu}
extra["os"] = data["status"]["nodeInfo"].get("operatingSystem")
extra["kubeletVersion"] = data["status"]["nodeInfo"]["kubeletVersion"]
- extra["provider_id"] = data["spec"]["providerID"]
+ extra["provider_id"] = data.get("spec", {}).get("providerID")
for condition in data["status"]["conditions"]:
if condition["type"] == "Ready" and condition["status"] == "True":
state = NodeState.RUNNING
