forked from elastic/cloud-on-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
136 lines (117 loc) · 4.43 KB
/
settings.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
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.
package runner
import (
"os"
"gopkg.in/yaml.v3"
"github.com/elastic/cloud-on-k8s/v2/hack/deployer/vault"
)
// Plans encapsulates list of plans, expected to map to a file
type Plans struct {
Plans []Plan
}
// Plan encapsulates information needed to provision a cluster
type Plan struct {
Id string `yaml:"id"` //nolint:revive
Operation string `yaml:"operation"`
ClusterName string `yaml:"clusterName"`
ClientVersion string `yaml:"clientVersion"`
ClientBuildDefDir string `yaml:"clientBuildDefDir"`
Provider string `yaml:"provider"`
KubernetesVersion string `yaml:"kubernetesVersion"`
MachineType string `yaml:"machineType"`
// Abbreviations not all-caps to allow merging with mergo in `merge` as mergo does not understand struct tags and
// we use lowercase in the YAML
Gke *GKESettings `yaml:"gke,omitempty"`
Aks *AKSSettings `yaml:"aks,omitempty"`
Ocp *OCPSettings `yaml:"ocp,omitempty"`
Ocp3 *OCP3Settings `yaml:"ocp3,omitempty"`
Eks *EKSSettings `yaml:"eks,omitempty"`
Kind *KindSettings `yaml:"kind,omitempty"`
Tanzu *TanzuSettings `yaml:"tanzu,omitempty"`
VaultInfo vault.Info `yaml:"vaultInfo,omitempty"`
ServiceAccount bool `yaml:"serviceAccount"`
EnforceSecurityPolicies bool `yaml:"enforceSecurityPolicies"`
DiskSetup string `yaml:"diskSetup"`
}
// GKESettings encapsulates settings specific to GKE
type GKESettings struct {
GCloudProject string `yaml:"gCloudProject"`
Region string `yaml:"region"`
LocalSsdCount int `yaml:"localSsdCount"`
NodeCountPerZone int `yaml:"nodeCountPerZone"`
GcpScopes string `yaml:"gcpScopes"`
ClusterIPv4CIDR string `yaml:"clusterIpv4Cidr"`
ServicesIPv4CIDR string `yaml:"servicesIpv4Cidr"`
Private bool `yaml:"private"`
NetworkPolicy bool `yaml:"networkPolicy"`
}
// AKSSettings encapsulates settings specific to AKS
type AKSSettings struct {
ResourceGroup string `yaml:"resourceGroup"`
Location string `yaml:"location"`
Zones string `yaml:"zones"`
NodeCount int `yaml:"nodeCount"`
}
// OCPSettings encapsulates settings specific to OCP on GCloud
type OCPSettings struct {
BaseDomain string `yaml:"baseDomain"`
GCloudProject string `yaml:"gCloudProject"`
Region string `yaml:"region"`
AdminUsername string `yaml:"adminUsername"`
WorkDir string `yaml:"workDir"`
StickyWorkDir bool `yaml:"stickyWorkDir"`
PullSecret string `yaml:"pullSecret"`
LocalSsdCount int `yaml:"localSsdCount"`
NodeCount int `yaml:"nodeCount"`
}
// OCP3Settings encapsulates settings specific to Ocp3 on GCloud
type OCP3Settings struct {
GCloudProject string `yaml:"gCloudProject"`
WorkerCount int `yaml:"workerCount"`
}
// EKSSettings are specific to Amazon EKS.
type EKSSettings struct {
NodeAMI string `yaml:"nodeAMI"`
NodeCount int `yaml:"nodeCount"`
Region string `yaml:"region"`
WorkDir string `yaml:"workDir"`
}
type KindSettings struct {
NodeCount int `yaml:"nodeCount"`
NodeImage string `yaml:"nodeImage"`
IPFamily string `yaml:"ipFamily"`
}
type TanzuSettings struct {
AKSSettings `yaml:",inline"`
InstallerImage string `yaml:"installerImage"`
WorkDir string `yaml:"workDir"`
SSHPubKey string `yaml:"sshPubKey"`
}
// RunConfig encapsulates Id used to choose a plan and a map of overrides to apply to the plan, expected to map to a file
type RunConfig struct {
Id string `yaml:"id"` //nolint:revive
Overrides map[string]interface{} `yaml:"overrides"`
}
func ParseFiles(plansFile, runConfigFile string) (Plans, RunConfig, error) {
yml, err := os.ReadFile(plansFile)
if err != nil {
return Plans{}, RunConfig{}, err
}
var plans Plans
err = yaml.Unmarshal(yml, &plans)
if err != nil {
return Plans{}, RunConfig{}, err
}
yml, err = os.ReadFile(runConfigFile)
if err != nil {
return Plans{}, RunConfig{}, err
}
var runConfig RunConfig
err = yaml.Unmarshal(yml, &runConfig)
if err != nil {
return Plans{}, RunConfig{}, err
}
return plans, runConfig, nil
}