1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 06:46:36 +01:00

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.
This commit is contained in:
W. Trevor King
2019-01-03 01:15:19 -08:00
parent b9cd189bc4
commit 31952f1520
30 changed files with 86 additions and 190 deletions

View File

@@ -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}"

View File

@@ -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"

View File

@@ -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"

View File

@@ -39,7 +39,7 @@ resource "libvirt_network" "net" {
domain = "${var.base_domain}"
addresses = [
"${var.libvirt_ip_range}",
"${var.machine_cidr}",
]
dns = [{

View File

@@ -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"

View File

@@ -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)}"

View File

@@ -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
}

View File

@@ -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))
@@ -86,8 +81,7 @@ func Platform() (*aws.Platform, error) {
}
return &aws.Platform{
VPCCIDRBlock: defaultVPCCIDR,
Region: region,
Region: region,
}, nil
}

View File

@@ -1,7 +1,6 @@
package installconfig
import (
"net"
"os"
"github.com/ghodss/yaml"
@@ -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"
@@ -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
)
@@ -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,
@@ -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:
@@ -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)

View File

@@ -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"
)
@@ -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",

View File

@@ -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.
@@ -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,

View File

@@ -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()
@@ -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
}

View File

@@ -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{
@@ -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",
@@ -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,
}

View File

@@ -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{

View File

@@ -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"`
}

View File

@@ -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)
}
@@ -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

View File

@@ -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.

View File

@@ -15,10 +15,11 @@ import (
)
type config struct {
ClusterID string `json:"cluster_id,omitempty"`
Name string `json:"cluster_name,omitempty"`
BaseDomain string `json:"base_domain,omitempty"`
Masters int `json:"master_count,omitempty"`
ClusterID string `json:"cluster_id,omitempty"`
Name string `json:"cluster_name,omitempty"`
BaseDomain string `json:"base_domain,omitempty"`
MachineCIDR string `json:"machine_cidr"`
Masters int `json:"master_count,omitempty"`
IgnitionBootstrap string `json:"ignition_bootstrap,omitempty"`
IgnitionMaster string `json:"ignition_master,omitempty"`
@@ -32,9 +33,10 @@ type config struct {
// terraform.tfvar JSON.
func TFVars(cfg *types.InstallConfig, bootstrapIgn, masterIgn string) ([]byte, error) {
config := &config{
ClusterID: cfg.ClusterID,
Name: cfg.ObjectMeta.Name,
BaseDomain: cfg.BaseDomain,
ClusterID: cfg.ClusterID,
Name: cfg.ObjectMeta.Name,
BaseDomain: cfg.BaseDomain,
MachineCIDR: cfg.Networking.MachineCIDR.String(),
IgnitionMaster: masterIgn,
IgnitionBootstrap: bootstrapIgn,
@@ -82,14 +84,8 @@ func TFVars(cfg *types.InstallConfig, bootstrapIgn, masterIgn string) ([]byte, e
}
config.AWS = aws.AWS{
Region: cfg.Platform.AWS.Region,
ExtraTags: cfg.Platform.AWS.UserTags,
VPCCIDRBlock: func() string {
if cfg.Platform.AWS.VPCCIDRBlock == nil {
return ""
}
return cfg.Platform.AWS.VPCCIDRBlock.String()
}(),
Region: cfg.Platform.AWS.Region,
ExtraTags: cfg.Platform.AWS.UserTags,
EC2AMIOverride: ami,
}
} else if cfg.Platform.Libvirt != nil {
@@ -100,13 +96,12 @@ func TFVars(cfg *types.InstallConfig, bootstrapIgn, masterIgn string) ([]byte, e
config.Libvirt = libvirt.Libvirt{
URI: cfg.Platform.Libvirt.URI,
Network: libvirt.Network{
IfName: cfg.Platform.Libvirt.Network.IfName,
IPRange: cfg.Platform.Libvirt.Network.IPRange.String(),
IfName: cfg.Platform.Libvirt.Network.IfName,
},
Image: cfg.Platform.Libvirt.DefaultMachinePlatform.Image,
MasterIPs: masterIPs,
}
if err := config.Libvirt.TFVars(config.Masters); err != nil {
if err := config.Libvirt.TFVars(&cfg.Networking.MachineCIDR.IPNet, config.Masters); err != nil {
return nil, errors.Wrap(err, "failed to insert libvirt variables")
}
if err := config.Libvirt.UseCachedImage(); err != nil {
@@ -114,9 +109,8 @@ func TFVars(cfg *types.InstallConfig, bootstrapIgn, masterIgn string) ([]byte, e
}
} else if cfg.Platform.OpenStack != nil {
config.OpenStack = openstack.OpenStack{
Region: cfg.Platform.OpenStack.Region,
NetworkCIDRBlock: cfg.Platform.OpenStack.NetworkCIDRBlock.String(),
BaseImage: cfg.Platform.OpenStack.BaseImage,
Region: cfg.Platform.OpenStack.Region,
BaseImage: cfg.Platform.OpenStack.BaseImage,
}
config.OpenStack.Credentials.Cloud = cfg.Platform.OpenStack.Cloud
config.OpenStack.ExternalNetwork = cfg.Platform.OpenStack.ExternalNetwork

View File

@@ -1,9 +1,5 @@
package aws
import (
"github.com/openshift/installer/pkg/ipnet"
)
// Platform stores all the global configuration that all machinesets
// use.
type Platform struct {
@@ -17,8 +13,4 @@ type Platform struct {
// installing on AWS for machine pools which do not define their own
// platform configuration.
DefaultMachinePlatform *MachinePool `json:"defaultMachinePlatform,omitempty"`
// VPCCIDRBlock
// +optional
VPCCIDRBlock *ipnet.IPNet `json:"vpcCIDRBlock,omitempty"`
}

View File

@@ -6,7 +6,6 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
"github.com/openshift/installer/pkg/types/aws"
"github.com/openshift/installer/pkg/validate"
)
var (
@@ -55,10 +54,5 @@ func ValidatePlatform(p *aws.Platform, fldPath *field.Path) field.ErrorList {
if p.DefaultMachinePlatform != nil {
allErrs = append(allErrs, ValidateMachinePool(p.DefaultMachinePlatform, fldPath.Child("defaultMachinePlatform"))...)
}
if p.VPCCIDRBlock != nil {
if err := validate.SubnetCIDR(&p.VPCCIDRBlock.IPNet); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("vpcCIDRBlock"), p.VPCCIDRBlock, err.Error()))
}
}
return allErrs
}

View File

@@ -6,7 +6,6 @@ import (
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/validation/field"
"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types/aws"
)
@@ -50,22 +49,6 @@ func TestValidatePlatform(t *testing.T) {
},
valid: false,
},
{
name: "valid CIDR",
platform: &aws.Platform{
Region: "us-east-1",
VPCCIDRBlock: ipnet.MustParseCIDR("192.168.0.0/16"),
},
valid: true,
},
{
name: "invalid CIDR",
platform: &aws.Platform{
Region: "us-east-1",
VPCCIDRBlock: ipnet.MustParseCIDR("0.0.0.0/16"),
},
valid: false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {

View File

@@ -108,10 +108,13 @@ func (p *Platform) Name() string {
// Networking defines the pod network provider in the cluster.
type Networking struct {
// MachineCIDR is the IP address space from which to assign machine IPs.
MachineCIDR ipnet.IPNet `json:"machineCIDR"`
// Type is the network type to install
Type netopv1.NetworkType `json:"type"`
// ServiceCIDR is the ip block from which to assign service IPs
// ServiceCIDR is the IP address space from which to assign service IPs.
ServiceCIDR ipnet.IPNet `json:"serviceCIDR"`
// ClusterNetworks is the IP address space from which to assign pod IPs.

View File

@@ -1,13 +1,7 @@
package libvirt
import (
"github.com/openshift/installer/pkg/ipnet"
)
// Network is the configuration of the libvirt network.
type Network struct {
// IfName is the name of the network interface.
IfName string `json:"if"`
// IPRange is the range of IPs to use.
IPRange ipnet.IPNet `json:"ipRange"`
}

View File

@@ -19,8 +19,5 @@ func ValidatePlatform(p *libvirt.Platform, fldPath *field.Path) field.ErrorList
if p.Network.IfName == "" {
allErrs = append(allErrs, field.Required(fldPath.Child("network").Child("if"), p.Network.IfName))
}
if err := validate.SubnetCIDR(&p.Network.IPRange.IPNet); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("network").Child("ipRange"), p.Network.IPRange, err.Error()))
}
return allErrs
}

View File

@@ -6,7 +6,6 @@ import (
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/validation/field"
"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types/libvirt"
)
@@ -14,8 +13,7 @@ func validPlatform() *libvirt.Platform {
return &libvirt.Platform{
URI: "qemu+tcp://192.168.122.1/system",
Network: libvirt.Network{
IfName: "tt0",
IPRange: *ipnet.MustParseCIDR("10.0.0.0/16"),
IfName: "tt0",
},
}
}
@@ -49,15 +47,6 @@ func TestValidatePlatform(t *testing.T) {
}(),
valid: false,
},
{
name: "missing ip range",
platform: func() *libvirt.Platform {
p := validPlatform()
p.Network.IPRange = ipnet.IPNet{}
return p
}(),
valid: false,
},
{
name: "valid machine pool",
platform: func() *libvirt.Platform {

View File

@@ -1,9 +1,5 @@
package openstack
import (
"github.com/openshift/installer/pkg/ipnet"
)
// Platform stores all the global configuration that all
// machinesets use.
type Platform struct {
@@ -15,9 +11,6 @@ type Platform struct {
// platform configuration.
DefaultMachinePlatform *MachinePool `json:"defaultMachinePlatform,omitempty"`
// NetworkCIDRBlock
NetworkCIDRBlock ipnet.IPNet `json:"NetworkCIDRBlock"`
// BaseImage
// Name of image to use from OpenStack cloud
BaseImage string `json:"baseImage"`

View File

@@ -6,7 +6,6 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
"github.com/openshift/installer/pkg/types/openstack"
"github.com/openshift/installer/pkg/validate"
)
// ValidatePlatform checks that the specified platform is valid.
@@ -46,9 +45,6 @@ func ValidatePlatform(p *openstack.Platform, fldPath *field.Path, fetcher ValidV
if p.DefaultMachinePlatform != nil {
allErrs = append(allErrs, ValidateMachinePool(p.DefaultMachinePlatform, fldPath.Child("defaultMachinePlatform"))...)
}
if err := validate.SubnetCIDR(&p.NetworkCIDRBlock.IPNet); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("NetworkCIDRBlock"), p.NetworkCIDRBlock, err.Error()))
}
return allErrs
}

View File

@@ -8,19 +8,17 @@ import (
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/validation/field"
"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types/openstack"
"github.com/openshift/installer/pkg/types/openstack/validation/mock"
)
func validPlatform() *openstack.Platform {
return &openstack.Platform{
Region: "test-region",
NetworkCIDRBlock: *ipnet.MustParseCIDR("10.0.0.0/16"),
BaseImage: "test-image",
Cloud: "test-cloud",
ExternalNetwork: "test-network",
FlavorName: "test-flavor",
Region: "test-region",
BaseImage: "test-image",
Cloud: "test-cloud",
ExternalNetwork: "test-network",
FlavorName: "test-flavor",
}
}

View File

@@ -50,6 +50,9 @@ func validateNetworking(n *types.Networking, fldPath *field.Path) field.ErrorLis
if !validate.ValidNetworkTypes[n.Type] {
allErrs = append(allErrs, field.NotSupported(fldPath.Child("type"), n.Type, validate.ValidNetworkTypeValues))
}
if err := validate.SubnetCIDR(&n.MachineCIDR.IPNet); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("machineCIDR"), n.MachineCIDR, err.Error()))
}
if err := validate.SubnetCIDR(&n.ServiceCIDR.IPNet); err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("serviceCIDR"), n.ServiceCIDR, err.Error()))
}

