Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

List and watch uninitialized resources #148

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ __pycache__
*.pyo
build/
dist/
ENV/
.idea/
tmp/
Pipfile*
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
16 changes: 13 additions & 3 deletions pykube/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ 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
if selector is not 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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down