Skip to content

Commit b42660b

Browse files
committed
OPNET-357: Populate network configuration at install-time
1 parent 8032847 commit b42660b

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

pkg/asset/manifests/infrastructure.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,18 @@ func (i *Infrastructure) Generate(dependencies asset.Parents) error {
158158
}
159159
case baremetal.Name:
160160
config.Spec.PlatformSpec.Type = configv1.BareMetalPlatformType
161+
config.Spec.PlatformSpec.BareMetal = &configv1.BareMetalPlatformSpec{}
161162
config.Status.PlatformStatus.BareMetal = &configv1.BareMetalPlatformStatus{
162163
APIServerInternalIP: installConfig.Config.Platform.BareMetal.APIVIPs[0],
163164
IngressIP: installConfig.Config.Platform.BareMetal.IngressVIPs[0],
164165
APIServerInternalIPs: installConfig.Config.Platform.BareMetal.APIVIPs,
165166
IngressIPs: installConfig.Config.Platform.BareMetal.IngressVIPs,
166167
LoadBalancer: installConfig.Config.Platform.BareMetal.LoadBalancer,
167168
}
169+
config.Spec.PlatformSpec.BareMetal.APIServerInternalIPs = types.StringsToIPs(installConfig.Config.Platform.BareMetal.APIVIPs)
170+
config.Spec.PlatformSpec.BareMetal.IngressIPs = types.StringsToIPs(installConfig.Config.Platform.BareMetal.IngressVIPs)
171+
config.Spec.PlatformSpec.BareMetal.MachineNetworks = types.MachineNetworksToCIDRs(installConfig.Config.MachineNetwork)
172+
config.Status.PlatformStatus.BareMetal.MachineNetworks = types.MachineNetworksToCIDRs(installConfig.Config.MachineNetwork)
168173
case gcp.Name:
169174
config.Spec.PlatformSpec.Type = configv1.GCPPlatformType
170175
config.Status.PlatformStatus.GCP = &configv1.GCPPlatformStatus{
@@ -228,15 +233,21 @@ func (i *Infrastructure) Generate(dependencies asset.Parents) error {
228233
config.Spec.PlatformSpec.Type = configv1.NonePlatformType
229234
case openstack.Name:
230235
config.Spec.PlatformSpec.Type = configv1.OpenStackPlatformType
236+
config.Spec.PlatformSpec.OpenStack = &configv1.OpenStackPlatformSpec{}
231237
config.Status.PlatformStatus.OpenStack = &configv1.OpenStackPlatformStatus{
232238
APIServerInternalIP: installConfig.Config.OpenStack.APIVIPs[0],
233239
IngressIP: installConfig.Config.OpenStack.IngressVIPs[0],
234240
APIServerInternalIPs: installConfig.Config.OpenStack.APIVIPs,
235241
IngressIPs: installConfig.Config.OpenStack.IngressVIPs,
236242
LoadBalancer: installConfig.Config.OpenStack.LoadBalancer,
237243
}
244+
config.Spec.PlatformSpec.OpenStack.APIServerInternalIPs = types.StringsToIPs(installConfig.Config.Platform.OpenStack.APIVIPs)
245+
config.Spec.PlatformSpec.OpenStack.IngressIPs = types.StringsToIPs(installConfig.Config.Platform.OpenStack.IngressVIPs)
246+
config.Spec.PlatformSpec.OpenStack.MachineNetworks = types.MachineNetworksToCIDRs(installConfig.Config.MachineNetwork)
247+
config.Status.PlatformStatus.OpenStack.MachineNetworks = types.MachineNetworksToCIDRs(installConfig.Config.MachineNetwork)
238248
case vsphere.Name:
239249
config.Spec.PlatformSpec.Type = configv1.VSpherePlatformType
250+
config.Spec.PlatformSpec.VSphere = &configv1.VSpherePlatformSpec{}
240251
if len(installConfig.Config.VSphere.APIVIPs) > 0 {
241252
config.Status.PlatformStatus.VSphere = &configv1.VSpherePlatformStatus{
242253
APIServerInternalIP: installConfig.Config.VSphere.APIVIPs[0],
@@ -245,6 +256,8 @@ func (i *Infrastructure) Generate(dependencies asset.Parents) error {
245256
IngressIPs: installConfig.Config.VSphere.IngressVIPs,
246257
LoadBalancer: installConfig.Config.VSphere.LoadBalancer,
247258
}
259+
} else {
260+
config.Status.PlatformStatus.VSphere = &configv1.VSpherePlatformStatus{}
248261
}
249262

250263
config.Spec.PlatformSpec.VSphere = vsphereinfra.GetInfraPlatformSpec(installConfig)
@@ -253,6 +266,7 @@ func (i *Infrastructure) Generate(dependencies asset.Parents) error {
253266
cloudProviderConfigMapKey = "vsphere.conf"
254267
}
255268

269+
config.Status.PlatformStatus.VSphere.MachineNetworks = types.MachineNetworksToCIDRs(installConfig.Config.MachineNetwork)
256270
case ovirt.Name:
257271
config.Spec.PlatformSpec.Type = configv1.OvirtPlatformType
258272
config.Status.PlatformStatus.Ovirt = &configv1.OvirtPlatformStatus{

pkg/asset/manifests/vsphere/infrastructure.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package vsphere
33
import (
44
configv1 "github.com/openshift/api/config/v1"
55
"github.com/openshift/installer/pkg/asset/installconfig"
6+
"github.com/openshift/installer/pkg/types"
67
)
78

89
// GetInfraPlatformSpec constructs VSpherePlatformSpec for the infrastructure spec
@@ -37,5 +38,10 @@ func GetInfraPlatformSpec(ic *installconfig.InstallConfig) *configv1.VSpherePlat
3738
})
3839
}
3940
}
41+
42+
platformSpec.APIServerInternalIPs = types.StringsToIPs(icPlatformSpec.APIVIPs)
43+
platformSpec.IngressIPs = types.StringsToIPs(icPlatformSpec.IngressVIPs)
44+
platformSpec.MachineNetworks = types.MachineNetworksToCIDRs(ic.Config.MachineNetwork)
45+
4046
return &platformSpec
4147
}