View File

@@ -25,7 +25,8 @@ func validInstallConfig() *types.InstallConfig {
BaseDomain: "test-domain",
Networking: types.Networking{
Type: "OpenshiftSDN",
ServiceCIDR: *ipnet.MustParseCIDR("10.0.0.0/16"),
MachineCIDR: *ipnet.MustParseCIDR("10.0.0.0/16"),
ServiceCIDR: *ipnet.MustParseCIDR("172.30.0.0/16"),
ClusterNetworks: []netopv1.ClusterNetwork{
{
CIDR: "192.168.1.0/24",
@@ -127,10 +128,10 @@ func TestValidateInstallConfig(t *testing.T) {
name: "overlapping cluster network cidr",
installConfig: func() *types.InstallConfig {
c := validInstallConfig()
c.Networking.ClusterNetworks[0].CIDR = "10.0.0.0/24"
c.Networking.ClusterNetworks[0].CIDR = "172.30.0.0/24"
return c
}(),
expectedError: `^networking\.clusterNetworks\[0]\.cidr: Invalid value: "10\.0\.0\.0/24": cluster network CIDR must not overlap with serviceCIDR$`,
expectedError: `^networking\.clusterNetworks\[0]\.cidr: Invalid value: "172\.30\.0\.0/24": cluster network CIDR must not overlap with serviceCIDR$`,
},
{
name: "cluster network host subnet length too large",
@@ -206,7 +207,7 @@ func TestValidateInstallConfig(t *testing.T) {
c.Platform.Libvirt = &libvirt.Platform{}
return c
}(),
expectedError: `^\[platform: Invalid value: types\.Platform{AWS:\(\*aws\.Platform\)\(0x[0-9a-f]*\), Libvirt:\(\*libvirt\.Platform\)\(0x[0-9a-f]*\), None:\(\*none\.Platform\)\(nil\), OpenStack:\(\*openstack\.Platform\)\(nil\)}: must only specify a single type of platform; cannot use both "aws" and "libvirt", platform\.libvirt\.uri: Invalid value: "": invalid URI "" \(no scheme\), platform\.libvirt\.network\.if: Required value, platform\.libvirt\.network\.ipRange: Invalid value: ipnet\.IPNet{IPNet:net\.IPNet{IP:net\.IP\(nil\), Mask:net\.IPMask\(nil\)}}: must use IPv4]$`,
expectedError: `^\[platform: Invalid value: types\.Platform{AWS:\(\*aws\.Platform\)\(0x[0-9a-f]*\), Libvirt:\(\*libvirt\.Platform\)\(0x[0-9a-f]*\), None:\(\*none\.Platform\)\(nil\), OpenStack:\(\*openstack\.Platform\)\(nil\)}: must only specify a single type of platform; cannot use both "aws" and "libvirt", platform\.libvirt\.uri: Invalid value: "": invalid URI "" \(no scheme\), platform\.libvirt\.network\.if: Required value]$`,
},
{
name: "invalid aws platform",
@@ -227,8 +228,7 @@ func TestValidateInstallConfig(t *testing.T) {
Libvirt: &libvirt.Platform{
URI: "qemu+tcp://192.168.122.1/system",
Network: libvirt.Network{
IfName: "tt0",
IPRange: *ipnet.MustParseCIDR("10.0.0.0/16"),
IfName: "tt0",
},
},
}
@@ -245,7 +245,7 @@ func TestValidateInstallConfig(t *testing.T) {
}
return c
}(),
expectedError: `^\[platform: Invalid value: types\.Platform{AWS:\(\*aws\.Platform\)\(nil\), Libvirt:\(\*libvirt\.Platform\)\(0x[0-9a-f]*\), None:\(\*none\.Platform\)\(nil\), OpenStack:\(\*openstack\.Platform\)\(nil\)}: must specify one of the platforms \(aws, none, openstack\), platform\.libvirt\.uri: Invalid value: "": invalid URI "" \(no scheme\), platform\.libvirt\.network\.if: Required value, platform\.libvirt\.network\.ipRange: Invalid value: ipnet\.IPNet{IPNet:net\.IPNet{IP:net\.IP\(nil\), Mask:net\.IPMask\(nil\)}}: must use IPv4]$`,
expectedError: `^\[platform: Invalid value: types\.Platform{AWS:\(\*aws\.Platform\)\(nil\), Libvirt:\(\*libvirt\.Platform\)\(0x[0-9a-f]*\), None:\(\*none\.Platform\)\(nil\), OpenStack:\(\*openstack\.Platform\)\(nil\)}: must specify one of the platforms \(aws, none, openstack\), platform\.libvirt\.uri: Invalid value: "": invalid URI "" \(no scheme\), platform\.libvirt\.network\.if: Required value]$`,
},
{
name: "valid openstack platform",
@@ -253,12 +253,11 @@ func TestValidateInstallConfig(t *testing.T) {
c := validInstallConfig()
c.Platform = types.Platform{
OpenStack: &openstack.Platform{
Region: "test-region",
NetworkCIDRBlock: *ipnet.MustParseCIDR("10.0.0.0/16"),
BaseImage: "test-image",
Cloud: "test-cloud",
ExternalNetwork: "test-network",
FlavorName: "test-flavor",
Region: "test-region",
BaseImage: "test-image",
Cloud: "test-cloud",
ExternalNetwork: "test-network",
FlavorName: "test-flavor",
},
}
return c
@@ -273,7 +272,7 @@ func TestValidateInstallConfig(t *testing.T) {
}
return c
}(),
expectedError: `^\[platform\.openstack\.cloud: Unsupported value: "": supported values: "test-cloud", platform\.openstack\.NetworkCIDRBlock: Invalid value: ipnet\.IPNet{IPNet:net\.IPNet{IP:net\.IP\(nil\), Mask:net\.IPMask\(nil\)}}: must use IPv4]$`,
expectedError: `^platform\.openstack\.cloud: Unsupported value: "": supported values: "test-cloud"$`,
},
}
for _, tc := range cases {