Skip to content
This repository has been archived by the owner on Dec 21, 2019. It is now read-only.

Commit

Permalink
feat main: Initial program implementation & example
Browse files Browse the repository at this point in the history
  • Loading branch information
tazjin committed Feb 8, 2017
1 parent 9e3ee3f commit 8fb24f9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions example/prod-cluster.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
Empty file.
5 changes: 5 additions & 0 deletions example/some-api/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: foo
importantFeature: {{ .importantFeature }}
port: {{ .apiPort }}
globalTest: {{ .globalTest }}
39 changes: 39 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 8fb24f9

Please sign in to comment.