From 54172678ff9634208e6de41d68df83405fbc78fe Mon Sep 17 00:00:00 2001 From: Sam Blausten Date: Wed, 11 Dec 2024 13:03:09 +0100 Subject: [PATCH] Support namespaced group tag values (#1754) --- .changeset/proud-tomatoes-fix.md | 5 +++++ .../src/utils/tags.test.ts | 18 ++++++++++++++++++ .../src/utils/tags.ts | 5 ++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .changeset/proud-tomatoes-fix.md diff --git a/.changeset/proud-tomatoes-fix.md b/.changeset/proud-tomatoes-fix.md new file mode 100644 index 000000000..6098a3981 --- /dev/null +++ b/.changeset/proud-tomatoes-fix.md @@ -0,0 +1,5 @@ +--- +'@roadiehq/catalog-backend-module-aws': patch +--- + +Add support from namespaced group tagging diff --git a/plugins/backend/catalog-backend-module-aws/src/utils/tags.test.ts b/plugins/backend/catalog-backend-module-aws/src/utils/tags.test.ts index 1b018758e..2e204c237 100644 --- a/plugins/backend/catalog-backend-module-aws/src/utils/tags.test.ts +++ b/plugins/backend/catalog-backend-module-aws/src/utils/tags.test.ts @@ -173,6 +173,24 @@ describe('labelsFromTags and ownerFromTags', () => { const result = ownerFromTags(tags, 'tagOwner', groups); expect(result).toBe('group:test/owner1'); }); + + it('should return owner from an object of tags with different ownerTagKey when tag contains namespace', () => { + const tags = { tagOwner: 'test/owner1', 'tag:two': 'value2' }; + const groupsWithMultipleNamespaces = [ + ...groups, + { + kind: 'Group', + metadata: { name: 'owner1', namespace: 'default' }, + } as Entity, + ]; + const result = ownerFromTags( + tags, + 'tagOwner', + groupsWithMultipleNamespaces, + ); + expect(result).toBe('group:test/owner1'); + }); + it('should handle complex owner keys and values in an array of tags', () => { const tags = [{ Key: 'owner:one', Value: 'owner1' }]; const result = ownerFromTags(tags, 'owner:one', groups); diff --git a/plugins/backend/catalog-backend-module-aws/src/utils/tags.ts b/plugins/backend/catalog-backend-module-aws/src/utils/tags.ts index 7c6534d75..ef8ca12c2 100644 --- a/plugins/backend/catalog-backend-module-aws/src/utils/tags.ts +++ b/plugins/backend/catalog-backend-module-aws/src/utils/tags.ts @@ -108,7 +108,10 @@ export const ownerFromTags = ( if (ownerString && groups && groups.length > 0) { const exactMatch = groups.find( - g => g.metadata.name.toLowerCase() === ownerString?.toLowerCase(), + g => + g.metadata.name.toLowerCase() === ownerString?.toLowerCase() || + `${g.metadata.namespace}/${g.metadata.name}`.toLowerCase() === + ownerString?.toLowerCase(), ); if (exactMatch) { return stringifyEntityRef(exactMatch);