diff --git a/.gitignore b/.gitignore index 26e63b2..8486607 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ __pycache__ *.pyo build/ dist/ +ENV/ +.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 31d4b3b..8694703 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): @@ -41,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): @@ -50,8 +55,13 @@ 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"] = \ + "true" if self.include_uninitialized else "false" + return "{}{}".format( + self.api_obj_class.endpoint, + "?{}".format(urlencode(params)) if params else "", + ) class Query(BaseQuery):