...

Source file src/sigs.k8s.io/gateway-api/apis/v1alpha2/validation/udproute.go

Documentation: sigs.k8s.io/gateway-api/apis/v1alpha2/validation

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package validation
    18  
    19  import (
    20  	"k8s.io/apimachinery/pkg/util/validation/field"
    21  
    22  	gatewayv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
    23  )
    24  
    25  // ValidateUDPRoute validates UDPRoute according to the Gateway API specification.
    26  // For additional details of the UDPRoute spec, refer to:
    27  // https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1alpha2.UDPRoute
    28  func ValidateUDPRoute(route *gatewayv1a2.UDPRoute) field.ErrorList {
    29  	return validateUDPRouteSpec(&route.Spec, field.NewPath("spec"))
    30  }
    31  
    32  // validateUDPRouteSpec validates that required fields of spec are set according to the
    33  // UDPRoute specification.
    34  func validateUDPRouteSpec(spec *gatewayv1a2.UDPRouteSpec, path *field.Path) field.ErrorList {
    35  	var errs field.ErrorList
    36  	path = path.Child("rules")
    37  
    38  	for i, rule := range spec.Rules {
    39  		for j, ref := range rule.BackendRefs {
    40  			// Avoid referencing to the loop variable.
    41  			ref := ref
    42  			errs = append(errs, validateBackendRefServicePort(&ref, path.Index(i).Child("backendRefs").Index(j))...)
    43  			errs = append(errs, validateParentRefs(spec.ParentRefs, path.Child("spec"))...)
    44  		}
    45  	}
    46  	return errs
    47  }
    48  

View as plain text