From 0abae802a80cdba3d46c96974918ce12710f2f97 Mon Sep 17 00:00:00 2001 From: Johnathan Kupferer Date: Thu, 8 Aug 2024 10:48:14 -0400 Subject: [PATCH 1/6] Update odo instructions --- .gitignore | 1 + Development.adoc | 16 +++++----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 8da04f3..d38171e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.swx *.pyc __pycache__ +.odo .odo/ .odo/env .odo/odo-file-index.json diff --git a/Development.adoc b/Development.adoc index 9323ea5..f45b794 100644 --- a/Development.adoc +++ b/Development.adoc @@ -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: @@ -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: + ---- From 679451e6b6d657a29de6542c04af17122175e122 Mon Sep 17 00:00:00 2001 From: Johnathan Kupferer Date: Thu, 8 Aug 2024 10:49:36 -0400 Subject: [PATCH 2/6] Fix reference to undefined kind variable --- operator/resourcewatcher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator/resourcewatcher.py b/operator/resourcewatcher.py index d5e82f3..d6178d9 100644 --- a/operator/resourcewatcher.py +++ b/operator/resourcewatcher.py @@ -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 = {} From 74faa144617e2d870d21b41dbcfda0b6dab0b517 Mon Sep 17 00:00:00 2001 From: Johnathan Kupferer Date: Thu, 8 Aug 2024 12:09:22 -0400 Subject: [PATCH 3/6] Remove preload and update handle status from manage method --- operator/resourcehandle.py | 1 + operator/resourcewatcher.py | 11 ----------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/operator/resourcehandle.py b/operator/resourcehandle.py index 71c4b26..ab92d76 100644 --- a/operator/resourcehandle.py +++ b/operator/resourcehandle.py @@ -1075,6 +1075,7 @@ async def manage(self, logger: kopf.ObjectLogger) -> None: if status_patch: await self.json_patch_status(status_patch) + await self.update_status(logger=logger) if resource_claim: await resource_claim.update_status_from_handle( logger=logger, diff --git a/operator/resourcewatcher.py b/operator/resourcewatcher.py index d6178d9..b6d27d3 100644 --- a/operator/resourcewatcher.py +++ b/operator/resourcewatcher.py @@ -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): From 5cd3af12a851c012e13f9b95fccf972cd9f2b149 Mon Sep 17 00:00:00 2001 From: Johnathan Kupferer Date: Thu, 8 Aug 2024 12:09:47 -0400 Subject: [PATCH 4/6] Add health and readiness check to status summary test --- .../poolboy_test_simple/tasks/test-status-summary-01.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/roles/poolboy_test_simple/tasks/test-status-summary-01.yaml b/test/roles/poolboy_test_simple/tasks/test-status-summary-01.yaml index 40a1e14..0340920 100644 --- a/test/roles/poolboy_test_simple/tasks/test-status-summary-01.yaml +++ b/test/roles/poolboy_test_simple/tasks/test-status-summary-01.yaml @@ -12,6 +12,8 @@ poolboy_domain ~ "/test": "simple" } }} spec: + healthCheck: >- + spec.stringvalue is defined override: apiVersion: "{{ poolboy_domain }}/v1" kind: ResourceClaimTest @@ -30,6 +32,8 @@ - one - two - three + readinessCheck: + spec.stringvalue in ('one', 'two', 'three') statusSummaryTemplate: stringValue: "{% raw %}{{ resources[0].state.spec.stringvalue }}{% endraw %}" template: @@ -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 From fb8ad466dec4a18c1100861797e85279d7a58651 Mon Sep 17 00:00:00 2001 From: Johnathan Kupferer Date: Thu, 8 Aug 2024 12:54:07 -0400 Subject: [PATCH 5/6] Add logging of failed patches --- operator/resourcehandle.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/operator/resourcehandle.py b/operator/resourcehandle.py index ab92d76..a3ba999 100644 --- a/operator/resourcehandle.py +++ b/operator/resourcehandle.py @@ -1071,11 +1071,23 @@ 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( logger=logger, From 62ecec0eec829bad4e5ad85aaecbefc09d5cf0b4 Mon Sep 17 00:00:00 2001 From: Johnathan Kupferer Date: Thu, 8 Aug 2024 12:54:46 -0400 Subject: [PATCH 6/6] Fix null resource_claim issue --- operator/resourcewatcher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/operator/resourcewatcher.py b/operator/resourcewatcher.py index b6d27d3..98402e6 100644 --- a/operator/resourcewatcher.py +++ b/operator/resourcewatcher.py @@ -264,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: