feat main: Initial program implementation & example

This commit is contained in:
Vincent Ambo 2017-02-08 11:51:08 +01:00
parent 9e3ee3f2bb
commit 8fb24f9f75
4 changed files with 60 additions and 0 deletions

16
example/prod-cluster.json Normal file
View file

@ -0,0 +1,16 @@
{
"context": "k8s.prod.mydomain.com",
"global": {
"globalTest": "lizards"
},
"include": [
{
"name": "some-api",
"values": {
"version": "1.0-SNAPSHOT-0e6884d",
"importantFeature": true,
"apiPort": 4567
}
}
]
}

View file

View file

@ -0,0 +1,5 @@
---
name: foo
importantFeature: {{ .importantFeature }}
port: {{ .apiPort }}
globalTest: {{ .globalTest }}

39
main.go Normal file
View file

@ -0,0 +1,39 @@
package main
import (
"os"
"fmt"
"github.com/tazjin/kontemplate/context"
"github.com/tazjin/kontemplate/templater"
)
func main() {
args := os.Args[1:]
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "Usage: kontemplate <cluster-config>")
os.Exit(1)
}
c, err := context.LoadContextFromFile(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Fprintf(os.Stderr,"Applying cluster %s\n", c.Name)
for _, rs := range c.ResourceSets {
fmt.Fprintf(os.Stderr,"Applying resource %s with values %v\n", rs.Name, rs.Values)
resources, err := templater.LoadAndPrepareTemplates(c)
if err != nil {
fmt.Println(err)
}
for _, r := range resources {
fmt.Print(r)
}
}
}