pkg/types/utils.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package types
2+
3+
import configv1 "github.com/openshift/api/config/v1"
4+
5+
// StringsToIPs is used to convert list of strings to list of IP addresses.
6+
func StringsToIPs(ips []string) []configv1.IP {
7+
res := []configv1.IP{}
8+
9+
if ips == nil {
10+
return res
11+
}
12+
13+
for _, ip := range ips {
14+
res = append(res, configv1.IP(ip))
15+
}
16+
17+
return res
18+
}
19+
20+
// MachineNetworksToCIDRs is used to convert list of Machine Network Entries to
21+
// list of CIDRs.
22+
func MachineNetworksToCIDRs(nets []MachineNetworkEntry) []configv1.CIDR {
23+
res := []configv1.CIDR{}
24+
25+
if nets == nil {
26+
return res
27+
}
28+
29+
for _, net := range nets {
30+
res = append(res, configv1.CIDR(net.CIDR.String()))
31+
}
32+
33+
return res
34+
}

pkg/types/utils_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package types
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
8+
configv1 "github.com/openshift/api/config/v1"
9+
"github.com/openshift/installer/pkg/ipnet"
10+
)
11+
12+
// TestStringsToIPs tests the StringsToIPs function.
13+
func TestStringsToIPs(t *testing.T) {
14+
testcases := []struct {
15+
ips []string
16+
expected []configv1.IP
17+
}{
18+
{
19+
[]string{"10.0.0.1", "10.0.0.2"},
20+
[]configv1.IP{"10.0.0.1", "10.0.0.2"},
21+
},
22+
{
23+
[]string{},
24+
[]configv1.IP{},
25+
},
26+
{
27+
[]string{"fe80:1:2:3::"},
28+
[]configv1.IP{"fe80:1:2:3::"},
29+
},
30+
}
31+
32+
for _, tc := range testcases {
33+
res := StringsToIPs(tc.ips)
34+
assert.Equal(t, tc.expected, res, "conversion failed")
35+
}
36+
}
37+
38+
// TestMachineNetworksToCIDRs tests the MachineNetworksToCIDRs function.
39+
func TestMachineNetworksToCIDRs(t *testing.T) {
40+
testcases := []struct {
41+
networks []MachineNetworkEntry
42+
expected []configv1.CIDR
43+
}{
44+
{
45+
[]MachineNetworkEntry{
46+
{CIDR: *ipnet.MustParseCIDR("10.0.0.1/32")},
47+
{CIDR: *ipnet.MustParseCIDR("10.0.0.2/32")},
48+
},
49+
[]configv1.CIDR{"10.0.0.1/32", "10.0.0.2/32"},
50+
},
51+
{
52+
[]MachineNetworkEntry{},
53+
[]configv1.CIDR{},
54+
},
55+
{
56+
[]MachineNetworkEntry{
57+
{CIDR: *ipnet.MustParseCIDR("fe80:1:2:3::/128")},
58+
},
59+
[]configv1.CIDR{"fe80:1:2:3::/128"},
60+
},
61+
}
62+
63+
for _, tc := range testcases {
64+
res := MachineNetworksToCIDRs(tc.networks)
65+
assert.Equal(t, tc.expected, res, "conversion failed")
66+
}
67+
}

0 commit comments

Comments
 (0)