From 129e69245cfc9f55beb82035b1e4830d789ad961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Huss?= Date: Mon, 12 Feb 2024 15:33:56 +0100 Subject: [PATCH] Gramo 0.1.0 --- .../back/tmpl.resolvers.fluxcd.ts.hbs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 utils/generator/back/tmpl.resolvers.fluxcd.ts.hbs diff --git a/utils/generator/back/tmpl.resolvers.fluxcd.ts.hbs b/utils/generator/back/tmpl.resolvers.fluxcd.ts.hbs new file mode 100644 index 0000000..b20aa46 --- /dev/null +++ b/utils/generator/back/tmpl.resolvers.fluxcd.ts.hbs @@ -0,0 +1,39 @@ +{{#if (and (eq type 'consume') (eq targetShort 'ImageRepository'))}} + {{type}}{{targetShort}}: async (parent, args: object) => { + const ns = typeof parent['spec']['imageRepositoryRef']['namespace'] == 'string' ? parent['spec']['imageRepositoryRef']['namespace']:parent['metadata']['namespace'] + const lst = (await list{{targetShort}}.{{targetGroup}}{{targetShort}}(parent,{namespace: ns, ...args})) + .filter((i) => i.metadata.name == parent['spec']['imageRepositoryRef']['name']) + if (lst.length<1) return null; + return lst[0] + }, +{{/if}} +{{#if (and (eq type 'provide') (eq short 'ImageRepository'))}} + {{type}}{{targetShort}}: async (parent, args: object) => { + const nss = await listNamespace.k8sNamespace(parent, args) + const res = (await Promise.all(nss.map(n=>n['metadata']['name']).map(async (ns)=>{ + const lst = await list{{targetShort}}.{{targetGroup}}{{targetShort}}(parent, {namespace: ns, ...args}) + return lst.filter(r=>r['spec']['imageRepositoryRef']['name']==parent['metadata']['name']&&(r['spec']['imageRepositoryRef']['namespace']==parent['metadata']['namespace']||(r['metadata']['namespace']==parent['metadata']['namespace']&&typeof parent['spec']['imageRepositoryRef']['namespace'] != 'string'))) + }))) + return res.flat().filter((v)=>v!=null) + }, +{{/if}} +{{#if (and (eq type 'consume') (eq targetShort 'GitRepository'))}} + {{type}}{{targetShort}}: async (parent, args: object) => { + if (parent['spec']['sourceRef']['kind']!='GitRepository') return null; + const ns = typeof parent['spec']['sourceRef']['namespace'] == 'string' ? parent['spec']['sourceRef']['namespace']:parent['metadata']['namespace'] + const lst = (await list{{targetShort}}.{{targetGroup}}{{targetShort}}(parent,{namespace: ns, ...args})) + .filter((i) => i.metadata.name == parent['spec']['sourceRef']['name']) + if (lst.length<1) return null; + return lst[0] + }, +{{/if}} +{{#if (and (eq type 'provide') (eq short 'GitRepository'))}} + {{type}}{{targetShort}}: async (parent, args: object) => { + const nss = await listNamespace.k8sNamespace(parent, args) + const res = (await Promise.all(nss.map(n=>n['metadata']['name']).map(async (ns)=>{ + const lst = await list{{targetShort}}.{{targetGroup}}{{targetShort}}(parent, {namespace: ns, ...args}) + return lst.filter(r=>r['spec']['sourceRef']['kind']=='GitRepository'&&r['spec']['sourceRef']['name']==parent['metadata']['name']&&(r['spec']['sourceRef']['namespace']==parent['metadata']['namespace']||(r['metadata']['namespace']==parent['metadata']['namespace']&&typeof parent['spec']['sourceRef']['namespace'] != 'string'))) + }))) + return res.flat().filter((v)=>v!=null) + }, +{{/if}}