From 9420c408d0206bea0677835012f687607dbe61b6 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 25 Oct 2021 10:51:46 -0400 Subject: [PATCH] Fix type error Signed-off-by: Sebastian Malton --- src/common/k8s/resource-stack.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/common/k8s/resource-stack.ts b/src/common/k8s/resource-stack.ts index 650650ff92..483dbeeb9b 100644 --- a/src/common/k8s/resource-stack.ts +++ b/src/common/k8s/resource-stack.ts @@ -121,30 +121,32 @@ export class ResourceStack { for(const filename of files) { const file = path.join(folderPath, filename); const raw = await fse.readFile(file); - let resourceData: string; + const data = ( + filename.endsWith(".hb") + ? hb.compile(raw.toString())(templateContext) + : raw.toString() + ).trim(); - if (filename.endsWith(".hb")) { - const template = hb.compile(raw.toString()); - - resourceData = template(templateContext); - } else { - resourceData = raw.toString(); + if (!data) { + continue; } - if (!resourceData.trim()) continue; + for (const entry of yaml.loadAll(data)) { + if (typeof entry !== "object" || !entry) { + continue; + } - const resourceArray = yaml.loadAll(resourceData.toString()); + const resource = entry as Record; - resourceArray.forEach((resource) => { - if (resource?.metadata) { - resource.metadata.labels ||= {}; + if (typeof resource.metadata === "object") { + resource.metadata.labels ??= {}; resource.metadata.labels["app.kubernetes.io/name"] = this.name; resource.metadata.labels["app.kubernetes.io/managed-by"] = productName; resource.metadata.labels["app.kubernetes.io/created-by"] = "resource-stack"; } resources.push(yaml.dump(resource)); - }); + } } return resources;