Skip to content
16 changes: 0 additions & 16 deletions data/data/install.openshift.io_installconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1810,22 +1810,6 @@ spec:
cluster. If empty, a new resource group will be created for
the cluster."
type: string
subnets:
description: Subnets is a list of existing subnet IDs. Leave unset
and the installer will create new subnets in the VPC network
on your behalf.
items:
type: string
type: array
vpc:
description: VPC is the ID of an existing VPC network. Leave unset
and the installer will create a new VPC network on your behalf.
type: string
vpcResourceGroupName:
description: VPCResourceGroupName specifies the resource group
containing an existing VPC. This must be defined if `VPC` is
defined.
type: string
required:
- region
type: object
Expand Down
2 changes: 0 additions & 2 deletions pkg/asset/cluster/ibmcloud/ibmcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ func Metadata(infraID string, config *types.InstallConfig, meta *icibmcloud.Meta
CISInstanceCRN: cisCrn,
Region: config.Platform.IBMCloud.Region,
ResourceGroupName: config.Platform.IBMCloud.ClusterResourceGroupName(infraID),
Subnets: config.Platform.IBMCloud.Subnets,
VPC: config.Platform.IBMCloud.VPC,
}
}
38 changes: 0 additions & 38 deletions pkg/asset/installconfig/ibmcloud/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ func validatePlatform(client API, ic *types.InstallConfig, path *field.Path) fie
allErrs = append(allErrs, validateResourceGroup(client, ic, path)...)
}

if ic.Platform.IBMCloud.VPC != "" {
allErrs = append(allErrs, validateNetworking(client, ic, path)...)
}

if ic.Platform.IBMCloud.DefaultMachinePlatform != nil {
allErrs = append(allErrs, validateMachinePool(client, ic.IBMCloud, ic.Platform.IBMCloud.DefaultMachinePlatform, path)...)
}
Expand Down Expand Up @@ -222,40 +218,6 @@ func validateResourceGroup(client API, ic *types.InstallConfig, path *field.Path
return allErrs
}

func validateNetworking(client API, ic *types.InstallConfig, path *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
platform := ic.Platform.IBMCloud

_, err := client.GetVPC(context.TODO(), platform.VPC)
if err != nil {
if errors.Is(err, &VPCResourceNotFoundError{}) {
allErrs = append(allErrs, field.NotFound(path.Child("vpc"), platform.VPC))
} else {
allErrs = append(allErrs, field.InternalError(path.Child("vpc"), err))
}
}

allErrs = append(allErrs, validateSubnets(client, ic, platform.Subnets, path)...)

return allErrs
}

func validateSubnets(client API, ic *types.InstallConfig, subnets []string, path *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
zones, err := client.GetVPCZonesForRegion(context.TODO(), ic.Platform.IBMCloud.Region)
if err != nil {
allErrs = append(allErrs, field.InternalError(path.Child("subnets"), err))
}
validZones := sets.NewString(zones...)
for idx, subnet := range subnets {
subnetPath := path.Child("subnets").Index(idx)
allErrs = append(allErrs, validateSubnetZone(client, subnet, validZones, subnetPath)...)
}

// TODO: IBM[#80]: additional subnet validation
return allErrs
}

