Skip to content

Commit 8b3ced3

Browse files
Merge pull request #2849 from Nordix/devel/modernizer
🌱 Switch to modern constructs via modernizer
2 parents 3f567a2 + 82cf4cb commit 8b3ced3

File tree

13 files changed

+153
-167
lines changed

13 files changed

+153
-167
lines changed

baremetal/metal3data_manager.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ func renderNetworkData(m3dt *infrav1.Metal3DataTemplate,
956956
}
957957
var err error
958958

959-
networkData := map[string][]interface{}{}
959+
networkData := map[string][]any{}
960960

961961
networkData["links"], err = renderNetworkLinks(m3dt.Spec.NetworkData.Links, m3m, machine, bmh)
962962
if err != nil {
@@ -977,11 +977,11 @@ func renderNetworkData(m3dt *infrav1.Metal3DataTemplate,
977977
}
978978

979979
// renderNetworkServices renders the services.
980-
func renderNetworkServices(services infrav1.NetworkDataService, poolAddresses map[string]addressFromPool) ([]interface{}, error) {
981-
data := []interface{}{}
980+
func renderNetworkServices(services infrav1.NetworkDataService, poolAddresses map[string]addressFromPool) ([]any, error) {
981+
data := []any{}
982982

983983
for _, service := range services.DNS {
984-
data = append(data, map[string]interface{}{
984+
data = append(data, map[string]any{
985985
"type": "dns",
986986
"address": service,
987987
})
@@ -993,7 +993,7 @@ func renderNetworkServices(services infrav1.NetworkDataService, poolAddresses ma
993993
return nil, errors.New("Pool not found in cache")
994994
}
995995
for _, service := range poolAddress.dnsServers {
996-
data = append(data, map[string]interface{}{
996+
data = append(data, map[string]any{
997997
"type": "dns",
998998
"address": service,
999999
})
@@ -1005,16 +1005,16 @@ func renderNetworkServices(services infrav1.NetworkDataService, poolAddresses ma
10051005

10061006
// renderNetworkLinks renders the different types of links.
10071007
func renderNetworkLinks(networkLinks infrav1.NetworkDataLink,
1008-
m3m *infrav1.Metal3Machine, machine *clusterv1.Machine, bmh *bmov1alpha1.BareMetalHost) ([]interface{}, error) {
1009-
data := []interface{}{}
1008+
m3m *infrav1.Metal3Machine, machine *clusterv1.Machine, bmh *bmov1alpha1.BareMetalHost) ([]any, error) {
1009+
data := []any{}
10101010

10111011
// Bond links
10121012
for _, link := range networkLinks.Bonds {
10131013
macAddress, err := getLinkMacAddress(link.MACAddress, m3m, machine, bmh)
10141014
if err != nil {
10151015
return nil, err
10161016
}
1017-
entry := map[string]interface{}{
1017+
entry := map[string]any{
10181018
"type": "bond",
10191019
"id": link.Id,
10201020
"mtu": link.MTU,
@@ -1049,7 +1049,7 @@ func renderNetworkLinks(networkLinks infrav1.NetworkDataLink,
10491049
if err != nil {
10501050
return nil, err
10511051
}
1052-
data = append(data, map[string]interface{}{
1052+
data = append(data, map[string]any{
10531053
"type": link.Type,
10541054
"id": link.Id,
10551055
"mtu": link.MTU,
@@ -1063,7 +1063,7 @@ func renderNetworkLinks(networkLinks infrav1.NetworkDataLink,
10631063
if err != nil {
10641064
return nil, err
10651065
}
1066-
data = append(data, map[string]interface{}{
1066+
data = append(data, map[string]any{
10671067
"type": "vlan",
10681068
"id": link.Id,
10691069
"mtu": link.MTU,
@@ -1079,8 +1079,8 @@ func renderNetworkLinks(networkLinks infrav1.NetworkDataLink,
10791079
// renderNetworkNetworks renders the different types of network.
10801080
func renderNetworkNetworks(networks infrav1.NetworkDataNetwork,
10811081
poolAddresses map[string]addressFromPool,
1082-
) ([]interface{}, error) {
1083-
data := []interface{}{}
1082+
) ([]any, error) {
1083+
data := []any{}
10841084

10851085
// IPv4 networks static allocation
10861086
for _, network := range networks.IPv4 {
@@ -1100,7 +1100,7 @@ func renderNetworkNetworks(networks infrav1.NetworkDataNetwork,
11001100
if err != nil {
11011101
return nil, err
11021102
}
1103-
data = append(data, map[string]interface{}{
1103+
data = append(data, map[string]any{
11041104
"type": "ipv4",
11051105
"id": network.ID,
11061106
"link": network.Link,
@@ -1122,7 +1122,7 @@ func renderNetworkNetworks(networks infrav1.NetworkDataNetwork,
11221122
if err != nil {
11231123
return nil, err
11241124
}
1125-
data = append(data, map[string]interface{}{
1125+
data = append(data, map[string]any{
11261126
"type": "ipv6",
11271127
"id": network.ID,
11281128
"link": network.Link,
@@ -1138,7 +1138,7 @@ func renderNetworkNetworks(networks infrav1.NetworkDataNetwork,
11381138
if err != nil {
11391139
return nil, err
11401140
}
1141-
data = append(data, map[string]interface{}{
1141+
data = append(data, map[string]any{
11421142
"type": "ipv4_dhcp",
11431143
"id": network.ID,
11441144
"link": network.Link,
@@ -1152,7 +1152,7 @@ func renderNetworkNetworks(networks infrav1.NetworkDataNetwork,
11521152
if err != nil {
11531153
return nil, err
11541154
}
1155-
data = append(data, map[string]interface{}{
1155+
data = append(data, map[string]any{
11561156
"type": "ipv6_dhcp",
11571157
"id": network.ID,
11581158
"link": network.Link,
@@ -1166,7 +1166,7 @@ func renderNetworkNetworks(networks infrav1.NetworkDataNetwork,
11661166
if err != nil {
11671167
return nil, err
11681168
}
1169-
data = append(data, map[string]interface{}{
1169+
data = append(data, map[string]any{
11701170
"type": "ipv6_slaac",
11711171
"id": network.ID,
11721172
"link": network.Link,
@@ -1184,46 +1184,46 @@ func renderNetworkNetworks(networks infrav1.NetworkDataNetwork,
11841184
//nolint:dupl
11851185
func getRoutesv4(netRoutes []infrav1.NetworkDataRoutev4,
11861186
poolAddresses map[string]addressFromPool,
1187-
) ([]interface{}, error) {
1188-
routes := []interface{}{}
1187+
) ([]any, error) {
1188+
routes := []any{}
11891189
for _, route := range netRoutes {
11901190
gateway := ipamv1.IPAddressv4Str("")
11911191
if route.Gateway.String != nil {
11921192
gateway = *route.Gateway.String
11931193
} else if route.Gateway.FromPoolRef != nil && route.Gateway.FromPoolRef.Name != "" {
11941194
poolAddress, ok := poolAddresses[route.Gateway.FromPoolRef.Name]
11951195
if !ok {
1196-
return []interface{}{}, errors.New("Failed to fetch pool from cache")
1196+
return []any{}, errors.New("Failed to fetch pool from cache")
11971197
}
11981198
gateway = ipamv1.IPAddressv4Str(poolAddress.Gateway)
11991199
} else if route.Gateway.FromIPPool != nil {
12001200
poolAddress, ok := poolAddresses[*route.Gateway.FromIPPool]
12011201
if !ok {
1202-
return []interface{}{}, errors.New("Failed to fetch pool from cache")
1202+
return []any{}, errors.New("Failed to fetch pool from cache")
12031203
}
12041204
gateway = ipamv1.IPAddressv4Str(poolAddress.Gateway)
12051205
}
1206-
services := []interface{}{}
1206+
services := []any{}
12071207
for _, service := range route.Services.DNS {
1208-
services = append(services, map[string]interface{}{
1208+
services = append(services, map[string]any{
12091209
"type": "dns",
12101210
"address": service,
12111211
})
12121212
}
12131213
if route.Services.DNSFromIPPool != nil {
12141214
poolAddress, ok := poolAddresses[*route.Services.DNSFromIPPool]
12151215
if !ok {
1216-
return []interface{}{}, errors.New("Pool not found in cache")
1216+
return []any{}, errors.New("Pool not found in cache")
12171217
}
12181218
for _, service := range poolAddress.dnsServers {
1219-
services = append(services, map[string]interface{}{
1219+
services = append(services, map[string]any{
12201220
"type": "dns",
12211221
"address": service,
12221222
})
12231223
}
12241224
}
12251225
mask := translateMask(route.Prefix, true)
1226-
routes = append(routes, map[string]interface{}{
1226+
routes = append(routes, map[string]any{
12271227
"network": route.Network,
12281228
"netmask": mask,
12291229
"gateway": gateway,
@@ -1238,46 +1238,46 @@ func getRoutesv4(netRoutes []infrav1.NetworkDataRoutev4,
12381238
//nolint:dupl
12391239
func getRoutesv6(netRoutes []infrav1.NetworkDataRoutev6,
12401240
poolAddresses map[string]addressFromPool,
1241-
) ([]interface{}, error) {
1242-
routes := []interface{}{}
1241+
) ([]any, error) {
1242+
routes := []any{}
12431243
for _, route := range netRoutes {
12441244
gateway := ipamv1.IPAddressv6Str("")
12451245
if route.Gateway.String != nil {
12461246
gateway = *route.Gateway.String
12471247
} else if route.Gateway.FromPoolRef != nil && route.Gateway.FromPoolRef.Name != "" {
12481248
poolAddress, ok := poolAddresses[route.Gateway.FromPoolRef.Name]
12491249
if !ok {
1250-
return []interface{}{}, errors.New("Failed to fetch pool from cache")
1250+
return []any{}, errors.New("Failed to fetch pool from cache")
12511251
}
12521252
gateway = ipamv1.IPAddressv6Str(poolAddress.Gateway)
12531253
} else if route.Gateway.FromIPPool != nil {
12541254
poolAddress, ok := poolAddresses[*route.Gateway.FromIPPool]
12551255
if !ok {
1256-
return []interface{}{}, errors.New("Failed to fetch pool from cache")
1256+
return []any{}, errors.New("Failed to fetch pool from cache")
12571257
}
12581258
gateway = ipamv1.IPAddressv6Str(poolAddress.Gateway)
12591259
}
1260-
services := []interface{}{}
1260+
services := []any{}
12611261
for _, service := range route.Services.DNS {
1262-
services = append(services, map[string]interface{}{
1262+
services = append(services, map[string]any{
12631263
"type": "dns",
12641264
"address": service,
12651265
})
12661266
}
12671267
if route.Services.DNSFromIPPool != nil {
12681268
poolAddress, ok := poolAddresses[*route.Services.DNSFromIPPool]
12691269
if !ok {
1270-
return []interface{}{}, errors.New("Pool not found in cache")
1270+
return []any{}, errors.New("Pool not found in cache")
12711271
}
12721272
for _, service := range poolAddress.dnsServers {
1273-
services = append(services, map[string]interface{}{
1273+
services = append(services, map[string]any{
12741274
"type": "dns",
12751275
"address": service,
12761276
})
12771277
}
12781278
}
12791279
mask := translateMask(route.Prefix, false)
1280-
routes = append(routes, map[string]interface{}{
1280+
routes = append(routes, map[string]any{
12811281
"network": route.Network,
12821282
"netmask": mask,
12831283
"gateway": gateway,
@@ -1288,7 +1288,7 @@ func getRoutesv6(netRoutes []infrav1.NetworkDataRoutev6,
12881288
}
12891289

12901290
// translateMask transforms a mask given as integer into a dotted-notation string.
1291-
func translateMask(maskInt int, ipv4 bool) interface{} {
1291+
func translateMask(maskInt int, ipv4 bool) any {
12921292
IPv4MaskLen := 32
12931293
IPv6MaskLen := 128
12941294
if ipv4 {

0 commit comments

Comments
 (0)