This repository has been archived by the owner on Sep 30, 2020. It is now read-only.
/
compiler.go
138 lines (115 loc) · 4.21 KB
/
compiler.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package model
import (
"fmt"
"strings"
"github.com/kubernetes-incubator/kube-aws/flatcar/amiregistry"
"github.com/kubernetes-incubator/kube-aws/pkg/api"
"github.com/pkg/errors"
)
func Compile(cfgRef *api.Cluster, opts api.ClusterOptions) (*Config, error) {
c := &api.Cluster{}
*c = *cfgRef
c.SetDefaults()
config := Config{
Cluster: c,
APIServerFlags: api.CommandLineFlags{},
APIServerVolumes: api.APIServerVolumes{},
ControllerFlags: api.CommandLineFlags{},
KubeSchedulerFlags: api.CommandLineFlags{},
}
if c.AmiId == "" {
var err error
if config.AMI, err = amiregistry.GetAMI(config.Region.String(), config.ReleaseChannel); err != nil {
return nil, errors.Wrapf(err, "failed getting AMI for config: %v", err)
}
} else {
config.AMI = c.AmiId
}
var err error
config.EtcdNodes, err = NewEtcdNodes(c.Etcd.Nodes, config.EtcdCluster())
if err != nil {
return nil, fmt.Errorf("failed to derived etcd nodes configuration: %v", err)
}
// Populate top-level subnets to model
if len(config.Subnets) > 0 {
if config.Controller.MinControllerCount() > 0 && len(config.Controller.Subnets) == 0 {
config.Controller.Subnets = config.Subnets
}
}
apiEndpoints, err := NewAPIEndpoints(c.APIEndpointConfigs, c.Subnets)
if err != nil {
return nil, fmt.Errorf("invalid cluster: %v", err)
}
config.APIEndpoints = apiEndpoints
apiEndpointNames := []string{}
for _, e := range apiEndpoints {
apiEndpointNames = append(apiEndpointNames, e.Name)
}
var adminAPIEndpoint APIEndpoint
if c.AdminAPIEndpointName != "" {
found, err := apiEndpoints.FindByName(c.AdminAPIEndpointName)
if err != nil {
return nil, fmt.Errorf("failed to find an API endpoint named \"%s\": %v", c.AdminAPIEndpointName, err)
}
adminAPIEndpoint = *found
} else {
if len(apiEndpoints) > 1 {
return nil, fmt.Errorf(
"adminAPIEndpointName must not be empty when there's 2 or more api endpoints under the key `apiEndpoints`. Specify one of: %s",
strings.Join(apiEndpointNames, ", "),
)
}
adminAPIEndpoint = apiEndpoints.GetDefault()
}
config.AdminAPIEndpoint = adminAPIEndpoint
if opts.S3URI != "" {
c.S3URI = strings.TrimSuffix(opts.S3URI, "/")
}
s3Folders := api.NewS3Folders(c.S3URI, c.ClusterName)
//conf.S3URI = s3Folders.ClusterExportedStacks().URI()
c.KubeResourcesAutosave.S3Path = s3Folders.ClusterBackups().Path()
if opts.SkipWait {
enabled := false
c.WaitSignal.EnabledOverride = &enabled
}
nodePools := c.NodePools
anyNodePoolIsMissingAPIEndpointName := true
for _, np := range nodePools {
if np.APIEndpointName == "" {
anyNodePoolIsMissingAPIEndpointName = true
break
}
}
if len(config.APIEndpoints) > 1 && c.Worker.APIEndpointName == "" && anyNodePoolIsMissingAPIEndpointName {
return nil, errors.New("worker.apiEndpointName must not be empty when there're 2 or more API endpoints under the key `apiEndpoints` and one of worker.nodePools[] are missing apiEndpointName")
}
if c.Worker.APIEndpointName != "" {
if _, err := config.APIEndpoints.FindByName(c.APIEndpointName); err != nil {
return nil, fmt.Errorf("invalid value for worker.apiEndpointName: no API endpoint named \"%s\" found", c.APIEndpointName)
}
}
for i, np := range config.Worker.NodePools {
if err := np.Taints.Validate(); err != nil {
return nil, fmt.Errorf("invalid taints for node pool at index %d: %v", i, err)
}
if np.APIEndpointName == "" {
if c.Worker.APIEndpointName == "" {
if len(config.APIEndpoints) > 1 {
return nil, errors.New("worker.apiEndpointName can be omitted only when there's only 1 api endpoint under apiEndpoints")
}
np.APIEndpointName = config.APIEndpoints.GetDefault().Name
} else {
np.APIEndpointName = c.Worker.APIEndpointName
}
}
if np.NodePoolRollingStrategy != "Parallel" && np.NodePoolRollingStrategy != "Sequential" && np.NodePoolRollingStrategy != "AvailabilityZone" {
if c.Worker.NodePoolRollingStrategy == "Sequential" || c.Worker.NodePoolRollingStrategy == "Parallel" || c.Worker.NodePoolRollingStrategy == "AvailabilityZone" {
np.NodePoolRollingStrategy = c.Worker.NodePoolRollingStrategy
} else {
np.NodePoolRollingStrategy = "AvailabilityZone"
}
}
config.Worker.NodePools[i] = np
}
return &config, nil
}