-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from laurci/feat/init-cmd
feat: kubernate init with templates
- Loading branch information
Showing
36 changed files
with
602 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules | ||
src/__generated__/ | ||
src/__generated__/ | ||
src/assets | ||
dist/ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
targetVersion: "v1" | ||
scripts: | ||
hello-world: ./src/hello-world.ts |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
output/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"tabWidth": 4, | ||
"singleQuote": false, | ||
"bracketSpacing": false, | ||
"printWidth": 140 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"recommendations": ["redhat.vscode-yaml", "esbenp.prettier-vscode"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"yaml.schemas": { | ||
"node_modules/kubernate/schemas/config.json": ".kubernaterc.yaml" | ||
}, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## {{projectName}} | ||
|
||
Run `kubernate hello-world`. | ||
|
||
This example uses Kubernate to create a namespace, a pod template and a deployment. The outputs are written to a single yaml file in `output/hello-world.yaml`. |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "{{projectName}}", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"scripts": { | ||
"format": "prettier --write .", | ||
"build": "tsc" | ||
}, | ||
"dependencies": { | ||
"kubernate": "~1.22" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^16.7.9", | ||
"prettier": "^2.3.2", | ||
"typescript": "^4.3.5" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import kube, {output} from "kubernate"; | ||
|
||
/** | ||
* Kubernate comes with some pre-built resource helpers for most common resources. | ||
* check imports from "kubernate/resources/*" | ||
*/ | ||
import namespace from "kubernate/resources/namespace"; | ||
|
||
import * as path from "path"; | ||
|
||
const outputPath = (fileName: string) => path.join(__dirname, "../output", fileName); | ||
|
||
/** | ||
* This is the main entry point and will be called by Kubernate. | ||
*/ | ||
export default async () => { | ||
// carete a new namespace | ||
const ns = namespace("hello-world"); | ||
|
||
// create and reuse this selector | ||
const selector = { | ||
app: "hello-world", | ||
}; | ||
|
||
// create a pod template for out deployment | ||
const pod = kube.core.v1.PodTemplate({ | ||
template: { | ||
metadata: { | ||
namespace: ns, | ||
name: "hello-world", | ||
labels: selector, | ||
}, | ||
spec: { | ||
containers: [ | ||
{ | ||
name: "hello-world-http", | ||
image: "kornkitti/express-hello-world:latest", | ||
imagePullPolicy: "Always", | ||
ports: [ | ||
{ | ||
containerPort: 8080, | ||
name: "http", | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
// create a deployment using our pod template | ||
kube.apps.v1.Deployment({ | ||
metadata: { | ||
namespace: ns, | ||
name: "hello-world", | ||
}, | ||
spec: { | ||
replicas: 1, | ||
selector: { | ||
matchLabels: selector, | ||
}, | ||
template: pod.template!, | ||
}, | ||
}); | ||
|
||
// write the output to disk | ||
await output.bundleToDisk(outputPath("hello-world.yaml")); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"incremental": true, | ||
"target": "ES2019", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"sourceMap": true, | ||
"outDir": "./dist", | ||
"strict": true, | ||
"strictFunctionTypes": false, | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"include": ["src"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
12 changes: 12 additions & 0 deletions
12
src/assets/init-templates/with-resources/.kubernaterc.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
targetVersion: "v1" | ||
scripts: | ||
hello-world: ./src/hello-world.ts | ||
resources: | ||
entry: ./src/resources/index.ts | ||
entryTypeName: Resources # this is optional | ||
exclude: | ||
- output/* | ||
include: input/*.yaml | ||
output: | ||
code: ./src/generated | ||
schemas: ./schemas |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
output/ | ||
src/generated |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"tabWidth": 4, | ||
"singleQuote": false, | ||
"bracketSpacing": false, | ||
"printWidth": 140 | ||
} |
3 changes: 3 additions & 0 deletions
3
src/assets/init-templates/with-resources/.vscode/extensions.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"recommendations": ["redhat.vscode-yaml", "esbenp.prettier-vscode"] | ||
} |
14 changes: 14 additions & 0 deletions
14
src/assets/init-templates/with-resources/.vscode/settings.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"yaml.schemas": { | ||
"node_modules/kubernate/schemas/config.json": ".kubernaterc.yaml", | ||
"schemas/resources.json": "[!output]**/[!.kubernaterc]*.yaml" | ||
}, | ||
"files.exclude": { | ||
"**/.git": true, | ||
"**/.svn": true, | ||
"**/.hg": true, | ||
"**/CVS": true, | ||
"**/.DS_Store": true, | ||
".kubernate": true | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## {{projectName}} | ||
|
||
Run `kubernate hello-world`. | ||
|
||
This example uses Kubernate to create a namespace, a pod template and a deployment for every demo/v1/HelloWorld you create. The outputs are written to a single yaml file in `output/hello-world.yaml`. | ||
|
||
If you update the spec of the resource, make sure to run `kubernate generate` to update the generated code. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# you have intellisense here. give it a try :) | ||
apiVersion: demo/v1 | ||
kind: HelloWorld | ||
metadata: | ||
name: hello-test1 | ||
spec: | ||
who: world1 | ||
--- | ||
apiVersion: demo/v1 | ||
kind: HelloWorld | ||
metadata: | ||
name: hello-test2 | ||
spec: | ||
who: world2 |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "{{projectName}}", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"scripts": { | ||
"format": "prettier --write .", | ||
"build": "tsc" | ||
}, | ||
"dependencies": { | ||
"kubernate": "~1.22" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^16.7.9", | ||
"prettier": "^2.3.2", | ||
"typescript": "^4.3.5" | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/assets/init-templates/with-resources/schemas/objects.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"description": "This is how you can declare a resource", | ||
"type": "object", | ||
"properties": { | ||
"apiVersion": { | ||
"type": "string", | ||
"enum": [ | ||
"demo/v1" | ||
] | ||
}, | ||
"kind": { | ||
"type": "string", | ||
"enum": [ | ||
"HelloWorld" | ||
] | ||
}, | ||
"metadata": { | ||
"type": "object", | ||
"properties": { | ||
"namespace": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"annotations": { | ||
"type": "object", | ||
"additionalProperties": {}, | ||
"propertyOrder": [] | ||
} | ||
}, | ||
"propertyOrder": [ | ||
"namespace", | ||
"name", | ||
"annotations" | ||
], | ||
"required": [ | ||
"name" | ||
] | ||
}, | ||
"spec": { | ||
"$ref": "#/definitions/HelloWorldServiceSpec" | ||
} | ||
}, | ||
"propertyOrder": [ | ||
"apiVersion", | ||
"kind", | ||
"metadata", | ||
"spec" | ||
], | ||
"required": [ | ||
"apiVersion", | ||
"kind", | ||
"metadata", | ||
"spec" | ||
], | ||
"definitions": { | ||
"HelloWorldServiceSpec": { | ||
"description": "This is the spec of our resource.", | ||
"type": "object", | ||
"properties": { | ||
"who": { | ||
"type": "string" | ||
} | ||
}, | ||
"propertyOrder": [ | ||
"who" | ||
], | ||
"required": [ | ||
"who" | ||
] | ||
} | ||
}, | ||
"$schema": "http://json-schema.org/draft-07/schema#" | ||
} |
8 changes: 8 additions & 0 deletions
8
src/assets/init-templates/with-resources/schemas/resources.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"oneOf": [ | ||
{ | ||
"$ref": "objects.json" | ||
} | ||
] | ||
} |
11 changes: 11 additions & 0 deletions
11
src/assets/init-templates/with-resources/src/generated/declarations.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
/** | ||
* This file was generated by kubernate. | ||
* Do not edit this file manually. Any changes will be overwritten. | ||
*/ | ||
import { HelloWorldService } from "../resources/hello-world-service"; | ||
|
||
|
||
export type DeclaredServicesMap = { | ||
"demo/v1/HelloWorld": HelloWorldService | ||
}; |
11 changes: 11 additions & 0 deletions
11
src/assets/init-templates/with-resources/src/generated/index.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
/** | ||
* This file was generated by kubernate. | ||
* Do not edit this file manually. Any changes will be overwritten. | ||
*/ | ||
import {makeResourcesBrowser} from "kubernate/internal/api"; | ||
import {join as pathJoin} from "path"; | ||
import {DeclaredServicesMap} from "./declarations"; | ||
|
||
const resources = makeResourcesBrowser<DeclaredServicesMap>(pathJoin(__dirname, "../..")); | ||
export default resources; |
Oops, something went wrong.