forked from elastic/cloud-on-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.go
119 lines (103 loc) · 3.85 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
// 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"
)
// 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"`
Eks *EKSSettings `yaml:"eks,omitempty"`
Kind *KindSettings `yaml:"kind,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"`
Autopilot bool `yaml:"autopilot"`
}
// 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"`
}
// 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"`
}
// 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
}