This repository has been archived by the owner on Sep 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 295
/
config.go
89 lines (73 loc) · 2.03 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package config
//go:generate go run ../../../codegen/templates_gen.go StackTemplateTemplate=stack-template.json
//go:generate gofmt -w templates.go
import (
"fmt"
controlplane "github.com/coreos/kube-aws/core/controlplane/config"
nodepool "github.com/coreos/kube-aws/core/nodepool/config"
"gopkg.in/yaml.v2"
"io/ioutil"
)
type UnmarshalledConfig struct {
controlplane.Cluster `yaml:",inline"`
WorkerConfig `yaml:"worker,omitempty"`
}
type WorkerConfig struct {
NodePools []*nodepool.ProvidedConfig `yaml:"nodePools,omitempty"`
}
type Config struct {
*controlplane.Cluster
NodePools []*nodepool.ProvidedConfig
}
func newDefaultUnmarshalledConfig() *UnmarshalledConfig {
return &UnmarshalledConfig{
Cluster: *controlplane.NewDefaultCluster(),
WorkerConfig: WorkerConfig{
NodePools: []*nodepool.ProvidedConfig{},
},
}
}
func ConfigFromBytes(data []byte) (*Config, error) {
c := newDefaultUnmarshalledConfig()
if err := yaml.Unmarshal(data, c); err != nil {
return nil, fmt.Errorf("failed to parse config: %v", err)
}
c.HyperkubeImage.Tag = c.K8sVer
cpCluser := &c.Cluster
if err := cpCluser.Load(); err != nil {
return nil, err
}
cpConfig, err := cpCluser.Config()
if err != nil {
return nil, err
}
nodePools := c.NodePools
for i, np := range nodePools {
if err := np.Load(cpConfig); err != nil {
return nil, fmt.Errorf("invalid node pool at index %d: %v", i, err)
}
}
return &Config{Cluster: cpCluser, NodePools: nodePools}, nil
}
func ConfigFromBytesWithEncryptService(data []byte, encryptService controlplane.EncryptService) (*Config, error) {
c, err := ConfigFromBytes(data)
if err != nil {
return nil, err
}
c.ProvidedEncryptService = encryptService
return c, nil
}
func ConfigFromFile(configPath string) (*Config, error) {
data, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, err
}
c, err := ConfigFromBytes(data)
if err != nil {
return nil, fmt.Errorf("file %s: %v", configPath, err)
}
return c, nil
}
func (c *Config) RootStackName() string {
return c.ClusterName
}