kubricate
Version:
A TypeScript framework for building reusable, type-safe Kubernetes infrastructure — without the YAML mess.
32 lines • 1.01 kB
JavaScript
import crypto from 'node:crypto';
// kubectl-executor.ts
import { writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
export class KubectlExecutor {
kubectlPath;
logger;
execa;
constructor(kubectlPath, logger, execa) {
this.kubectlPath = kubectlPath;
this.logger = logger;
this.execa = execa;
}
async apply(resource) {
const tempPath = this.createTempFilePath();
await writeFile(tempPath, JSON.stringify(resource), 'utf8');
this.logger.info(`Applying secret resource with kubectl: ${tempPath}`);
try {
await this.execa.run(this.kubectlPath, ['apply', '-f', tempPath]);
this.logger.log('✅ Applied secret via kubectl');
} catch (err) {
this.logger.error(`❌ kubectl apply failed: ${err.message}`);
throw err;
}
}
createTempFilePath() {
const id = crypto.randomUUID();
return path.join(tmpdir(), `kubricate-secret-${id}.json`);
}
}
//# sourceMappingURL=kubectl-executor.js.map