@@ -6,7 +6,6 @@ package validation
66
77import (
88 "fmt"
9- "regexp"
109 "slices"
1110 "strings"
1211
@@ -20,9 +19,6 @@ import (
2019 apisaws "github.com/gardener/gardener-extension-provider-aws/pkg/apis/aws"
2120)
2221
23- // valid values for networks.vpc.gatewayEndpoints
24- var gatewayEndpointPattern = regexp .MustCompile (`^[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$` )
25-
2622// ValidateInfrastructureConfigAgainstCloudProfile validates the given `InfrastructureConfig` against the given `CloudProfile`.
2723func ValidateInfrastructureConfigAgainstCloudProfile (oldInfra , infra * apisaws.InfrastructureConfig , shoot * core.Shoot , cloudProfileSpec * gardencorev1beta1.CloudProfileSpec , fldPath * field.Path ) field.ErrorList {
2824 allErrs := field.ErrorList {}
@@ -95,9 +91,7 @@ func ValidateInfrastructureConfig(infra *apisaws.InfrastructureConfig, ipFamilie
9591 if len (infra .Networks .VPC .GatewayEndpoints ) > 0 {
9692 epsPath := networksPath .Child ("vpc" , "gatewayEndpoints" )
9793 for i , svc := range infra .Networks .VPC .GatewayEndpoints {
98- if ! gatewayEndpointPattern .MatchString (svc ) {
99- allErrs = append (allErrs , field .Invalid (epsPath .Index (i ), svc , "must be a valid domain name" ))
100- }
94+ allErrs = append (allErrs , validateGatewayEndpointName (svc , epsPath .Index (i ))... )
10195 }
10296 }
10397
@@ -110,6 +104,8 @@ func ValidateInfrastructureConfig(infra *apisaws.InfrastructureConfig, ipFamilie
110104 for i , zone := range infra .Networks .Zones {
111105 zonePath := networksPath .Child ("zones" ).Index (i )
112106
107+ allErrs = append (allErrs , validateZoneName (zone .Name , zonePath .Child ("name" ))... )
108+
113109 publicPath := zonePath .Child ("public" )
114110 cidrs = append (cidrs , cidrvalidation .NewCIDR (zone .Public , publicPath ))
115111 allErrs = append (allErrs , cidrvalidation .ValidateCIDRIsCanonical (publicPath , zone .Public )... )
@@ -134,9 +130,7 @@ func ValidateInfrastructureConfig(infra *apisaws.InfrastructureConfig, ipFamilie
134130 }
135131 referencedElasticIPAllocationIDs = append (referencedElasticIPAllocationIDs , * zone .ElasticIPAllocationID )
136132
137- if ! strings .HasPrefix (* zone .ElasticIPAllocationID , "eipalloc-" ) {
138- allErrs = append (allErrs , field .Invalid (zonePath .Child ("elasticIPAllocationID" ), * zone .ElasticIPAllocationID , "must start with eipalloc-" ))
139- }
133+ allErrs = append (allErrs , validateEipAllocationID (* zone .ElasticIPAllocationID , zonePath .Child ("elasticIPAllocationID" ))... )
140134 }
141135 }
142136
@@ -146,16 +140,23 @@ func ValidateInfrastructureConfig(infra *apisaws.InfrastructureConfig, ipFamilie
146140 allErrs = append (allErrs , nodes .ValidateSubset (workerCIDRs ... )... )
147141 }
148142
149- if (infra .Networks .VPC .ID == nil && infra .Networks .VPC .CIDR == nil ) || (infra .Networks .VPC .ID != nil && infra .Networks .VPC .CIDR != nil ) {
143+ idProvided := infra .Networks .VPC .ID != nil
144+ cidrProvided := infra .Networks .VPC .CIDR != nil
145+ switch {
146+ case ! idProvided && ! cidrProvided :
150147 allErrs = append (allErrs , field .Invalid (networksPath .Child ("vpc" ), infra .Networks .VPC , "must specify either a vpc id or a cidr" ))
151- } else if infra .Networks .VPC .CIDR != nil && infra .Networks .VPC .ID == nil && ! slices .Contains (ipFamilies , core .IPFamilyIPv6 ) {
148+ case idProvided && cidrProvided :
149+ allErrs = append (allErrs , field .Invalid (networksPath .Child ("vpc" ), infra .Networks .VPC , "cannot specify both vpc id and cidr" ))
150+ case cidrProvided && ! idProvided && ! slices .Contains (ipFamilies , core .IPFamilyIPv6 ):
152151 cidrPath := networksPath .Child ("vpc" , "cidr" )
153152 vpcCIDR := cidrvalidation .NewCIDR (* infra .Networks .VPC .CIDR , cidrPath )
154153 allErrs = append (allErrs , cidrvalidation .ValidateCIDRIsCanonical (cidrPath , * infra .Networks .VPC .CIDR )... )
155154 allErrs = append (allErrs , vpcCIDR .ValidateParse ()... )
156155 allErrs = append (allErrs , vpcCIDR .ValidateSubset (nodes )... )
157156 allErrs = append (allErrs , vpcCIDR .ValidateSubset (cidrs ... )... )
158157 allErrs = append (allErrs , vpcCIDR .ValidateNotOverlap (pods , services )... )
158+ case idProvided && ! cidrProvided :
159+ allErrs = append (allErrs , validateVpcID (* infra .Networks .VPC .ID , networksPath .Child ("vpc" , "id" ))... )
159160 }
160161
161162 // make sure that VPC cidrs don't overlap with each other
@@ -259,8 +260,8 @@ func ValidateIgnoreTags(fldPath *field.Path, ignoreTags *apisaws.IgnoreTags) fie
259260 keysPath := fldPath .Child ("keys" )
260261 for i , key := range ignoreTags .Keys {
261262 idxPath := keysPath .Index (i )
262- if key == "" {
263- allErrs = append (allErrs , field . Invalid ( idxPath , key , "ignored key must not be empty" ) )
263+ if errs := validateTagKey ( key , idxPath ); errs != nil {
264+ allErrs = append (allErrs , errs ... )
264265 continue
265266 }
266267 allErrs = append (allErrs , validateKeyIsReserved (idxPath , key )... )
@@ -270,8 +271,8 @@ func ValidateIgnoreTags(fldPath *field.Path, ignoreTags *apisaws.IgnoreTags) fie
270271 prefixesPath := fldPath .Child ("keyPrefixes" )
271272 for i , prefix := range ignoreTags .KeyPrefixes {
272273 idxPath := prefixesPath .Index (i )
273- if prefix == "" {
274- allErrs = append (allErrs , field . Invalid ( idxPath , prefix , "ignored key prefix must not be empty" ) )
274+ if errs := validateTagKey ( prefix , idxPath ); errs != nil {
275+ allErrs = append (allErrs , errs ... )
275276 continue
276277 }
277278 allErrs = append (allErrs , validatePrefixIncludesReservedKey (idxPath , prefix )... )
0 commit comments