From 02ff8fa8beab22ffaea5e238d8f702f5f467cfbc Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 18 Dec 2018 23:50:47 -0800 Subject: [PATCH] pkg/apis/hive/v1alpha1: Make VPCCIDRBlock an *IPNet Catching up with openshift/installer@b2d6fa40 (validate: simplify CIDR validation, 2018-11-27, openshift/installer#711). --- pkg/apis/hive/v1alpha1/installconfig.go | 3 ++- pkg/install/convertconfig.go | 20 +++++++------------- pkg/install/convertconfig_test.go | 17 ++++++++--------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/pkg/apis/hive/v1alpha1/installconfig.go b/pkg/apis/hive/v1alpha1/installconfig.go index 18f9f5e9d8f..a111cd00161 100644 --- a/pkg/apis/hive/v1alpha1/installconfig.go +++ b/pkg/apis/hive/v1alpha1/installconfig.go @@ -72,7 +72,8 @@ type AWSPlatform struct { DefaultMachinePlatform *AWSMachinePoolPlatform `json:"defaultMachinePlatform,omitempty"` // VPCCIDRBlock - VPCCIDRBlock string `json:"vpcCIDRBlock"` + // +optional + VPCCIDRBlock string `json:"vpcCIDRBlock,omitempty"` } // LibvirtPlatform stores all the global configuration that diff --git a/pkg/install/convertconfig.go b/pkg/install/convertconfig.go index 31f22e23447..5f2d00fc10a 100644 --- a/pkg/install/convertconfig.go +++ b/pkg/install/convertconfig.go @@ -18,7 +18,6 @@ package install import ( "fmt" - "net" hivev1 "github.com/openshift/hive/pkg/apis/hive/v1alpha1" @@ -50,7 +49,7 @@ func GenerateInstallConfig(cd *hivev1.ClusterDeployment, sshKey, pullSecret stri platform.AWS = &installeraws.Platform{ Region: aws.Region, UserTags: aws.UserTags, - VPCCIDRBlock: aws.VPCCIDRBlock, + VPCCIDRBlock: parseCIDR(aws.VPCCIDRBlock), } if aws.DefaultMachinePlatform != nil { platform.AWS.DefaultMachinePlatform = &installeraws.MachinePool{ @@ -97,13 +96,9 @@ func GenerateInstallConfig(cd *hivev1.ClusterDeployment, sshKey, pullSecret stri SSHKey: sshKey, BaseDomain: spec.Config.BaseDomain, Networking: types.Networking{ - Type: networkType, - ServiceCIDR: ipnet.IPNet{ - IPNet: parseCIDR(spec.Config.Networking.ServiceCIDR), - }, - PodCIDR: &ipnet.IPNet{ - IPNet: parseCIDR(spec.Config.Networking.PodCIDR), - }, + Type: networkType, + ServiceCIDR: *parseCIDR(spec.Config.Networking.ServiceCIDR), + PodCIDR: parseCIDR(spec.Config.Networking.PodCIDR), }, PullSecret: pullSecret, Platform: platform, @@ -112,12 +107,11 @@ func GenerateInstallConfig(cd *hivev1.ClusterDeployment, sshKey, pullSecret stri return ic, nil } -func parseCIDR(s string) net.IPNet { +func parseCIDR(s string) *ipnet.IPNet { if s == "" { - return net.IPNet{} + return &ipnet.IPNet{} } - _, cidr, _ := net.ParseCIDR(s) - return *cidr + return ipnet.MustParseCIDR(s) } func convertNetworkingType(hnt hivev1.NetworkType) (netopv1.NetworkType, error) { diff --git a/pkg/install/convertconfig_test.go b/pkg/install/convertconfig_test.go index bd7c722f0aa..2d2510e0d83 100644 --- a/pkg/install/convertconfig_test.go +++ b/pkg/install/convertconfig_test.go @@ -43,7 +43,6 @@ const ( adminPassword = "adminpassword" adminSSHKey = "adminSSH" pullSecret = "pullSecret" - vpcCIDRBlock = "10.1.0.0/16" awsInstanceType = "fake-aws-type" awsRegion = "us-east-1" iamRoleName = "rolename" @@ -52,6 +51,10 @@ const ( ec2VolType = "sometype" ) +var ( + vpcCIDRBlock = ipnet.MustParseCIDR("10.1.0.0/16") +) + func buildValidClusterDeployment() *hivev1.ClusterDeployment { replicas := int64(3) return &hivev1.ClusterDeployment{ @@ -71,7 +74,7 @@ func buildValidClusterDeployment() *hivev1.ClusterDeployment { UserTags: map[string]string{ "foo": "bar", }, - VPCCIDRBlock: vpcCIDRBlock, + VPCCIDRBlock: vpcCIDRBlock.String(), DefaultMachinePlatform: &hivev1.AWSMachinePoolPlatform{ InstanceType: awsInstanceType, IAMRoleName: iamRoleName, @@ -137,13 +140,9 @@ func buildBaseExpectedInstallConfig() *installtypes.InstallConfig { PullSecret: pullSecret, Networking: installtypes.Networking{ // TODO: Hardcoded to match installer for now. - Type: "OpenshiftSDN", - ServiceCIDR: ipnet.IPNet{ - IPNet: parseCIDR("172.30.0.0/16"), - }, - PodCIDR: &ipnet.IPNet{ - IPNet: parseCIDR("10.128.0.0/14"), - }, + Type: "OpenshiftSDN", + ServiceCIDR: *ipnet.MustParseCIDR("172.30.0.0/16"), + PodCIDR: ipnet.MustParseCIDR("10.128.0.0/14"), }, Platform: installtypes.Platform{ AWS: &installawstypes.Platform{