Skip to content

Commit e18526f

Browse files
committed
Adding validation, test and field changes.
1 parent 6045e06 commit e18526f

File tree

5 files changed

+87
-1
lines changed

5 files changed

+87
-1
lines changed

data/data/install.openshift.io_installconfigs.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5304,6 +5304,39 @@ spec:
53045304
This resource group must be empty with no other resources when trying to use it for creating a cluster.
53055305
If empty, a new resource group will created for the cluster.
53065306
type: string
5307+
subnets:
5308+
description: Subnets is the list of subnets the user can bring
5309+
into the cluster to be used.
5310+
items:
5311+
description: SubnetSpec specifies the properties the subnet
5312+
needs to be used in the cluster.
5313+
properties:
5314+
cidr:
5315+
description: |-
5316+
SubnetCIDR specifies the CIDR for the subnet if it needs to be created.
5317+
Should not be mentioned if the subnet is a bring your own subnet.
5318+
items:
5319+
type: string
5320+
type: array
5321+
name:
5322+
description: Name of the subnet.
5323+
type: string
5324+
natGateway:
5325+
description: |-
5326+
NatGatewayName specifies the name of the NAT gateway to be created for this subnet.
5327+
Can only be used if the outbound type is set to MultiZoneNatGateway.
5328+
type: string
5329+
role:
5330+
description: Role specifies the actual role which the subnet
5331+
should be used in.
5332+
type: string
5333+
required:
5334+
- cidr
5335+
- name
5336+
- natGateway
5337+
- role
5338+
type: object
5339+
type: array
53075340
userProvisionedDNS:
53085341
default: Disabled
53095342
description: |-

pkg/asset/installconfig/azure/validation.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func Validate(client API, ic *types.InstallConfig) error {
7171
}
7272
allErrs = append(allErrs, validateMarketplaceImages(client, ic)...)
7373
allErrs = append(allErrs, validateBootDiagnostics(client, ic)...)
74+
// allErrs = append(allErrs, validateCustomSubnetsAndNatGateways(client, ic.Azure)...)
7475
return allErrs.ToAggregate()
7576
}
7677

@@ -995,3 +996,34 @@ func checkBootDiagnosticsURI(client API, diag *aztypes.BootDiagnostics, region s
995996
}
996997
return nil
997998
}
999+
1000+
// func validateCustomSubnetsAndNatGateways(client API, p *aztypes.Platform, fldPath *field.Path) field.ErrorList {
1001+
// var allErrs field.ErrorList
1002+
// ctx := context.TODO()
1003+
// for index, subnet := range p.Subnets {
1004+
// subnetPrefixes := subnet.SubnetCIDR
1005+
// if len(subnet.SubnetCIDR) == 0 {
1006+
// sub, err := client.GetControlPlaneSubnet(ctx, p.ResourceGroupName, p.VirtualNetwork, subnet.Name)
1007+
// if err != nil {
1008+
// allErrs = append(allErrs, field.Invalid(fldPath.Child(fmt.Sprintf("subnets[%d]", index)), subnet.Name, "unable to find subnet"))
1009+
// continue
1010+
// }
1011+
// subnetPrefixes = to.StringSlice(sub.AddressPrefixes)
1012+
// }
1013+
// vnet, err := client.GetVirtualNetwork(ctx, p.ResourceGroupName, p.VirtualNetwork)
1014+
// if err != nil {
1015+
// continue
1016+
// } else {
1017+
// // check if the vnet has the subnets.
1018+
// vnetSubnets := vnet.Subnets
1019+
// for _, subnetcidr := range subnetPrefixes {
1020+
// _, subnetRange, err := net.ParseCIDR(subnetcidr)
1021+
// if err != nil {
1022+
// allErrs = append(allErrs, field.Invalid(fldPath.Child(fmt.Sprintf("subnets[%d]", index)), subnetRange, "unable to translate subnet cidr"))
1023+
// continue
1024+
// }
1025+
// }
1026+
// }
1027+
// }
1028+
// return allErrs
1029+
// }

pkg/explain/printer_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ resource group.
341341
This resource group must be empty with no other resources when trying to use it for creating a cluster.
342342
If empty, a new resource group will created for the cluster.
343343
344+
subnets <[]object>
345+
Subnets is the list of subnets the user can bring into the cluster to be used.
346+
SubnetSpec specifies the properties the subnet needs to be used in the cluster.
347+
344348
userProvisionedDNS <string>
345349
Default: "Disabled"
346350
Valid Values: "Enabled","Disabled"

pkg/types/azure/validation/platform.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ func ValidatePlatform(p *azure.Platform, publish types.PublishingStrategy, fldPa
127127
allErrs = append(allErrs, field.Required(fldPath.Child("clusterOSImage"), fmt.Sprintf("clusterOSImage must not be set when the cloud name is %s", cloud)))
128128
}
129129
}
130+
for index, subnet := range p.Subnets {
131+
if subnet.NatGatewayName != "" && p.OutboundType != azure.NATGatewayMultiZoneOutboundType {
132+
allErrs = append(allErrs, field.Invalid(fldPath.Child("subnet").Index(index), subnet.NatGatewayName, "cannot specify nat gateway if outbound type is not MultiZoneNatGateway"))
133+
}
134+
}
130135

131136
return allErrs
132137
}
@@ -239,6 +244,7 @@ func findDuplicateTagKeys(tagSet map[string]string) error {
239244
var (
240245
validOutboundTypes = map[azure.OutboundType]struct{}{
241246
azure.LoadbalancerOutboundType: {},
247+
azure.NATGatewayMultiZoneOutboundType: {},
242248
azure.NATGatewaySingleZoneOutboundType: {},
243249
azure.UserDefinedRoutingOutboundType: {},
244250
}

pkg/types/azure/validation/platform_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func TestValidatePlatform(t *testing.T) {
134134
p.OutboundType = "random-egress"
135135
return p
136136
}(),
137-
expected: `^test-path\.outboundType: Unsupported value: "random-egress": supported values: "Loadbalancer", "NATGatewaySingleZone", "UserDefinedRouting"$`,
137+
expected: `^test-path\.outboundType: Unsupported value: "random-egress": supported values: "Loadbalancer", "MultiZoneNatGateway", "NATGatewaySingleZone", "UserDefinedRouting"$`,
138138
},
139139
{
140140
name: "invalid user defined type",
@@ -217,6 +217,17 @@ func TestValidatePlatform(t *testing.T) {
217217
}(),
218218
expected: `^test-path\.customerManagedKey: Invalid value: "-": invalid user assigned identity key for encryption$`,
219219
},
220+
{
221+
name: "mentioned nat gateway when outbound type is not multi zone",
222+
platform: func() *azure.Platform {
223+
p := validPlatform()
224+
p.Subnets = []azure.SubnetSpec{{
225+
NatGatewayName: "test-invalid",
226+
}}
227+
return p
228+
}(),
229+
expected: `^test-path\.subnet\[0\]: Invalid value: "test-invalid": cannot specify nat gateway if outbound type is not MultiZoneNatGateway$`,
230+
},
220231
}
221232
ic := types.InstallConfig{}
222233
for _, tc := range cases {

0 commit comments

Comments
 (0)