diff --git a/tenant/ingres-template.yaml b/tenant/ingres-template.yaml new file mode 100644 index 0000000..c81f9f1 --- /dev/null +++ b/tenant/ingres-template.yaml @@ -0,0 +1,7 @@ + - path: /()(%tenant%/.*) + pathType: ImplementationSpecific + backend: + service: + name: frontend-%tenant% + port: + number: %port% \ No newline at end of file diff --git a/tenant/tenant-creation.js b/tenant/tenant-creation.js index 6c67fa2..dd75729 100644 --- a/tenant/tenant-creation.js +++ b/tenant/tenant-creation.js @@ -80,6 +80,16 @@ function createK8sFrontendYaml(tenant, applicationId, port, backgroundColor) { fs.writeFileSync(`../deployement/k8s/frontend-${tenant}.yaml`, frontendTenantYaml); } +function appendTenantToIngress(tenant, port) { + let ingressYaml = fs.readFileSync('../deployement/k8s/ingress.yaml', 'utf8'); + let ingresTemplateYaml = fs.readFileSync('./ingres-template.yaml', 'utf8'); + const replacements = { "%tenant%": tenant, "%port%": port }; + let ingresAppendTenantYaml = ingresTemplateYaml.replace(/%\w+%/g, function(all) { + return replacements[all] || all; + }); + fs.writeFileSync('../deployement/k8s/ingress.yaml', ingressYaml + "\n" + ingresAppendTenantYaml); +} + async function main() { const tenant = prompt("Tenant name (key): "); const port = prompt("Port: "); @@ -91,6 +101,7 @@ async function main() { console.log(`- Client Secret: ${clientSecret}`); console.log(); createK8sFrontendYaml(tenant, applicationId, port, backgroundColor); + appendTenantToIngress(tenant, port); } main();