From e835da55aa1d100237db33d8359c52bcaad2b91d Mon Sep 17 00:00:00 2001 From: Johnathan Kupferer Date: Wed, 4 Sep 2024 09:51:16 -0400 Subject: [PATCH 1/2] Fix bug in ResourceHandle age preference - Older handles should be preferred, recent change flipped the logic --- operator/resourcehandle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator/resourcehandle.py b/operator/resourcehandle.py index 2d27f78..e1f43fd 100644 --- a/operator/resourcehandle.py +++ b/operator/resourcehandle.py @@ -68,7 +68,7 @@ def __lt__(self, cmp): return False # Prefer older matches - return self.resource_handle.creation_timestamp < cmp.resource_handle.creation_timestamp + return self.resource_handle.creation_timestamp > cmp.resource_handle.creation_timestamp class ResourceHandle(KopfObject): api_group = Poolboy.operator_domain From c64f4edc39721847463133860a8bbf6b57c73d6d Mon Sep 17 00:00:00 2001 From: Johnathan Kupferer Date: Wed, 4 Sep 2024 10:18:38 -0400 Subject: [PATCH 2/2] Fix resource handle preference logic. --- operator/resourcehandle.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/operator/resourcehandle.py b/operator/resourcehandle.py index e1f43fd..308f56e 100644 --- a/operator/resourcehandle.py +++ b/operator/resourcehandle.py @@ -36,39 +36,39 @@ def __lt__(self, cmp): '''Compare matches by preference''' if self.resource_count_difference < cmp.resource_count_difference: return True - elif self.resource_count_difference > cmp.resource_count_difference: + if self.resource_count_difference > cmp.resource_count_difference: return False if self.resource_name_difference_count < cmp.resource_name_difference_count: return True - elif self.resource_name_difference_count > cmp.resource_name_difference_count: + if self.resource_name_difference_count > cmp.resource_name_difference_count: return False if self.template_difference_count < cmp.template_difference_count: return True - elif self.template_difference_count > cmp.template_difference_count: + if self.template_difference_count > cmp.template_difference_count: return False # Prefer healthy resources to unknown health state - if self.resource_handle.is_healthy and not cmp.resource_handle.is_healthy == None: + if self.resource_handle.is_healthy and cmp.resource_handle.is_healthy == None: return True - elif not self.resource_handle.is_healthy and cmp.resource_handle.is_healthy == None: + if self.resource_handle.is_healthy == None and cmp.resource_handle.is_healthy: return False # Prefer ready resources to unready or unknown readiness state if self.resource_handle.is_ready and not cmp.resource_handle.is_ready: return True - elif not self.resource_handle.is_ready and cmp.resource_handle.is_ready: + if not self.resource_handle.is_ready and cmp.resource_handle.is_ready: return False # Prefer unknown readiness state to known unready state - if self.resource_handle.is_ready == None and not cmp.resource_handle.is_ready == False: + if self.resource_handle.is_ready == None and cmp.resource_handle.is_ready == False: return True - elif not self.resource_handle.is_ready == False and cmp.resource_handle.is_ready == None: + if not self.resource_handle.is_ready == False and cmp.resource_handle.is_ready == None: return False # Prefer older matches - return self.resource_handle.creation_timestamp > cmp.resource_handle.creation_timestamp + return self.resource_handle.creation_timestamp < cmp.resource_handle.creation_timestamp class ResourceHandle(KopfObject): api_group = Poolboy.operator_domain