-
Notifications
You must be signed in to change notification settings - Fork 1
/
customizations_yaml.go
276 lines (257 loc) · 13.2 KB
/
customizations_yaml.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
MIT License
(C) Copyright 2022 Hewlett Packard Enterprise Development LP
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
package pit
import (
"fmt"
"net"
"regexp"
"strings"
"github.com/Cray-HPE/cray-site-init/pkg/csi"
valid "github.com/asaskevich/govalidator"
"github.com/spf13/viper"
)
// CustomizationsWLM is the struct for holding all WLM related values for customizations.yaml
type CustomizationsWLM struct {
WLMStaticIPs struct {
SlurmCtlD net.IP `yaml:"slurmctld" valid:"ipv4,required" desc:"The slurmCtlD IP address on the nmn, accessible from all UAIs,UANs, and Compute Nodes"`
SlurmDbd net.IP `yaml:"slurmdbd" valid:"ipv4,required" desc:"The slurmDbd IP address on the nmn, accessible from all UAIs,UANs, and Compute Nodes"`
Pbs net.IP `yaml:"pbs" valid:"ipv4,required" desc:"The PBS IP address on the nmn, accessible from all UAIs,UANs, and Compute Nodes"`
PbsComm net.IP `yaml:"pbs_comm" valid:"ipv4,required" desc:"The PBS Comm IP address on the nmn, accessible from all UAIs,UANs, and Compute Nodes"`
}
MacVlanSetup struct {
NMNSubnetCIDR string `yaml:"nmn_subnet" valid:"cidr,required"`
NMNSupernetCIDR string `yaml:"nmn_supernet" valid:"cidr,required"`
NMNSupernetGateway net.IP `yaml:"nmn_supernet_gateway" valid:"ipv4,required"`
NMNVlanInterface string `yaml:"nmn_vlan" valid:"_,required"`
NMNMacVlanReservationStart net.IP `yaml:"nmn_reservation_start" valid:"ipv4,required"`
NMNMacVlanReservationEnd net.IP `yaml:"nmn_reservation_end" valid:"ipv4,required"`
Routes []struct {
Destination string `yaml:"dst" valid:"cidr,required"`
Gateway string `yaml:"gw" valid:"cidr,required"`
}
}
}
// CustomizationsNetworking is the struct for holding all Networking related variables for use in customizations.yaml
type CustomizationsNetworking struct {
NMN string `yaml:"nmn" valid:"cidr,required"`
NMNLB string `yaml:"nmn_load_balancers" valid:"cidr,required"`
HMN string `yaml:"hmn" valid:"cidr,required"`
HMNLB string `yaml:"hmn_load_balancers" valid:"cidr,required"`
HSN string `yaml:"high_speed" valid:"cidr,required"`
NetStaticIps struct {
SiteToSystem net.IP `yaml:"site_to_system_lookups" valid:"ipv4,required"`
SystemToSite net.IP `yaml:"system_to_site_lookups" valid:"ipv4,required"`
NmnTftp net.IP `yaml:"nmn_tftp" valid:"ipv4,required"`
HmnTftp net.IP `yaml:"hmn_tftp" valid:"ipv4,required"`
NmnAPIGateway net.IP `yaml:"nmn_api_gw" valid:"ipv4,required"`
NmnUnbound net.IP `yaml:"nmn_unbound" valid:"ipv4,required"`
NmnAPIGatewayLocal net.IP `yaml:"nmn_api_gw_local" valid:"ipv4,required"`
HmnAPIGateway net.IP `yaml:"hmn_api_gw" valid:"ipv4,required"`
NcnMasters []net.IP `yaml:"nmn_ncn_masters" valid:"required"`
NcnStorage []net.IP `yaml:"nmn_ncn_storage" valid:"required"`
NcnStorageMons []net.IP `yaml:"nmn_ncn_storage_mons" valid:"required"`
}
DNS struct {
ExternalDomain string `yaml:"external" valid:"host,required"`
ExternalS3 string `yaml:"external_s3" valid:"required,host"`
ExternalAuth string `yaml:"external_auth" valid:"required,host"`
ExternalAPI string `yaml:"external_api" valid:"required,host"`
InternalS3 string `yaml:"internal_s3" valid:"required,host"`
InternalAPI string `yaml:"internal_api" valid:"required,host"`
PrimaryServerName string `yaml:"primary_server_name" valid:"required,host"`
SecondaryServers string `yaml:"secondary_servers" valid:"required,host"`
NotifyZones string `yaml:"notify_zones" valid:"required,host"`
}
MetalLB struct {
Peers []PeerDetail `yaml:"peers"`
AddressPools []AddressPoolDetail `yaml:"address-pools"`
}
}
// CustomizationsYaml is the golang representation of the customizations.yaml stanza we generate
type CustomizationsYaml struct {
Networking CustomizationsNetworking `yaml:"network"`
WLM CustomizationsWLM `yaml:"wlm"`
}
// ValidationErrors uses govalidator and struct tags to validate and returns errors
func (c *CustomizationsYaml) ValidationErrors() error {
_, err := valid.ValidateStruct(c)
return err
}
// IsValid uses govalidator and struct tags to validate and returns a boolean
func (c *CustomizationsYaml) IsValid() bool {
result, _ := valid.ValidateStruct(c)
return result
}
// GenCustomizationsYaml generates our configurations.yaml nested struct
func GenCustomizationsYaml(ncns []csi.LogicalNCN, shastaNetworks map[string]*csi.IPV4Network, switches []*csi.ManagementSwitch) CustomizationsYaml {
v := viper.GetViper()
systemName := v.GetString("system-name")
siteDomain := v.GetString("site-domain")
var output CustomizationsYaml
var metallb MetalLBConfigMap
// nmnMacvlanSubnet, _ := shastaNetworks["NMN"].LookUpSubnet("uai_macvlan")
var masters []net.IP
var storage []net.IP
var storageMons []net.IP
//
// Only the first three storage nodes run ceph mgr daemon, so
// we need to have a separate list when passing list of IPs
// to the sysmgmt-health chart for the cephExporter endpoint
// list (CASMPET-5428).
//
monRegEx := regexp.MustCompile("ncn-s00([1-3])")
for _, ncn := range ncns {
if ncn.Subrole == "Storage" {
storage = append(storage, ncn.GetIP("NMN"))
if monRegEx.Match([]byte(ncn.Hostname)) {
storageMons = append(storageMons, ncn.GetIP("NMN"))
}
}
if ncn.Subrole == "Master" {
masters = append(masters, ncn.GetIP("NMN"))
}
}
metallb = GetMetalLBConfig(v, shastaNetworks, switches)
nmnLBs, _ := shastaNetworks["NMNLB"].LookUpSubnet("nmn_metallb_address_pool")
hmnLBs, _ := shastaNetworks["HMNLB"].LookUpSubnet("hmn_metallb_address_pool")
uaiNet, _ := shastaNetworks["NMN"].LookUpSubnet("uai_macvlan")
cmnStaticNet, _ := shastaNetworks["CMN"].LookUpSubnet("cmn_metallb_static_pool")
// Normalize the CIDR before using it
_, uaiNetCIDR, _ := net.ParseCIDR(uaiNet.CIDR.String())
var customizationsNetworks = CustomizationsNetworking{
NMN: shastaNetworks["NMN"].CIDR,
NMNLB: shastaNetworks["NMNLB"].CIDR,
HMN: shastaNetworks["HMN"].CIDR,
HMNLB: shastaNetworks["HMNLB"].CIDR,
HSN: shastaNetworks["HSN"].CIDR,
NetStaticIps: struct {
SiteToSystem net.IP "yaml:\"site_to_system_lookups\" valid:\"ipv4,required\""
SystemToSite net.IP "yaml:\"system_to_site_lookups\" valid:\"ipv4,required\""
NmnTftp net.IP "yaml:\"nmn_tftp\" valid:\"ipv4,required\""
HmnTftp net.IP "yaml:\"hmn_tftp\" valid:\"ipv4,required\""
NmnAPIGateway net.IP "yaml:\"nmn_api_gw\" valid:\"ipv4,required\""
NmnUnbound net.IP "yaml:\"nmn_unbound\" valid:\"ipv4,required\""
NmnAPIGatewayLocal net.IP "yaml:\"nmn_api_gw_local\" valid:\"ipv4,required\""
HmnAPIGateway net.IP "yaml:\"hmn_api_gw\" valid:\"ipv4,required\""
NcnMasters []net.IP "yaml:\"nmn_ncn_masters\" valid:\"required\""
NcnStorage []net.IP "yaml:\"nmn_ncn_storage\" valid:\"required\""
NcnStorageMons []net.IP "yaml:\"nmn_ncn_storage_mons\" valid:\"required\""
}{
SiteToSystem: cmnStaticNet.LookupReservation("external-dns").IPAddress,
SystemToSite: net.ParseIP(strings.Split(v.GetString("site-dns"), ",")[0]),
NmnTftp: nmnLBs.LookupReservation("cray-tftp").IPAddress,
HmnTftp: hmnLBs.LookupReservation("cray-tftp").IPAddress,
NmnAPIGateway: nmnLBs.LookupReservation("istio-ingressgateway").IPAddress,
NmnUnbound: nmnLBs.LookupReservation("unbound").IPAddress,
NmnAPIGatewayLocal: nmnLBs.LookupReservation("istio-ingressgateway-local").IPAddress,
HmnAPIGateway: hmnLBs.LookupReservation("istio-ingressgateway").IPAddress,
NcnMasters: masters,
NcnStorage: storage,
NcnStorageMons: storageMons,
},
DNS: struct {
ExternalDomain string "yaml:\"external\" valid:\"host,required\""
ExternalS3 string "yaml:\"external_s3\" valid:\"required,host\""
ExternalAuth string "yaml:\"external_auth\" valid:\"required,host\""
ExternalAPI string "yaml:\"external_api\" valid:\"required,host\""
InternalS3 string "yaml:\"internal_s3\" valid:\"required,host\""
InternalAPI string "yaml:\"internal_api\" valid:\"required,host\""
PrimaryServerName string `yaml:"primary_server_name" valid:"required,host"`
SecondaryServers string `yaml:"secondary_servers" valid:"required,host"`
NotifyZones string `yaml:"notify_zones" valid:"required,host"`
}{
ExternalDomain: strings.ToLower(fmt.Sprintf("%s.%s", systemName, siteDomain)),
ExternalS3: strings.ToLower(fmt.Sprintf("s3.%s.%s", systemName, siteDomain)),
ExternalAuth: strings.ToLower(fmt.Sprintf("auth.%s.%s", systemName, siteDomain)),
ExternalAPI: strings.ToLower(fmt.Sprintf("api.%s.%s", systemName, siteDomain)),
InternalS3: "rgw-vip.nmn",
InternalAPI: "api-gw-service-nmn.local",
PrimaryServerName: v.GetString("primary-server-name"),
SecondaryServers: v.GetString("secondary-servers"),
NotifyZones: v.GetString("notify-zones"),
},
MetalLB: struct {
Peers []PeerDetail "yaml:\"peers\""
AddressPools []AddressPoolDetail "yaml:\"address-pools\""
}{
Peers: metallb.PeerSwitches,
AddressPools: metallb.Networks,
},
}
output.Networking = customizationsNetworks
output.WLM = CustomizationsWLM{
WLMStaticIPs: struct {
SlurmCtlD net.IP "yaml:\"slurmctld\" valid:\"ipv4,required\" desc:\"The slurmCtlD IP address on the nmn, accessible from all UAIs,UANs, and Compute Nodes\""
SlurmDbd net.IP "yaml:\"slurmdbd\" valid:\"ipv4,required\" desc:\"The slurmDbd IP address on the nmn, accessible from all UAIs,UANs, and Compute Nodes\""
Pbs net.IP "yaml:\"pbs\" valid:\"ipv4,required\" desc:\"The PBS IP address on the nmn, accessible from all UAIs,UANs, and Compute Nodes\""
PbsComm net.IP "yaml:\"pbs_comm\" valid:\"ipv4,required\" desc:\"The PBS Comm IP address on the nmn, accessible from all UAIs,UANs, and Compute Nodes\""
}{
SlurmCtlD: uaiNet.LookupReservation("slurmctld_service").IPAddress,
SlurmDbd: uaiNet.LookupReservation("slurmdbd_service").IPAddress,
Pbs: uaiNet.LookupReservation("pbs_service").IPAddress,
PbsComm: uaiNet.LookupReservation("pbs_comm_service").IPAddress,
},
MacVlanSetup: struct {
NMNSubnetCIDR string "yaml:\"nmn_subnet\" valid:\"cidr,required\""
NMNSupernetCIDR string "yaml:\"nmn_supernet\" valid:\"cidr,required\""
NMNSupernetGateway net.IP "yaml:\"nmn_supernet_gateway\" valid:\"ipv4,required\""
NMNVlanInterface string "yaml:\"nmn_vlan\" valid:\"_,required\""
NMNMacVlanReservationStart net.IP "yaml:\"nmn_reservation_start\" valid:\"ipv4,required\""
NMNMacVlanReservationEnd net.IP "yaml:\"nmn_reservation_end\" valid:\"ipv4,required\""
Routes []struct {
Destination string "yaml:\"dst\" valid:\"cidr,required\""
Gateway string "yaml:\"gw\" valid:\"cidr,required\""
}
}{
NMNSubnetCIDR: uaiNetCIDR.String(),
NMNSupernetGateway: uaiNet.Gateway,
NMNSupernetCIDR: shastaNetworks["NMN"].CIDR,
NMNVlanInterface: "bond0.nmn0",
NMNMacVlanReservationStart: uaiNet.ReservationStart,
NMNMacVlanReservationEnd: uaiNet.ReservationEnd,
},
}
for netName, network := range shastaNetworks {
if netName == "NMNLB" || netName == "HMN" || netName == "HMNLB" {
output.WLM.MacVlanSetup.Routes = append(output.WLM.MacVlanSetup.Routes, struct {
Destination string "yaml:\"dst\" valid:\"cidr,required\""
Gateway string "yaml:\"gw\" valid:\"cidr,required\""
}{
Destination: network.CIDR,
Gateway: uaiNet.LookupReservation("uai_nmn_blackhole").IPAddress.String(),
})
} else if netName == "NMN_RVR" || netName == "NMN_MTN" || netName == "CMN" {
output.WLM.MacVlanSetup.Routes = append(output.WLM.MacVlanSetup.Routes, struct {
Destination string "yaml:\"dst\" valid:\"cidr,required\""
Gateway string "yaml:\"gw\" valid:\"cidr,required\""
}{
Destination: network.CIDR,
Gateway: uaiNet.Gateway.String(),
})
}
}
return output
}
func init() {
valid.TagMap["cidr"] = valid.Validator(func(str string) bool {
_, _, err := net.ParseCIDR(str)
return err == nil
})
}