diff --git a/clustersconfig/clustersconfig.go b/clustersconfig/clustersconfig.go index df013d8..f84c11a 100644 --- a/clustersconfig/clustersconfig.go +++ b/clustersconfig/clustersconfig.go @@ -16,13 +16,14 @@ type Config struct { Groups []*Group Clusters []*Cluster Configs []*Template - StaticPods []*Template `yaml:"static_pods"` + StaticPods []*Template `yaml:"static_pods"` + Addons map[string][]*Template SSLConfig string `yaml:"ssl_config"` CertRequests []*CertRequest `yaml:"cert_requests"` } func FromBytes(data []byte) (*Config, error) { - config := &Config{} + config := &Config{Addons: make(map[string][]*Template)} if err := yaml.Unmarshal(data, config); err != nil { return nil, err } @@ -192,6 +193,7 @@ type Vars map[string]interface{} type Cluster struct { Name string Domain string + Addons string Subnets struct { Services string Pods string diff --git a/clustersconfig/dir.go b/clustersconfig/dir.go index 8049065..06a643d 100644 --- a/clustersconfig/dir.go +++ b/clustersconfig/dir.go @@ -11,7 +11,7 @@ import ( ) func FromDir(dirPath string) (*Config, error) { - config := &Config{} + config := &Config{Addons: make(map[string][]*Template)} store := dirStore{dirPath} load := func(dir, name string, out interface{}) error { @@ -95,6 +95,23 @@ func FromDir(dirPath string) (*Config, error) { return nil, err } + { + addonSets, err := store.listDir("addons") + if err != nil { + return nil, err + } + + for _, addonSet := range addonSets { + templates := make([]*Template, 0) + if err = loadTemplates(path.Join("addons", addonSet), &templates); err != nil { + return nil, err + } + + config.Addons[addonSet] = templates + } + } + + // load SSL configuration if ba, err := ioutil.ReadFile(filepath.Join(dirPath, "ssl-config.json")); err == nil { config.SSLConfig = string(ba) @@ -121,6 +138,32 @@ type dirStore struct { path string } +// listDir +func (b *dirStore) listDir(prefix string) (subDirs []string, err error) { + entries, err := ioutil.ReadDir(filepath.Join(b.path, prefix)) + if err != nil { + return + } + + subDirs = make([]string, 0, len(entries)) + + for _, entry := range entries { + if !entry.IsDir() { + continue + } + + name := entry.Name() + + if len(name) == 0 || name[0] == '.' { + continue + } + + subDirs = append(subDirs, name) + } + + return +} + // Names is part of the kvStore interface func (b *dirStore) List(prefix string) ([]string, error) { files, err := filepath.Glob(filepath.Join(b.path, filepath.Join(path.Split(prefix)), "*.yaml"))