Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix status summary issues #116

Merged
merged 6 commits into from
Aug 8, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.swx
*.pyc
__pycache__
.odo
.odo/
.odo/env
.odo/odo-file-index.json
16 changes: 5 additions & 11 deletions Development.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ helm template helm \
. Create a project for development using `odo`:
+
------------------------------
odo project create poolboy-dev
oc project create poolboy-dev
------------------------------

. Grant privileges for cluster role `poolboy-dev` to default service account:
Expand All @@ -36,21 +36,15 @@ odo project create poolboy-dev
oc adm policy add-cluster-role-to-user poolboy-dev -z default
-------------------------------------------------------------

. Setup `odo` from the provided `devfile.yaml`:
. Run odo:
+
---------------------------------
odo create --devfile devfile.yaml
---------------------------------
-------
odo dev
-------
+
NOTE: The poolboy operator domain is specified in the devfile.
If you are developing with a different operator domain then you will need to update the `devfile.yaml`.

. Use `odo push` to push code into the odo container:
+
--------
odo push
--------

. Run tests with Ansible:
+
----
Expand Down
17 changes: 15 additions & 2 deletions operator/resourcehandle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,9 +1071,22 @@ async def manage(self, logger: kopf.ObjectLogger) -> None:
resources_to_create.append(resource_definition)

if patch:
await self.json_patch(patch)
try:
await self.json_patch(patch)
except kubernetes_asyncio.client.exceptions.ApiException as exception:
if exception.status == 422:
logger.error(f"Failed to apply {patch}")
raise

if status_patch:
await self.json_patch_status(status_patch)
try:
await self.json_patch_status(status_patch)
except kubernetes_asyncio.client.exceptions.ApiException as exception:
if exception.status == 422:
logger.error(f"Failed to apply {status_patch}")
raise

await self.update_status(logger=logger)

if resource_claim:
await resource_claim.update_status_from_handle(
Expand Down
16 changes: 3 additions & 13 deletions operator/resourcewatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ async def watch(self):
method = Poolboy.custom_objects_api.list_cluster_custom_object
elif self.namespace:
method = getattr(
Poolboy.core_v1_api, "list_namespaced_" + inflection.underscore(kind)
Poolboy.core_v1_api, "list_namespaced_" + inflection.underscore(self.kind)
)
kwargs = dict(namespace=namespace)
else:
method = getattr(
Poolboy.core_v1_api, "list_" + inflection.underscore(kind)
Poolboy.core_v1_api, "list_" + inflection.underscore(self.kind)
)
kwargs = {}

Expand Down Expand Up @@ -180,17 +180,6 @@ async def __watch(self, method, **kwargs):
watch = None
self.cache.clear()
try:
_continue = None
while True:
obj_list = await method(**kwargs, _continue=_continue, limit=50)
for obj in obj_list.get('items', []):
if not isinstance(obj, Mapping):
obj = Poolboy.api_client.sanitize_for_serialization(event_obj)
await self.__watch_event(event_type='PRELOAD', event_obj=obj)
_continue = obj_list['metadata'].get('continue')
if not _continue:
break

watch = kubernetes_asyncio.watch.Watch()
async for event in watch.stream(method, **kwargs):
if not isinstance(event, Mapping):
Expand Down Expand Up @@ -275,6 +264,7 @@ async def __watch_event(self, event_type, event_obj):

await resource_handle.handle_resource_event(logger=logger)

resource_claim = None
try:
resource_claim = await resource_handle.get_resource_claim()
except kubernetes_asyncio.client.exceptions.ApiException as exception:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
poolboy_domain ~ "/test": "simple"
} }}
spec:
healthCheck: >-
spec.stringvalue is defined
override:
apiVersion: "{{ poolboy_domain }}/v1"
kind: ResourceClaimTest
Expand All @@ -30,6 +32,8 @@
- one
- two
- three
readinessCheck:
spec.stringvalue in ('one', 'two', 'three')
statusSummaryTemplate:
stringValue: "{% raw %}{{ resources[0].state.spec.stringvalue }}{% endraw %}"
template:
Expand Down Expand Up @@ -67,7 +71,8 @@
namespace: "{{ poolboy_test_namespace }}"
register: r_get_resource_claim
failed_when: >-
r_get_resource_claim.resources[0].status.resources[0].state is undefined
r_get_resource_claim.resources[0].status.resources[0].state is undefined or
r_get_resource_claim.resources[0].status.summary is undefined
until: r_get_resource_claim is success
delay: 1
retries: 10
Expand Down
Loading