mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-31 13:50:01 +00:00 
			
		
		
		
	Remove ingress regex path requirement
This commit is contained in:
		| @@ -19,7 +19,6 @@ package validation | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"net" | ||||
| 	"regexp" | ||||
| 	"strings" | ||||
|  | ||||
| 	apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation" | ||||
| @@ -198,7 +197,6 @@ var ValidateIngressName = apimachineryvalidation.NameIsDNSSubdomain | ||||
|  | ||||
| // IngressValidationOptions cover beta to GA transitions for HTTP PathType | ||||
| type IngressValidationOptions struct { | ||||
| 	requireRegexPath     bool | ||||
| 	allowResourceBackend bool | ||||
| } | ||||
|  | ||||
| @@ -214,8 +212,6 @@ func ValidateIngressCreate(ingress *networking.Ingress, requestGV schema.GroupVe | ||||
| 	allErrs := field.ErrorList{} | ||||
| 	var opts IngressValidationOptions | ||||
| 	opts = IngressValidationOptions{ | ||||
| 		// TODO(robscott): Remove regex validation for 1.19. | ||||
| 		requireRegexPath: true, | ||||
| 		// TODO(cmluciano): Allow resource backend for 1.19. | ||||
| 		allowResourceBackend: false, | ||||
| 	} | ||||
| @@ -233,10 +229,6 @@ func ValidateIngressUpdate(ingress, oldIngress *networking.Ingress, requestGV sc | ||||
| 	allErrs := apivalidation.ValidateObjectMetaUpdate(&ingress.ObjectMeta, &oldIngress.ObjectMeta, field.NewPath("metadata")) | ||||
| 	var opts IngressValidationOptions | ||||
| 	opts = IngressValidationOptions{ | ||||
| 		// TODO(robscott): Remove regex validation for 1.19. | ||||
| 		// Only require regex path validation for this Ingress if the previous | ||||
| 		// version of the Ingress also passed that validation. | ||||
| 		requireRegexPath:     allPathsPassRegexValidation(oldIngress), | ||||
| 		allowResourceBackend: resourceBackendPresent(oldIngress), | ||||
| 	} | ||||
|  | ||||
| @@ -377,14 +369,6 @@ func validateHTTPIngressPath(path *networking.HTTPIngressPath, fldPath *field.Pa | ||||
| 		allErrs = append(allErrs, field.NotSupported(fldPath.Child("pathType"), *path.PathType, supportedPathTypes.List())) | ||||
| 	} | ||||
|  | ||||
| 	// TODO(robscott): Remove regex validation for 1.19. | ||||
| 	if opts.requireRegexPath { | ||||
| 		_, err := regexp.CompilePOSIX(path.Path) | ||||
| 		if err != nil { | ||||
| 			allErrs = append(allErrs, field.Invalid(fldPath.Child("path"), path.Path, "must be a valid regex")) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	allErrs = append(allErrs, validateIngressBackend(&path.Backend, fldPath.Child("backend"), opts)...) | ||||
| 	return allErrs | ||||
| } | ||||
| @@ -485,25 +469,6 @@ func validateIngressTypedLocalObjectReference(params *api.TypedLocalObjectRefere | ||||
| 	return allErrs | ||||
| } | ||||
|  | ||||
| // allPathsPassRegexValidation returns true if the Ingress has paths that all | ||||
| // match the Ingress path validation with requireRegexPath enabled. | ||||
| func allPathsPassRegexValidation(ingress *networking.Ingress) bool { | ||||
| 	for _, rule := range ingress.Spec.Rules { | ||||
| 		if rule.HTTP == nil { | ||||
| 			continue | ||||
| 		} | ||||
| 		for _, path := range rule.HTTP.Paths { | ||||
| 			if len(path.Path) == 0 { | ||||
| 				continue | ||||
| 			} | ||||
| 			if _, err := regexp.CompilePOSIX(path.Path); err != nil { | ||||
| 				return false | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| func resourceBackendPresent(ingress *networking.Ingress) bool { | ||||
| 	if ingress.Spec.Backend != nil && ingress.Spec.Backend.Resource != nil { | ||||
| 		return true | ||||
|   | ||||
		Reference in New Issue
	
	Block a user