From 4e41e8359d6000ee082e84c930fcba18b9f7be50 Mon Sep 17 00:00:00 2001 From: dvazar Date: Wed, 20 Dec 2017 22:36:00 +0700 Subject: [PATCH 1/2] added: "includeUninitialized" query parameter --- .gitignore | 2 ++ pykube/query.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 26e63b2..86b53eb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ __pycache__ *.pyo build/ dist/ +ENV/ +.idea/ \ No newline at end of file diff --git a/pykube/query.py b/pykube/query.py index 31d4b3b..49c2010 100644 --- a/pykube/query.py +++ b/pykube/query.py @@ -21,11 +21,13 @@ def __init__(self, api, api_obj_class, namespace=None): self.namespace = namespace self.selector = everything self.field_selector = everything + self.include_uninitialized = None def all(self): return self._clone() - def filter(self, namespace=None, selector=None, field_selector=None): + def filter(self, namespace=None, selector=None, field_selector=None, + include_uninitialized=None): clone = self._clone() if namespace is not None: clone.namespace = namespace @@ -33,6 +35,8 @@ def filter(self, namespace=None, selector=None, field_selector=None): clone.selector = selector if field_selector is not None: clone.field_selector = field_selector + if include_uninitialized is not None: + clone.include_uninitialized = include_uninitialized return clone def _clone(self, cls=None): @@ -50,8 +54,12 @@ def _build_api_url(self, params=None): params["labelSelector"] = as_selector(self.selector) if self.field_selector is not everything: params["fieldSelector"] = as_selector(self.field_selector) - query_string = urlencode(params) - return "{}{}".format(self.api_obj_class.endpoint, "?{}".format(query_string) if query_string else "") + if self.include_uninitialized is not None: + params["includeUninitialized"] = self.include_uninitialized + return "{}{}".format( + self.api_obj_class.endpoint, + "?{}".format(urlencode(params)) if params else "", + ) class Query(BaseQuery): From 030c4865f57cd8a2e8858a92054e929c53a640c3 Mon Sep 17 00:00:00 2001 From: dvazar Date: Thu, 21 Dec 2017 15:41:44 +0700 Subject: [PATCH 2/2] added: docs of use --- .gitignore | 4 +++- CHANGELOG.md | 1 + README.rst | 4 ++++ pykube/query.py | 4 +++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 86b53eb..8486607 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ __pycache__ build/ dist/ ENV/ -.idea/ \ No newline at end of file +.idea/ +tmp/ +Pipfile* \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index b1fb79c..867565f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * `Query.watch` learned to carry forward all query parameters * `APIObject` learned `watch` to enable per-object watches * `Deployment` learned to roll back using `rollout_undo` similar to `kubectl rollout undo deployment` +* Added `includeUninitialized` query parameter to include partially initialized resources in the response ## 0.14.0 diff --git a/README.rst b/README.rst index 5d0d95b..d66873c 100644 --- a/README.rst +++ b/README.rst @@ -80,6 +80,10 @@ Selector query: pending_pods = pykube.objects.Pod.objects(api).filter( field_selector={"status.phase": "Pending"} ) + uninitialized_pods = pykube.objects.Pod.objects(api).filter( + selector={"environment": "production", "tier": "frontend"}, + include_uninitialized=True, + ) Watch query: diff --git a/pykube/query.py b/pykube/query.py index 49c2010..8694703 100644 --- a/pykube/query.py +++ b/pykube/query.py @@ -45,6 +45,7 @@ def _clone(self, cls=None): clone = cls(self.api, self.api_obj_class, namespace=self.namespace) clone.selector = self.selector clone.field_selector = self.field_selector + clone.include_uninitialized = self.include_uninitialized return clone def _build_api_url(self, params=None): @@ -55,7 +56,8 @@ def _build_api_url(self, params=None): if self.field_selector is not everything: params["fieldSelector"] = as_selector(self.field_selector) if self.include_uninitialized is not None: - params["includeUninitialized"] = self.include_uninitialized + params["includeUninitialized"] = \ + "true" if self.include_uninitialized else "false" return "{}{}".format( self.api_obj_class.endpoint, "?{}".format(urlencode(params)) if params else "",