Skip to content

Commit 31952f1

Browse files
committed
pkg/types: Add cross-platform Networking.MachineCIDR
The concept was not platform-specific, and it's simpler to track the cross-platform value in a single, generic location.
1 parent b9cd189 commit 31952f1

File tree

30 files changed

+86
-190
lines changed

30 files changed

+86
-190
lines changed

data/data/aws/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module "vpc" {
7070
source = "./vpc"
7171

7272
base_domain = "${var.base_domain}"
73-
cidr_block = "${var.aws_vpc_cidr_block}"
73+
cidr_block = "${var.machine_cidr}"
7474
cluster_id = "${var.cluster_id}"
7575
cluster_name = "${var.cluster_name}"
7676
region = "${var.aws_region}"

data/data/aws/variables-aws.tf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ variable "aws_ec2_ami_override" {
2121
default = ""
2222
}
2323

24-
variable "aws_vpc_cidr_block" {
25-
type = "string"
26-
27-
description = <<EOF
28-
Block of IP addresses used by the VPC.
29-
This should not overlap with any other networks, such as a private datacenter connected via Direct Connect.
30-
EOF
31-
}
32-
3324
variable "aws_extra_tags" {
3425
type = "map"
3526

data/data/config.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ terraform {
22
required_version = ">= 0.10.7"
33
}
44

5+
variable "machine_cidr" {
6+
type = "string"
7+
8+
description = <<EOF
9+
The IP address space from which to assign machine IPs.
10+
EOF
11+
}
12+
513
variable "master_count" {
614
type = "string"
715
default = "1"

data/data/libvirt/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ resource "libvirt_network" "net" {
3939
domain = "${var.base_domain}"
4040

4141
addresses = [
42-
"${var.libvirt_ip_range}",
42+
"${var.machine_cidr}",
4343
]
4444

4545
dns = [{

data/data/libvirt/variables-libvirt.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ variable "libvirt_network_if" {
1313
description = "The name of the bridge to use"
1414
}
1515

16-
variable "libvirt_ip_range" {
17-
type = "string"
18-
description = "IP range for the libvirt machines"
19-
}
20-
2116
variable "os_image" {
2217
type = "string"
2318
description = "The URL of the OS disk image"

data/data/openstack/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module "masters" {
7070
module "topology" {
7171
source = "./topology"
7272

73-
cidr_block = "${var.openstack_network_cidr_block}"
73+
cidr_block = "${var.machine_cidr}"
7474
cluster_id = "${var.cluster_id}"
7575
cluster_name = "${var.cluster_name}"
7676
external_master_subnet_ids = "${compact(var.openstack_external_master_subnet_ids)}"

data/data/openstack/variables-openstack.tf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,3 @@ variable "openstack_region" {
243243
type = "string"
244244
description = "The target OpenStack region for the cluster."
245245
}
246-
247-
variable "openstack_network_cidr_block" {
248-
type = "string"
249-
250-
description = <<EOF
251-
Block of IP addresses used by the VPC.
252-
This should not overlap with any other networks, such as a private datacenter connected via Direct Connect.
253-
EOF
254-
}

pkg/asset/installconfig/aws/aws.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@ import (
1616
"github.com/sirupsen/logrus"
1717
survey "gopkg.in/AlecAivazis/survey.v1"
1818

19-
"github.com/openshift/installer/pkg/ipnet"
2019
"github.com/openshift/installer/pkg/types/aws"
2120
"github.com/openshift/installer/pkg/types/aws/validation"
2221
)
2322

24-
var (
25-
defaultVPCCIDR = ipnet.MustParseCIDR("10.0.0.0/16")
26-
)
27-
2823
// Platform collects AWS-specific configuration.
2924
func Platform() (*aws.Platform, error) {
3025
longRegions := make([]string, 0, len(validation.Regions))
@@ -86,8 +81,7 @@ func Platform() (*aws.Platform, error) {
8681
}
8782

8883
return &aws.Platform{
89-
VPCCIDRBlock: defaultVPCCIDR,
90-
Region: region,
84+
Region: region,
9185
}, nil
9286
}
9387

pkg/asset/installconfig/installconfig.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package installconfig
22

33
import (
4-
"net"
54
"os"
65

76
"github.com/ghodss/yaml"
@@ -11,6 +10,7 @@ import (
1110

1211
netopv1 "github.com/openshift/cluster-network-operator/pkg/apis/networkoperator/v1"
1312
"github.com/openshift/installer/pkg/asset"
13+
"github.com/openshift/installer/pkg/asset/installconfig/libvirt"
1414
"github.com/openshift/installer/pkg/ipnet"
1515
"github.com/openshift/installer/pkg/types"
1616
openstackvalidation "github.com/openshift/installer/pkg/types/openstack/validation"
@@ -23,7 +23,8 @@ const (
2323
)
2424

2525
var (
26-
defaultServiceCIDR = parseCIDR("172.30.0.0/16")
26+
defaultMachineCIDR = ipnet.MustParseCIDR("10.0.0.0/16")
27+
defaultServiceCIDR = ipnet.MustParseCIDR("172.30.0.0/16")
2728
defaultClusterCIDR = "10.128.0.0/14"
2829
defaultHostSubnetLength = 9 // equivalent to a /23 per node
2930
)
@@ -74,11 +75,9 @@ func (a *InstallConfig) Generate(parents asset.Parents) error {
7475
SSHKey: sshPublicKey.Key,
7576
BaseDomain: baseDomain.BaseDomain,
7677
Networking: types.Networking{
77-
Type: "OpenshiftSDN",
78-
79-
ServiceCIDR: ipnet.IPNet{
80-
IPNet: defaultServiceCIDR,
81-
},
78+
Type: "OpenshiftSDN",
79+
MachineCIDR: *defaultMachineCIDR,
80+
ServiceCIDR: *defaultServiceCIDR,
8281
ClusterNetworks: []netopv1.ClusterNetwork{
8382
{
8483
CIDR: defaultClusterCIDR,
@@ -96,6 +95,7 @@ func (a *InstallConfig) Generate(parents asset.Parents) error {
9695
a.Config.AWS = platform.AWS
9796
case platform.Libvirt != nil:
9897
a.Config.Libvirt = platform.Libvirt
98+
a.Config.Networking.MachineCIDR = *libvirt.DefaultMachineCIDR
9999
numberOfMasters = 1
100100
numberOfWorkers = 1
101101
case platform.None != nil:
@@ -142,11 +142,6 @@ func (a *InstallConfig) Files() []*asset.File {
142142
return []*asset.File{}
143143
}
144144

145-
func parseCIDR(s string) net.IPNet {
146-
_, cidr, _ := net.ParseCIDR(s)
147-
return *cidr
148-
}
149-
150145
// Load returns the installconfig from disk.
151146
func (a *InstallConfig) Load(f asset.FileFetcher) (found bool, err error) {
152147
file, err := fetchInstallConfigFile(f)

pkg/asset/installconfig/installconfig_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/openshift/installer/pkg/asset"
1515
"github.com/openshift/installer/pkg/asset/mock"
16-
"github.com/openshift/installer/pkg/ipnet"
1716
"github.com/openshift/installer/pkg/types"
1817
"github.com/openshift/installer/pkg/types/aws"
1918
)
@@ -27,7 +26,8 @@ func validInstallConfig() *types.InstallConfig {
2726
BaseDomain: "test-domain",
2827
Networking: types.Networking{
2928
Type: "OpenshiftSDN",
30-
ServiceCIDR: *ipnet.MustParseCIDR("10.0.0.0/16"),
29+
MachineCIDR: *defaultMachineCIDR,
30+
ServiceCIDR: *defaultServiceCIDR,
3131
ClusterNetworks: []netopv1.ClusterNetwork{
3232
{
3333
CIDR: "192.168.1.0/24",

0 commit comments

Comments
 (0)