Skip to content
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
31 changes: 23 additions & 8 deletions operator/resourceclaim.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def prune_k8s_resource(resource: Mapping) -> Mapping:
ret = {
key: value
for key, value in resource.items()
if key != "metadata"
if key not in {"metadata", "status"}
}
ret["metadata"] = {
key: value
for key, value in resource['metadata'].items()
if key not in {'annotations', 'managedFields'}
if key not in {'annotations', 'generation', 'managedFields'}
}
if 'annotations' in resource['metadata']:
filtered_annotations = {
Expand All @@ -38,6 +38,12 @@ def prune_k8s_resource(resource: Mapping) -> Mapping:
}
if filtered_annotations:
ret["metadata"]["annotations"] = filtered_annotations
if 'status' in resource:
ret["status"] = {
key: value
for key, value in resource['status'].items()
if not key in {'diffBase'}
}
return ret

class ResourceClaim(KopfObject):
Expand Down Expand Up @@ -76,7 +82,11 @@ async def get(cls, name: str, namespace: str, use_cache: bool=True) -> ResourceC
if use_cache and (namespace, name) in cls.instances:
return cls.instances[(namespace, name)]
definition = await Poolboy.custom_objects_api.get_namespaced_custom_object(
Poolboy.operator_domain, Poolboy.operator_version, namespace, 'resourceclaims', name
group=cls.api_group,
name=name,
namespace=namespace,
plural=cls.plural,
version=cls.api_version,
)
if use_cache:
return cls.__register_definition(definition)
Expand Down Expand Up @@ -543,13 +553,18 @@ async def update_status_from_handle(self,
"provider": resource_handle.resources[resource_index]['provider'],
**status_resource,
}
if 'name' in current_entry:
resource_entry['name'] = current_entry['name']
if 'validationError' in current_entry:
resource_entry['validationError'] = current_entry['validationError']
if resource_states:
if resource_index < len(resource_states) and resource_states[resource_index] is not None:
resource_entry['state'] = prune_k8s_resource(
resource_states[resource_index]
)
if (
resource_states and
resource_index < len(resource_states) and
resource_states[resource_index] is not None
):
resource_entry['state'] = prune_k8s_resource(
resource_states[resource_index]
)
elif 'state' in current_entry:
resource_entry['state'] = current_entry['state']

Expand Down
5 changes: 4 additions & 1 deletion operator/resourcehandle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,10 @@ async def manage(self, logger: kopf.ObjectLogger) -> None:
linked_resource_provider = None
linked_resource_state = None
for pn, pv in enumerate(resource_providers):
if pv.name == linked_provider.name:
if (
pv.name == linked_provider.name and
self.resources[pn].get('name', pv.name) == linked_provider.resource_name
):
linked_resource_provider = pv
linked_resource_state = resource_states[pn]
break
Expand Down
5 changes: 5 additions & 0 deletions operator/resourcewatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@ async def __watch_event(self, event_type, event_obj):
if not resource_handle_name:
return

if event_type == 'DELETED':
self.cache.pop(resource_name, None)
else:
self.cache[resource_name] = ResourceWatch.CacheEntry(event_obj)

try:
resource_handle = await resourcehandle.ResourceHandle.get(
name=resource_handle_name,
Expand Down