From f270233dcca04793330863b454c9791263ea8c33 Mon Sep 17 00:00:00 2001 From: Sekar Saravanan Date: Tue, 16 Jul 2024 12:21:38 +0530 Subject: [PATCH] issue-5702 - Multiple duplicate mappings generated for single mapping resource fixed Signed-off-by: Sekar Saravanan --- python/ambassador/ir/ir.py | 8 +++++++- python/ambassador_diag/diagd.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/python/ambassador/ir/ir.py b/python/ambassador/ir/ir.py index d0996a626d..bfb8b8a062 100644 --- a/python/ambassador/ir/ir.py +++ b/python/ambassador/ir/ir.py @@ -817,7 +817,13 @@ def add_mapping(self, aconf: Config, mapping: IRBaseMapping) -> Optional[IRBaseM else: self.logger.debug(f"IR: already have group for {mapping.name}") group = self.groups[mapping.group_id] - group.add_mapping(aconf, mapping) + + # Add mapping into the group only if the _cache_key doesn't exist in a group. + existing_mapping_cache_keys = [ group_mapping["_cache_key"] for group_mapping in group["mappings"] if "_cache_key" in group_mapping ] + if mapping["_cache_key"] in existing_mapping_cache_keys: + self.logger.debug(f"IR: _cache_key for {mapping.name} is {mapping['_cache_key']} already exists in a group.") + else: + group.add_mapping(aconf, mapping) self.cache_add(mapping) self.cache_add(group) diff --git a/python/ambassador_diag/diagd.py b/python/ambassador_diag/diagd.py index c93b30534f..316a49ade8 100644 --- a/python/ambassador_diag/diagd.py +++ b/python/ambassador_diag/diagd.py @@ -551,7 +551,7 @@ def check_cache(self) -> bool: result = False self.logger.error("CACHE: ENVOY CONFIG MISMATCH") errors += "econf diffs:\n" - errors += self.json_diff("econf", i1, i2) + errors += self.json_diff("econf", e1, e2) if not result: err_path = os.path.join(self.snapshot_path, "diff-tmp.txt")