func validateSubnetZone(client API, subnetID string, validZones sets.String, subnetPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if subnet, err := client.GetSubnet(context.TODO(), subnetID); err == nil {
Expand Down
42 changes: 0 additions & 42 deletions pkg/asset/installconfig/ibmcloud/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var (
validClusterName = "valid-cluster-name"
validDNSZoneID = "valid-zone-id"
validBaseDomain = "valid.base.domain"
validVPC = "valid-vpc"
validPublicSubnetUSSouth1ID = "public-subnet-us-south-1-id"
validPublicSubnetUSSouth2ID = "public-subnet-us-south-2-id"
validPrivateSubnetUSSouth1ID = "private-subnet-us-south-1-id"
Expand All @@ -42,13 +41,6 @@ var (

validInstanceProfies = []vpcv1.InstanceProfile{{Name: &[]string{"type-a"}[0]}, {Name: &[]string{"type-b"}[0]}}

validVPCConfig = func(ic *types.InstallConfig) {
ic.IBMCloud.VPC = validVPC
ic.IBMCloud.Subnets = validSubnets
}
notFoundVPC = func(ic *types.InstallConfig) { ic.IBMCloud.VPC = "not-found" }
internalErrorVPC = func(ic *types.InstallConfig) { ic.IBMCloud.VPC = "internal-error-vpc" }
subnetInvalidZone = func(ic *types.InstallConfig) { ic.IBMCloud.Subnets = []string{"subnet-invalid-zone"} }
machinePoolInvalidType = func(ic *types.InstallConfig) {
ic.ControlPlane.Platform.IBMCloud = &ibmcloudtypes.MachinePool{
InstanceType: "invalid-type",
Expand Down Expand Up @@ -115,47 +107,13 @@ func TestValidate(t *testing.T) {
edits: editFunctions{},
errorMsg: "",
},
{
name: "valid vpc config",
edits: editFunctions{validVPCConfig},
errorMsg: "",
},
{
name: "not found vpc",
edits: editFunctions{validVPCConfig, notFoundVPC},
errorMsg: `^platform\.ibmcloud\.vpc: Not found: \"not-found\"$`,
},
{
name: "internal error vpc",
edits: editFunctions{validVPCConfig, internalErrorVPC},
errorMsg: `^platform\.ibmcloud\.vpc: Internal error$`,
},
{
name: "subnet invalid zone",
edits: editFunctions{validVPCConfig, subnetInvalidZone},
errorMsg: `^\Qplatform.ibmcloud.subnets[0]: Invalid value: "subnet-invalid-zone": subnet is not in expected zones: [us-south-1 us-south-2 us-south-3]\E$`,
},
{
name: "machine pool invalid type",
edits: editFunctions{validVPCConfig, machinePoolInvalidType},
errorMsg: `^\QcontrolPlane.platform.ibmcloud.type: Not found: "invalid-type"\E$`,
},
{
name: "machine pool invalid type",
edits: editFunctions{validVPCConfig, machinePoolInvalidType},
errorMsg: `^\QcontrolPlane.platform.ibmcloud.type: Not found: "invalid-type"\E$`,
},
}

mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

ibmcloudClient := mock.NewMockAPI(mockCtrl)

ibmcloudClient.EXPECT().GetVPC(gomock.Any(), validVPC).Return(&vpcv1.VPC{}, nil).AnyTimes()
ibmcloudClient.EXPECT().GetVPC(gomock.Any(), "not-found").Return(nil, &ibmcloud.VPCResourceNotFoundError{})
ibmcloudClient.EXPECT().GetVPC(gomock.Any(), "internal-error-vpc").Return(nil, fmt.Errorf(""))

ibmcloudClient.EXPECT().GetSubnet(gomock.Any(), validPublicSubnetUSSouth1ID).Return(&vpcv1.Subnet{Zone: &vpcv1.ZoneReference{Name: &validZoneUSSouth1}}, nil).AnyTimes()
ibmcloudClient.EXPECT().GetSubnet(gomock.Any(), validPublicSubnetUSSouth2ID).Return(&vpcv1.Subnet{Zone: &vpcv1.ZoneReference{Name: &validZoneUSSouth1}}, nil).AnyTimes()
ibmcloudClient.EXPECT().GetSubnet(gomock.Any(), validPrivateSubnetUSSouth1ID).Return(&vpcv1.Subnet{Zone: &vpcv1.ZoneReference{Name: &validZoneUSSouth1}}, nil).AnyTimes()
Expand Down
7 changes: 1 addition & 6 deletions pkg/asset/machines/ibmcloud/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ func provider(clusterID string,
) (*ibmcloudprovider.IBMCloudMachineProviderSpec, error) {
az := mpool.Zones[azIdx]

var vpc string
if platform.VPC != "" {
vpc = platform.VPC
} else {
vpc = fmt.Sprintf("%s-vpc", clusterID)
}
var vpc = fmt.Sprintf("%s-vpc", clusterID)

var resourceGroup string
if platform.ResourceGroupName != "" {
Expand Down
14 changes: 0 additions & 14 deletions pkg/types/ibmcloud/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,11 @@ type Platform struct {
// +optional
ResourceGroupName string `json:"resourceGroupName,omitempty"`

// VPCResourceGroupName specifies the resource group containing an existing
// VPC. This must be defined if `VPC` is defined.
// +optional
VPCResourceGroupName string `json:"vpcResourceGroupName,omitempty"`

// DefaultMachinePlatform is the default configuration used when installing
// on IBM Cloud for machine pools which do not define their own platform
// configuration.
// +optional
DefaultMachinePlatform *MachinePool `json:"defaultMachinePlatform,omitempty"`

// VPC is the ID of an existing VPC network. Leave unset and the installer
// will create a new VPC network on your behalf.
VPC string `json:"vpc,omitempty"`

// Subnets is a list of existing subnet IDs. Leave unset and the installer
// will create new subnets in the VPC network on your behalf.
// +optional
Subnets []string `json:"subnets,omitempty"`
}

// ClusterResourceGroupName returns the name of the resource group for the cluster.
Expand Down
18 changes: 0 additions & 18 deletions pkg/types/ibmcloud/validation/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,8 @@ func ValidatePlatform(p *ibmcloud.Platform, fldPath *field.Path) field.ErrorList
allErrs = append(allErrs, field.NotSupported(fldPath.Child("region"), p.Region, regionShortNames))
}

allErrs = append(allErrs, validateVPCConfig(p, fldPath)...)

if p.DefaultMachinePlatform != nil {
allErrs = append(allErrs, ValidateMachinePool(p, p.DefaultMachinePlatform, fldPath.Child("defaultMachinePlatform"))...)
}
return allErrs
}

func validateVPCConfig(p *ibmcloud.Platform, path *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if p.VPC != "" || len(p.Subnets) > 0 || p.VPCResourceGroupName != "" {
if p.VPC == "" {
allErrs = append(allErrs, field.Required(path.Child("vpc"), "vpc is required when specifying subnets or vpcResourceGroupName"))
}
if len(p.Subnets) == 0 {
allErrs = append(allErrs, field.Required(path.Child("subnets"), "subnets is required when specifying vpc or vpcResourceGroupName"))
}
if p.VPCResourceGroupName == "" {
allErrs = append(allErrs, field.Required(path.Child("vpcResourceGroupName"), "vpcResourceGroupName is required when specifying vpc or subnets"))
}
}
return allErrs
}
87 changes: 0 additions & 87 deletions pkg/types/ibmcloud/validation/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,93 +61,6 @@ func TestValidatePlatform(t *testing.T) {
}(),
valid: true,
},
{
name: "valid vpc config",
platform: func() *ibmcloud.Platform {
p := validMinimalPlatform()
p.VPC = "valid-vpc-name"
p.Subnets = []string{"valid-compute-subnet-id", "valid-control-subnet-id"}
p.VPCResourceGroupName = "vpc-rg-name"
return p
}(),
valid: true,
},
{
name: "invalid vpc config missing vpc",
platform: func() *ibmcloud.Platform {
p := validMinimalPlatform()
p.Subnets = []string{"valid-compute-subnet-id", "valid-control-subnet-id"}
p.VPCResourceGroupName = "vpc-rg-name"
return p
}(),
valid: false,
},
{
name: "invalid vpc config missing subnets",
platform: func() *ibmcloud.Platform {
p := validMinimalPlatform()
p.VPC = "valid-vpc-name"
p.VPCResourceGroupName = "vpc-rg-name"
return p
}(),
valid: false,
},
{
name: "invalid vpc config missing vpcResourceGroupNname",
platform: func() *ibmcloud.Platform {
p := validMinimalPlatform()
p.VPC = "valid-vpc-name"
p.Subnets = []string{"valid-compute-subnet-id", "valid-control-subnet-id"}
return p
}(),
valid: false,
},
{
name: "invalid vpc config missing vpc and subnets",
platform: func() *ibmcloud.Platform {
p := validMinimalPlatform()
p.VPCResourceGroupName = "vpc-rg-name"
return p
}(),
valid: false,
},
{
name: "invalid vpc config missing vpcResourceGroupName",
platform: func() *ibmcloud.Platform {
p := validMinimalPlatform()
p.VPC = "valid-vpc-name"
p.Subnets = []string{"valid-compute-subnet-id", "valid-control-subnet-id"}
return p
}(),
valid: false,
},
{
name: "invalid vpc config missing vpc and subnets",
platform: func() *ibmcloud.Platform {
p := validMinimalPlatform()
p.VPCResourceGroupName = "vpc-rg-name"
return p
}(),
valid: false,
},
{
name: "invalid vpc config missing vpc and vpcResourceGroupName",
platform: func() *ibmcloud.Platform {
p := validMinimalPlatform()
p.Subnets = []string{"valid-compute-subnet-id", "valid-control-subnet-id"}
return p
}(),
valid: false,
},
{
name: "invalid vpc config missing subnets and vpcResourceGroupName",
platform: func() *ibmcloud.Platform {
p := validMinimalPlatform()
p.VPC = "valid-vpc-name"
return p
}(),
valid: false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
Expand Down