Created
April 4, 2024 08:51
-
-
Save srfrnk/d860cd3071bb7713039950dc6210784b to your computer and use it in GitHub Desktop.
Convert YAML K8s manifest file into a JS CDK8S manifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"yaml": "^2.4.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run this: bash -s ./setup.sh | |
npm i | |
chmod +x ./Yaml2Crdk8s.js | |
# Usage: ./Yaml2Crdk8s.js < <INPUT_FILE>.yml > <OUTPUT_FILE>.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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