about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--example/prod-cluster.json16
-rw-r--r--example/some-api/deployment.yaml0
-rw-r--r--example/some-api/service.yaml5
-rw-r--r--main.go39
4 files changed, 60 insertions, 0 deletions
diff --git a/example/prod-cluster.json b/example/prod-cluster.json
new file mode 100644
index 000000000000..76246ca382de
--- /dev/null
+++ b/example/prod-cluster.json
@@ -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
+      }
+    }
+  ]
+}
diff --git a/example/some-api/deployment.yaml b/example/some-api/deployment.yaml
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/example/some-api/deployment.yaml
diff --git a/example/some-api/service.yaml b/example/some-api/service.yaml
new file mode 100644
index 000000000000..6aee8788093c
--- /dev/null
+++ b/example/some-api/service.yaml
@@ -0,0 +1,5 @@
+---
+name: foo
+importantFeature: {{ .importantFeature }}
+port: {{ .apiPort }}
+globalTest: {{ .globalTest }}
diff --git a/main.go b/main.go
new file mode 100644
index 000000000000..c33ec133d70c
--- /dev/null
+++ b/main.go
@@ -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)
+		}
+	}
+}