feat: addons

This commit is contained in:
Mikaël Cluseau 2018-07-07 12:15:28 +11:00
parent 852aa03280
commit e82b59c032
2 changed files with 48 additions and 3 deletions

View File

@ -17,12 +17,13 @@ type Config struct {
Clusters []*Cluster Clusters []*Cluster
Configs []*Template Configs []*Template
StaticPods []*Template `yaml:"static_pods"` StaticPods []*Template `yaml:"static_pods"`
Addons map[string][]*Template
SSLConfig string `yaml:"ssl_config"` SSLConfig string `yaml:"ssl_config"`
CertRequests []*CertRequest `yaml:"cert_requests"` CertRequests []*CertRequest `yaml:"cert_requests"`
} }
func FromBytes(data []byte) (*Config, error) { func FromBytes(data []byte) (*Config, error) {
config := &Config{} config := &Config{Addons: make(map[string][]*Template)}
if err := yaml.Unmarshal(data, config); err != nil { if err := yaml.Unmarshal(data, config); err != nil {
return nil, err return nil, err
} }
@ -192,6 +193,7 @@ type Vars map[string]interface{}
type Cluster struct { type Cluster struct {
Name string Name string
Domain string Domain string
Addons string
Subnets struct { Subnets struct {
Services string Services string
Pods string Pods string

View File

@ -11,7 +11,7 @@ import (
) )
func FromDir(dirPath string) (*Config, error) { func FromDir(dirPath string) (*Config, error) {
config := &Config{} config := &Config{Addons: make(map[string][]*Template)}
store := dirStore{dirPath} store := dirStore{dirPath}
load := func(dir, name string, out interface{}) error { load := func(dir, name string, out interface{}) error {
@ -95,6 +95,23 @@ func FromDir(dirPath string) (*Config, error) {
return nil, err 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 { if ba, err := ioutil.ReadFile(filepath.Join(dirPath, "ssl-config.json")); err == nil {
config.SSLConfig = string(ba) config.SSLConfig = string(ba)
@ -121,6 +138,32 @@ type dirStore struct {
path string 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 // Names is part of the kvStore interface
func (b *dirStore) List(prefix string) ([]string, error) { func (b *dirStore) List(prefix string) ([]string, error) {
files, err := filepath.Glob(filepath.Join(b.path, filepath.Join(path.Split(prefix)), "*.yaml")) files, err := filepath.Glob(filepath.Join(b.path, filepath.Join(path.Split(prefix)), "*.yaml"))