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 2a66f36
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
5 changes: 4 additions & 1 deletion pkg/apis/hive/v1alpha1/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
corev1 "k8s.io/api/core/v1"

"net"

"github.com/openshift/installer/pkg/ipnet"
)

// InstallConfig is the configuration for an OpenShift install.
Expand Down Expand Up @@ -72,7 +74,8 @@ type AWSPlatform struct {
DefaultMachinePlatform *AWSMachinePoolPlatform `json:"defaultMachinePlatform,omitempty"`

// VPCCIDRBlock
VPCCIDRBlock string `json:"vpcCIDRBlock"`
// +optional
VPCCIDRBlock *ipnet.IPNet `json:"vpcCIDRBlock,omitempty"`
}

// LibvirtPlatform stores all the global configuration that
Expand Down
18 changes: 6 additions & 12 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 @@ -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
15 changes: 7 additions & 8 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 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 2a66f36

Please sign in to comment.