Skip to content

Instantly share code, notes, and snippets.

@srfrnk
Created April 4, 2024 08:51
Show Gist options
  • Save srfrnk/d860cd3071bb7713039950dc6210784b to your computer and use it in GitHub Desktop.
Save srfrnk/d860cd3071bb7713039950dc6210784b to your computer and use it in GitHub Desktop.
Convert YAML K8s manifest file into a JS CDK8S manifest
{
"dependencies": {
"yaml": "^2.4.1"
}
}
# Run this: bash -s ./setup.sh
npm i
chmod +x ./Yaml2Crdk8s.js
# Usage: ./Yaml2Crdk8s.js < <INPUT_FILE>.yml > <OUTPUT_FILE>.js
#!/usr/bin/env node
const fs=require('fs');
const YAML = require('yaml')
input=YAML.parseAllDocuments(fs.readFileSync('/dev/stdin').toString(),{}).map((item)=>item.toJS());
for (const obj of input) {
kind=obj.kind;
delete obj.kind;
delete obj.apiVersion;
console.log(`new Kube${kind}(scope,"${obj.metadata.name}-${kind.toLowerCase()}",${JSON.stringify(obj)});\n`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment