22import Configstore from "configstore" ;
33import clear from "clear" ;
44import Mustache from "mustache" ;
5+ import { parse , stringify } from "yaml" ;
6+ import { readFile , writeFile } from "node:fs/promises" ;
57import { getOutputValues } from "./lib/terraform.mjs" ;
68import { exitWithError } from "./lib/utils.mjs" ;
79
@@ -16,6 +18,7 @@ const config = new Configstore(projectName, { projectName });
1618
1719const compartmentId = config . get ( "compartmentId" ) ;
1820const namespace = config . get ( "namespace" ) ;
21+ const profile = config . get ( "profile" ) ;
1922const regionName = config . get ( "regionName" ) ;
2023const regionKey = config . get ( "regionKey" ) ;
2124const webVersion = config . get ( "webVersion" ) ;
@@ -28,6 +31,7 @@ const genAiModelSummarization = config.get("genAiModelSummarization");
2831
2932const { db_service, db_password } = await getOutputValues ( "./deploy/terraform" ) ;
3033
34+ await addProfileToKubeconfig ( profile ) ;
3135await createBackendProperties ( ) ;
3236await createProdKustomization ( ) ;
3337await copyCerts ( ) ;
@@ -150,3 +154,25 @@ async function createRegistrySecret() {
150154 exitWithError ( error . stderr ) ;
151155 }
152156}
157+
158+ async function addProfileToKubeconfig ( profile = "DEFAULT" ) {
159+ if ( profile === "DEFAULT" ) return ;
160+
161+ const kubeconfigPath = "./deploy/terraform/generated/kubeconfig" ;
162+
163+ let yamlContent = await readFile ( kubeconfigPath , {
164+ encoding : "utf-8" ,
165+ } ) ;
166+
167+ const profileFlag = "--profile" ;
168+ const profileValue = profile ;
169+
170+ const kubeconfig = parse ( yamlContent ) ;
171+ const execArgs = kubeconfig . users [ 0 ] . user . exec . args ;
172+ kubeconfig . users [ 0 ] . user . exec . args = [ ...execArgs , profileFlag , profileValue ] ;
173+ const newKubeconfigContent = stringify ( kubeconfig ) ;
174+
175+ await writeFile ( kubeconfigPath , newKubeconfigContent , {
176+ encoding : "utf-8" ,
177+ } ) ;
178+ }
0 commit comments