Skip to content

Commit

Permalink
refactoring: Move the code generator
Browse files Browse the repository at this point in the history
which has been used for embedding config/templates/* files into go structs hence kube-aws binaries, from the config package to its own package, so that we can reuse it from the upcoming node pools feature.
  • Loading branch information
mumoshu committed Nov 28, 2016
1 parent 347f9de commit 0fdbb1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions config/templates_gen.go → codegen/templates_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"os"
"path/filepath"
"strings"
"text/template"
"time"
)
Expand All @@ -29,16 +30,9 @@ var (
)
`))

var files = []struct {
type Entry struct {
Filename string
VarName string
}{
{"cloud-config-controller", "CloudConfigController"},
{"cloud-config-worker", "CloudConfigWorker"},
{"cloud-config-etcd", "CloudConfigEtcd"},
{"cluster.yaml", "DefaultClusterConfig"},
{"kubeconfig.tmpl", "KubeConfigTemplate"},
{"stack-template.json", "StackTemplateTemplate"},
}

type Data struct {
Expand Down Expand Up @@ -69,6 +63,18 @@ func toGoByteSlice(sli []byte) string {
}

func main() {
files := []Entry{}
args := os.Args[1:]
for _, arg := range args {
parts := strings.Split(arg, "=")
varname, filename := parts[0], parts[1]
entry := Entry{
Filename: filename,
VarName: varname,
}
files = append(files, entry)
}

tmpls := make([]Var, len(files))
for i, file := range files {
path := filepath.Join("templates", file.Filename)
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package config

//go:generate go run templates_gen.go
//go:generate go run ../codegen/templates_gen.go CloudConfigController=cloud-config-controller CloudConfigWorker=cloud-config-worker CloudConfigEtcd=cloud-config-etcd DefaultClusterConfig=cluster.yaml KubeConfigTemplate=kubeconfig.tmpl StackTemplateTemplate=stack-template.json
//go:generate gofmt -w templates.go

import (
Expand Down

0 comments on commit 0fdbb1f

Please sign in to comment.