Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/data/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module "vpc" {
source = "./vpc"

base_domain = "${var.base_domain}"
cidr_block = "${var.aws_vpc_cidr_block}"
cidr_block = "${var.machine_cidr}"
cluster_id = "${var.cluster_id}"
cluster_name = "${var.cluster_name}"
region = "${var.aws_region}"
Expand Down
9 changes: 0 additions & 9 deletions data/data/aws/variables-aws.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ variable "aws_ec2_ami_override" {
default = ""
}

variable "aws_vpc_cidr_block" {
type = "string"

description = <<EOF
Block of IP addresses used by the VPC.
This should not overlap with any other networks, such as a private datacenter connected via Direct Connect.
EOF
}

variable "aws_extra_tags" {
type = "map"

Expand Down
8 changes: 8 additions & 0 deletions data/data/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ terraform {
required_version = ">= 0.10.7"
}

variable "machine_cidr" {
type = "string"

description = <<EOF
The IP address space from which to assign machine IPs.
EOF
}

variable "master_count" {
type = "string"
default = "1"
Expand Down
2 changes: 1 addition & 1 deletion data/data/libvirt/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ resource "libvirt_network" "net" {
domain = "${var.base_domain}"

addresses = [
"${var.libvirt_ip_range}",
"${var.machine_cidr}",
]

dns = [{
Expand Down
5 changes: 0 additions & 5 deletions data/data/libvirt/variables-libvirt.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ variable "libvirt_network_if" {
description = "The name of the bridge to use"
}

variable "libvirt_ip_range" {
type = "string"
description = "IP range for the libvirt machines"
}

variable "os_image" {
type = "string"
description = "The URL of the OS disk image"
Expand Down
2 changes: 1 addition & 1 deletion data/data/openstack/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module "masters" {
module "topology" {
source = "./topology"

cidr_block = "${var.openstack_network_cidr_block}"
cidr_block = "${var.machine_cidr}"
cluster_id = "${var.cluster_id}"
cluster_name = "${var.cluster_name}"
external_master_subnet_ids = "${compact(var.openstack_external_master_subnet_ids)}"
Expand Down
9 changes: 0 additions & 9 deletions data/data/openstack/variables-openstack.tf
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,3 @@ variable "openstack_region" {
type = "string"
description = "The target OpenStack region for the cluster."
}

variable "openstack_network_cidr_block" {
type = "string"

description = <<EOF
Block of IP addresses used by the VPC.
This should not overlap with any other networks, such as a private datacenter connected via Direct Connect.
EOF
}
8 changes: 1 addition & 7 deletions pkg/asset/installconfig/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ import (
"github.com/sirupsen/logrus"
survey "gopkg.in/AlecAivazis/survey.v1"

"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types/aws"
"github.com/openshift/installer/pkg/types/aws/validation"
)

var (
defaultVPCCIDR = ipnet.MustParseCIDR("10.0.0.0/16")
)

// Platform collects AWS-specific configuration.
func Platform() (*aws.Platform, error) {
longRegions := make([]string, 0, len(validation.Regions))
Expand Down Expand Up @@ -86,8 +81,7 @@ func Platform() (*aws.Platform, error) {
}

return &aws.Platform{
VPCCIDRBlock: defaultVPCCIDR,
Region: region,
Region: region,
}, nil
}

Expand Down
19 changes: 7 additions & 12 deletions pkg/asset/installconfig/installconfig.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package installconfig

import (
"net"
"os"

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

netopv1 "github.com/openshift/cluster-network-operator/pkg/apis/networkoperator/v1"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig/libvirt"
"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types"
openstackvalidation "github.com/openshift/installer/pkg/types/openstack/validation"
Expand All @@ -23,7 +23,8 @@ const (
)

var (
defaultServiceCIDR = parseCIDR("172.30.0.0/16")
defaultMachineCIDR = ipnet.MustParseCIDR("10.0.0.0/16")
defaultServiceCIDR = ipnet.MustParseCIDR("172.30.0.0/16")
defaultClusterCIDR = "10.128.0.0/14"
defaultHostSubnetLength = 9 // equivalent to a /23 per node
)
Expand Down Expand Up @@ -74,11 +75,9 @@ func (a *InstallConfig) Generate(parents asset.Parents) error {
SSHKey: sshPublicKey.Key,
BaseDomain: baseDomain.BaseDomain,
Networking: types.Networking{
Type: "OpenshiftSDN",

ServiceCIDR: ipnet.IPNet{
IPNet: defaultServiceCIDR,
},
Type: "OpenshiftSDN",
MachineCIDR: *defaultMachineCIDR,
ServiceCIDR: *defaultServiceCIDR,
ClusterNetworks: []netopv1.ClusterNetwork{
{
CIDR: defaultClusterCIDR,
Expand All @@ -96,6 +95,7 @@ func (a *InstallConfig) Generate(parents asset.Parents) error {
a.Config.AWS = platform.AWS
case platform.Libvirt != nil:
a.Config.Libvirt = platform.Libvirt
a.Config.Networking.MachineCIDR = *libvirt.DefaultMachineCIDR
numberOfMasters = 1
numberOfWorkers = 1
case platform.None != nil:
Expand Down Expand Up @@ -142,11 +142,6 @@ func (a *InstallConfig) Files() []*asset.File {
return []*asset.File{}
}

func parseCIDR(s string) net.IPNet {
_, cidr, _ := net.ParseCIDR(s)
return *cidr
}

// Load returns the installconfig from disk.
func (a *InstallConfig) Load(f asset.FileFetcher) (found bool, err error) {
file, err := fetchInstallConfigFile(f)
Expand Down
4 changes: 2 additions & 2 deletions pkg/asset/installconfig/installconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/mock"
"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/aws"
)
Expand All @@ -27,7 +26,8 @@ func validInstallConfig() *types.InstallConfig {
BaseDomain: "test-domain",
Networking: types.Networking{
Type: "OpenshiftSDN",
ServiceCIDR: *ipnet.MustParseCIDR("10.0.0.0/16"),
MachineCIDR: *defaultMachineCIDR,
ServiceCIDR: *defaultServiceCIDR,
ClusterNetworks: []netopv1.ClusterNetwork{
{
CIDR: "192.168.1.0/24",
Expand Down
7 changes: 4 additions & 3 deletions pkg/asset/installconfig/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const (
)

var (
defaultNetworkIPRange = ipnet.MustParseCIDR("192.168.126.0/24")
// DefaultMachineCIDR is the libvirt default IP address space from
// which to assign machine IPs.
DefaultMachineCIDR = ipnet.MustParseCIDR("192.168.126.0/24")
)

// Platform collects libvirt-specific configuration.
Expand All @@ -45,8 +47,7 @@ func Platform() (*libvirt.Platform, error) {

return &libvirt.Platform{
Network: libvirt.Network{
IfName: defaultNetworkIfName,
IPRange: *defaultNetworkIPRange,
IfName: defaultNetworkIfName,
},
DefaultMachinePlatform: &libvirt.MachinePool{
Image: qcowImage,
Expand Down
16 changes: 5 additions & 11 deletions pkg/asset/installconfig/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ import (
"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"

"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types/openstack"
openstackvalidation "github.com/openshift/installer/pkg/types/openstack/validation"
)

var (
defaultNetworkCIDR = ipnet.MustParseCIDR("10.0.0.0/16")
)

// Platform collects OpenStack-specific configuration.
func Platform() (*openstack.Platform, error) {
validValuesFetcher := openstackvalidation.NewValidValuesFetcher()
Expand Down Expand Up @@ -160,11 +155,10 @@ func Platform() (*openstack.Platform, error) {
}

return &openstack.Platform{
NetworkCIDRBlock: *defaultNetworkCIDR,
Region: region,
BaseImage: image,
Cloud: cloud,
ExternalNetwork: extNet,
FlavorName: flavor,
Region: region,
BaseImage: image,
Cloud: cloud,
ExternalNetwork: extNet,
FlavorName: flavor,
}, nil
}
6 changes: 3 additions & 3 deletions pkg/asset/machines/libvirt/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Machines(config *types.InstallConfig, pool *types.MachinePool, role, userDa
if pool.Replicas != nil {
total = *pool.Replicas
}
provider := provider(clustername, platform, userDataSecret)
provider := provider(clustername, config.Networking.MachineCIDR.String(), platform, userDataSecret)
var machines []clusterapi.Machine
for idx := int64(0); idx < total; idx++ {
machine := clusterapi.Machine{
Expand Down Expand Up @@ -61,7 +61,7 @@ func Machines(config *types.InstallConfig, pool *types.MachinePool, role, userDa
return machines, nil
}

func provider(clusterName string, platform *libvirt.Platform, userDataSecret string) *libvirtprovider.LibvirtMachineProviderConfig {
func provider(clusterName string, networkInterfaceAddress string, platform *libvirt.Platform, userDataSecret string) *libvirtprovider.LibvirtMachineProviderConfig {
return &libvirtprovider.LibvirtMachineProviderConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: "libvirtproviderconfig.k8s.io/v1alpha1",
Expand All @@ -77,7 +77,7 @@ func provider(clusterName string, platform *libvirt.Platform, userDataSecret str
BaseVolumeID: fmt.Sprintf("/var/lib/libvirt/images/%s-base", clusterName),
},
NetworkInterfaceName: clusterName,
NetworkInterfaceAddress: platform.Network.IPRange.String(),
NetworkInterfaceAddress: networkInterfaceAddress,
Autostart: false,
URI: platform.URI,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/machines/libvirt/machinesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func MachineSets(config *types.InstallConfig, pool *types.MachinePool, role, use
total = *pool.Replicas
}

provider := provider(clustername, platform, userDataSecret)
provider := provider(clustername, config.Networking.MachineCIDR.String(), platform, userDataSecret)
name := fmt.Sprintf("%s-%s-%d", clustername, pool.Name, 0)
mset := clusterapi.MachineSet{
TypeMeta: metav1.TypeMeta{
Expand Down
1 change: 0 additions & 1 deletion pkg/tfvars/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type AWS struct {
ExtraTags map[string]string `json:"aws_extra_tags,omitempty"`
Master `json:",inline"`
Region string `json:"aws_region,omitempty"`
VPCCIDRBlock string `json:"aws_vpc_cidr_block"`
Worker `json:",inline"`
}

Expand Down
14 changes: 4 additions & 10 deletions pkg/tfvars/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@ type Libvirt struct {

// Network describes a libvirt network configuration.
type Network struct {
IfName string `json:"libvirt_network_if"`
IPRange string `json:"libvirt_ip_range"`
IfName string `json:"libvirt_network_if"`
}

// TFVars fills in computed Terraform variables.
func (l *Libvirt) TFVars(masterCount int) error {
_, network, err := net.ParseCIDR(l.Network.IPRange)
if err != nil {
return fmt.Errorf("failed to parse libvirt network ipRange: %v", err)
}

func (l *Libvirt) TFVars(machineCIDR *net.IPNet, masterCount int) error {
if l.BootstrapIP == "" {
ip, err := cidr.Host(network, 10)
ip, err := cidr.Host(machineCIDR, 10)
if err != nil {
return fmt.Errorf("failed to generate bootstrap IP: %v", err)
}
Expand All @@ -42,7 +36,7 @@ func (l *Libvirt) TFVars(masterCount int) error {
return fmt.Errorf("length of MasterIPs doesn't match master count")
}
} else {
if ips, err := generateIPs("master", network, masterCount, 11); err == nil {
if ips, err := generateIPs("master", machineCIDR, masterCount, 11); err == nil {
l.MasterIPs = ips
} else {
return err
Expand Down
15 changes: 7 additions & 8 deletions pkg/tfvars/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package openstack

// OpenStack converts OpenStack related config.
type OpenStack struct {
BaseImage string `json:"openstack_base_image,omitempty"`
Credentials `json:",inline"`
External `json:",inline"`
ExternalNetwork string `json:"openstack_external_network,omitempty"`
ExtraTags map[string]string `json:"openstack_extra_tags,omitempty"`
Master `json:",inline"`
Region string `json:"openstack_region,omitempty"`
NetworkCIDRBlock string `json:"openstack_network_cidr_block,omitempty"`
BaseImage string `json:"openstack_base_image,omitempty"`
Credentials `json:",inline"`
External `json:",inline"`
ExternalNetwork string `json:"openstack_external_network,omitempty"`
ExtraTags map[string]string `json:"openstack_extra_tags,omitempty"`
Master `json:",inline"`
Region string `json:"openstack_region,omitempty"`
}

// External converts external related config.
Expand Down
Loading