chore: Better example & gofmt
This commit is contained in:
parent
8fb24f9f75
commit
8fac7c1a41
6 changed files with 42 additions and 14 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"context": "k8s.prod.mydomain.com",
|
"context": "k8s.prod.mydomain.com",
|
||||||
"global": {
|
"global": {
|
||||||
"globalTest": "lizards"
|
"globalVar": "lizards"
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
name: foo
|
|
||||||
importantFeature: {{ .importantFeature }}
|
|
||||||
port: {{ .apiPort }}
|
|
||||||
globalTest: {{ .globalTest }}
|
|
||||||
34
example/some-api/some-api.yaml
Normal file
34
example/some-api/some-api.yaml
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
---
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: some-api
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: some-api
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: my.container.repo/some-api:{{ .version }}
|
||||||
|
name: some-api
|
||||||
|
env:
|
||||||
|
- name: ENABLE_IMPORTANT_FEATURE
|
||||||
|
value: {{ .importantFeature }}
|
||||||
|
- name: SOME_GLOBAL_VAR
|
||||||
|
value: {{ .globalVar }}
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: some-api
|
||||||
|
labels:
|
||||||
|
app: some-api
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: some-api
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: {{ .apiPort }}
|
||||||
|
name: http
|
||||||
6
main.go
6
main.go
|
|
@ -1,8 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/tazjin/kontemplate/context"
|
"github.com/tazjin/kontemplate/context"
|
||||||
"github.com/tazjin/kontemplate/templater"
|
"github.com/tazjin/kontemplate/templater"
|
||||||
|
|
@ -22,10 +22,10 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr,"Applying cluster %s\n", c.Name)
|
fmt.Fprintf(os.Stderr, "Applying cluster %s\n", c.Name)
|
||||||
|
|
||||||
for _, rs := range c.ResourceSets {
|
for _, rs := range c.ResourceSets {
|
||||||
fmt.Fprintf(os.Stderr,"Applying resource %s with values %v\n", rs.Name, rs.Values)
|
fmt.Fprintf(os.Stderr, "Applying resource %s with values %v\n", rs.Name, rs.Values)
|
||||||
resources, err := templater.LoadAndPrepareTemplates(c)
|
resources, err := templater.LoadAndPrepareTemplates(c)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
package templater
|
package templater
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"bytes"
|
|
||||||
|
|
||||||
"github.com/tazjin/kontemplate/context"
|
|
||||||
"github.com/polydawn/meep"
|
"github.com/polydawn/meep"
|
||||||
|
"github.com/tazjin/kontemplate/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error that is caused by non-existent template files being specified
|
// Error that is caused by non-existent template files being specified
|
||||||
|
|
@ -28,7 +28,7 @@ func LoadAndPrepareTemplates(c *context.Context) ([]string, error) {
|
||||||
output := make([]string, 0)
|
output := make([]string, 0)
|
||||||
|
|
||||||
for _, rs := range c.ResourceSets {
|
for _, rs := range c.ResourceSets {
|
||||||
fmt.Fprintf(os.Stderr,"Loading resources for %s\n", rs.Name)
|
fmt.Fprintf(os.Stderr, "Loading resources for %s\n", rs.Name)
|
||||||
|
|
||||||
rp := path.Join(c.BaseDir, rs.Name)
|
rp := path.Join(c.BaseDir, rs.Name)
|
||||||
files, err := ioutil.ReadDir(rp)
|
files, err := ioutil.ReadDir(rp)
|
||||||
|
|
@ -40,7 +40,6 @@ func LoadAndPrepareTemplates(c *context.Context) ([]string, error) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if !file.IsDir() && isResourceFile(file) {
|
if !file.IsDir() && isResourceFile(file) {
|
||||||
p := path.Join(rp, file.Name())
|
p := path.Join(rp, file.Name())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue