From 5347c9984fb23c6471e25bd617a624c883866abf Mon Sep 17 00:00:00 2001 From: Andrew Johnstone Date: Sat, 13 Aug 2016 09:45:23 +0100 Subject: [PATCH 1/2] make ready generic --- CHANGELOG.md | 1 + pykube/objects.py | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a03b6e2..07a4bde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * `HorizontalPodAutoscaler` * `KubeConfig` learned to handle empty or missing user configuration * `HTTPClient` learned to create an HTTP session with no authentication +* ready supported on all objects if exposed by the kubernetes api ### Bug fixes diff --git a/pykube/objects.py b/pykube/objects.py index 5857578..29c8b5f 100644 --- a/pykube/objects.py +++ b/pykube/objects.py @@ -95,6 +95,15 @@ def delete(self): if r.status_code != 404: self.api.raise_for_status(r) + @property + def ready(self): + try: + return ( + self.obj["status"]["observedGeneration"] >= self.obj["metadata"]["generation"] + ) + except KeyError as e: + raise NotImplementedError(e) + class NamespacedAPIObject(APIObject): @@ -128,14 +137,6 @@ class Deployment(NamespacedAPIObject, ReplicatedMixin, ScalableMixin): endpoint = "deployments" kind = "Deployment" - @property - def ready(self): - return ( - self.obj["status"]["observedGeneration"] >= self.obj["metadata"]["generation"] and - self.obj["status"]["updatedReplicas"] == self.replicas - ) - - class Endpoint(NamespacedAPIObject): version = "v1" From 252e7900be3582d5aa308dadb81017b60ffbc061 Mon Sep 17 00:00:00 2001 From: Andrew Johnstone Date: Sat, 13 Aug 2016 09:54:39 +0100 Subject: [PATCH 2/2] correct formatting --- pykube/objects.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pykube/objects.py b/pykube/objects.py index 29c8b5f..79ee159 100644 --- a/pykube/objects.py +++ b/pykube/objects.py @@ -102,7 +102,7 @@ def ready(self): self.obj["status"]["observedGeneration"] >= self.obj["metadata"]["generation"] ) except KeyError as e: - raise NotImplementedError(e) + raise NotImplementedError(e) class NamespacedAPIObject(APIObject): @@ -137,6 +137,7 @@ class Deployment(NamespacedAPIObject, ReplicatedMixin, ScalableMixin): endpoint = "deployments" kind = "Deployment" + class Endpoint(NamespacedAPIObject): version = "v1"