Skip to content

Commit

Permalink
pkg/apis/hive/v1alpha1: Make VPCCIDRBlock an *IPNet
Browse files Browse the repository at this point in the history
Catching up with openshift/installer@b2d6fa40 (validate: simplify CIDR
validation, 2018-11-27, openshift/installer#711).
  • Loading branch information
wking committed Dec 19, 2018
1 parent 99124d7 commit 02ff8fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
3 changes: 2 additions & 1 deletion pkg/apis/hive/v1alpha1/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 7 additions & 13 deletions pkg/install/convertconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package install

import (
"fmt"
"net"

hivev1 "github.com/openshift/hive/pkg/apis/hive/v1alpha1"

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
17 changes: 8 additions & 9 deletions pkg/install/convertconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{
Expand All @@ -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,
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 02ff8fa

Please sign in to comment.