diff --git a/scripts/native/cicd/hwlab-node-control-plane-refresh.mjs b/scripts/native/cicd/hwlab-node-control-plane-refresh.mjs index 9c500127..2ed59e6d 100644 --- a/scripts/native/cicd/hwlab-node-control-plane-refresh.mjs +++ b/scripts/native/cicd/hwlab-node-control-plane-refresh.mjs @@ -136,10 +136,17 @@ function renderControlPlane() { async function applyPipeline() { const pipelinePath = path.join(renderDir, overlay.tektonDir, "pipeline.yaml"); if (!existsSync(pipelinePath)) throw new Error(`rendered Pipeline missing: ${pipelinePath}`); - const pipelineText = readFileSync(pipelinePath, "utf8"); - const pipeline = yamlModule().parse(pipelineText); - const pipelineName = pipeline?.metadata?.name; - if (typeof pipelineName !== "string" || pipelineName.length === 0) throw new Error(`rendered Pipeline metadata.name missing: ${pipelinePath}`); + const YAML = yamlModule(); + const pipeline = YAML.parse(readFileSync(pipelinePath, "utf8")); + if (!pipeline || typeof pipeline !== "object") throw new Error(`rendered Pipeline is not an object: ${pipelinePath}`); + const renderedPipelineName = pipeline?.metadata?.name; + if (typeof renderedPipelineName !== "string" || renderedPipelineName.length === 0) { + throw new Error(`rendered Pipeline metadata.name missing: ${pipelinePath}`); + } + const pipelineName = requiredOverlayString("pipelineName"); + pipeline.metadata = pipeline.metadata && typeof pipeline.metadata === "object" ? pipeline.metadata : {}; + pipeline.metadata.name = pipelineName; + const pipelineText = YAML.stringify(pipeline); await kubeRequest( "PATCH", `/apis/tekton.dev/v1/namespaces/${encodeURIComponent(tektonNamespace)}/pipelines/${encodeURIComponent(pipelineName)}?fieldManager=${encodeURIComponent(fieldManager)}&force=true`,