2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/ *  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Copyright  2022  The  Kubernetes  Authors .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Licensed  under  the  Apache  License ,  Version  2.0  ( the  "License" ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								you  may  not  use  this  file  except  in  compliance  with  the  License .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You  may  obtain  a  copy  of  the  License  at  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    http : //www.apache.org/licenses/LICENSE-2.0
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Unless  required  by  applicable  law  or  agreed  to  in  writing ,  software  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								distributed  under  the  License  is  distributed  on  an  "AS IS"  BASIS ,  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								WITHOUT  WARRANTIES  OR  CONDITIONS  OF  ANY  KIND ,  either  express  or  implied .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								See  the  License  for  the  specific  language  governing  permissions  and  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								limitations  under  the  License .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* /  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								package  validation  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"encoding/json" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"errors" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"fmt" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"regexp" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"strings" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									apiequality  "k8s.io/apimachinery/pkg/api/equality" 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									apimachineryvalidation  "k8s.io/apimachinery/pkg/api/validation" 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-04 17:03:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									metav1validation  "k8s.io/apimachinery/pkg/apis/meta/v1/validation" 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"k8s.io/apimachinery/pkg/runtime" 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 03:37:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"k8s.io/apimachinery/pkg/types" 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"k8s.io/apimachinery/pkg/util/sets" 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"k8s.io/apimachinery/pkg/util/validation" 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"k8s.io/apimachinery/pkg/util/validation/field" 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"k8s.io/apiserver/pkg/cel" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"k8s.io/apiserver/pkg/cel/environment" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									dracel  "k8s.io/dynamic-resource-allocation/cel" 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"k8s.io/dynamic-resource-allocation/structured" 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									corevalidation  "k8s.io/kubernetes/pkg/apis/core/validation" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"k8s.io/kubernetes/pkg/apis/resource" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  (  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// validateResourceDriverName reuses the validation of a CSI driver because
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// the allowed values are exactly the same.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									validateDriverName       =  corevalidation . ValidateCSIDriverName 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									validateDeviceName       =  corevalidation . ValidateDNS1123Label 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									validateDeviceClassName  =  corevalidation . ValidateDNS1123Subdomain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									validateRequestName      =  corevalidation . ValidateDNS1123Label 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validatePoolName ( name  string ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  name  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath ,  "" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  len ( name )  >  resource . PoolNameMaxLength  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 01:11:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . TooLong ( fldPath ,  ""  /*unused*/ ,  resource . PoolNameMaxLength ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										parts  :=  strings . Split ( name ,  "/" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  _ ,  part  :=  range  parts  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  corevalidation . ValidateDNS1123Subdomain ( part ,  fldPath ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// ValidateResourceClaim validates a ResourceClaim.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ValidateResourceClaim ( resourceClaim  * resource . ResourceClaim )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  corevalidation . ValidateObjectMeta ( & resourceClaim . ObjectMeta ,  true ,  corevalidation . ValidateResourceClaimName ,  field . NewPath ( "metadata" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateResourceClaimSpec ( & resourceClaim . Spec ,  field . NewPath ( "spec" ) ,  false ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// ValidateResourceClaimUpdate tests if an update to ResourceClaim is valid.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ValidateResourceClaimUpdate ( resourceClaim ,  oldClaim  * resource . ResourceClaim )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  corevalidation . ValidateObjectMetaUpdate ( & resourceClaim . ObjectMeta ,  & oldClaim . ObjectMeta ,  field . NewPath ( "metadata" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  apimachineryvalidation . ValidateImmutableField ( resourceClaim . Spec ,  oldClaim . Spec ,  field . NewPath ( "spec" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Because the spec is immutable, all CEL expressions in it must have been stored.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If the user tries an update, this is not true and checking is less strict, but
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// as there are errors, it doesn't matter.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateResourceClaimSpec ( & resourceClaim . Spec ,  field . NewPath ( "spec" ) ,  true ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// ValidateResourceClaimStatusUpdate tests if an update to the status of a ResourceClaim is valid.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ValidateResourceClaimStatusUpdate ( resourceClaim ,  oldClaim  * resource . ResourceClaim )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  corevalidation . ValidateObjectMetaUpdate ( & resourceClaim . ObjectMeta ,  & oldClaim . ObjectMeta ,  field . NewPath ( "metadata" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									requestNames  :=  gatherRequestNames ( & resourceClaim . Spec . Devices ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateResourceClaimStatusUpdate ( & resourceClaim . Status ,  & oldClaim . Status ,  resourceClaim . DeletionTimestamp  !=  nil ,  requestNames ,  field . NewPath ( "status" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateResourceClaimSpec ( spec  * resource . ResourceClaimSpec ,  fldPath  * field . Path ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  field . ErrorList { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDeviceClaim ( & spec . Devices ,  fldPath . Child ( "devices" ) ,  stored ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDeviceClaim ( deviceClaim  * resource . DeviceClaim ,  fldPath  * field . Path ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  field . ErrorList { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									requestNames  :=  gatherRequestNames ( deviceClaim ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSet ( deviceClaim . Requests ,  resource . DeviceRequestsMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( request  resource . DeviceRequest ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  validateDeviceRequest ( request ,  fldPath ,  stored ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( request  resource . DeviceRequest )  ( string ,  string )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  request . Name ,  "name" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fldPath . Child ( "requests" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSlice ( deviceClaim . Constraints ,  resource . DeviceConstraintsMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( constraint  resource . DeviceConstraint ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  validateDeviceConstraint ( constraint ,  fldPath ,  requestNames ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ,  fldPath . Child ( "constraints" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSlice ( deviceClaim . Config ,  resource . DeviceConfigMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( config  resource . DeviceClaimConfiguration ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 16:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  validateDeviceClaimConfiguration ( config ,  fldPath ,  requestNames ,  stored ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ,  fldPath . Child ( "config" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  requestNames  map [ string ] sets . Set [ string ]  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( r  requestNames )  Has ( s  string )  bool  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									segments  :=  strings . Split ( s ,  "/" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If there are more than one / in the string, we
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// know there can't be any match.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( segments )  >  2  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If the first segment doesn't have a match, we
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// don't need to check the other one.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									subRequestNames ,  found  :=  r [ segments [ 0 ] ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ! found  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( segments )  ==  1  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If the first segment matched and we have another one,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// check for a match for that too.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  subRequestNames . Has ( segments [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  gatherRequestNames ( deviceClaim  * resource . DeviceClaim )  requestNames  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									requestNames  :=  make ( requestNames ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  request  :=  range  deviceClaim . Requests  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  len ( request . FirstAvailable )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											requestNames [ request . Name ]  =  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										subRequestNames  :=  sets . New [ string ] ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  _ ,  subRequest  :=  range  request . FirstAvailable  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											subRequestNames . Insert ( subRequest . Name ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										requestNames [ request . Name ]  =  subRequestNames 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  requestNames 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  gatherAllocatedDevices ( allocationResult  * resource . DeviceAllocationResult )  sets . Set [ structured . DeviceID ]  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allocatedDevices  :=  sets . New [ structured . DeviceID ] ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  result  :=  range  allocationResult . Results  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 17:49:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										deviceID  :=  structured . MakeDeviceID ( result . Driver ,  result . Pool ,  result . Device ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allocatedDevices . Insert ( deviceID ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allocatedDevices 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDeviceRequest ( request  resource . DeviceRequest ,  fldPath  * field . Path ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  validateRequestName ( request . Name ,  fldPath . Child ( "name" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 04:47:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  request . DeviceClassName  ==  ""  &&  len ( request . FirstAvailable )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath ,  "exactly one of `deviceClassName` or `firstAvailable` must be specified" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  if  request . DeviceClassName  !=  ""  &&  len ( request . FirstAvailable )  >  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath ,  nil ,  "exactly one of `deviceClassName` or `firstAvailable` must be specified" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  if  request . DeviceClassName  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateDeviceClass ( request . DeviceClassName ,  fldPath . Child ( "deviceClassName" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateSelectorSlice ( request . Selectors ,  fldPath . Child ( "selectors" ) ,  stored ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateDeviceAllocationMode ( request . AllocationMode ,  request . Count ,  fldPath . Child ( "allocationMode" ) ,  fldPath . Child ( "count" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  if  len ( request . FirstAvailable )  >  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  request . Selectors  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Invalid ( fldPath . Child ( "selectors" ) ,  request . Selectors ,  "must not be specified when firstAvailable is set" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  request . AllocationMode  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Invalid ( fldPath . Child ( "allocationMode" ) ,  request . AllocationMode ,  "must not be specified when firstAvailable is set" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  request . Count  !=  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Invalid ( fldPath . Child ( "count" ) ,  request . Count ,  "must not be specified when firstAvailable is set" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  request . AdminAccess  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Invalid ( fldPath . Child ( "adminAccess" ) ,  request . AdminAccess ,  "must not be specified when firstAvailable is set" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateSet ( request . FirstAvailable ,  resource . FirstAvailableDeviceRequestMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											func ( subRequest  resource . DeviceSubRequest ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  validateDeviceSubRequest ( subRequest ,  fldPath ,  stored ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											func ( subRequest  resource . DeviceSubRequest )  ( string ,  string )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  subRequest . Name ,  "name" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											fldPath . Child ( "firstAvailable" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  validateDeviceSubRequest ( subRequest  resource . DeviceSubRequest ,  fldPath  * field . Path ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  validateRequestName ( subRequest . Name ,  fldPath . Child ( "name" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDeviceClass ( subRequest . DeviceClassName ,  fldPath . Child ( "deviceClassName" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSelectorSlice ( subRequest . Selectors ,  fldPath . Child ( "selectors" ) ,  stored ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDeviceAllocationMode ( subRequest . AllocationMode ,  subRequest . Count ,  fldPath . Child ( "allocationMode" ) ,  fldPath . Child ( "count" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  validateDeviceAllocationMode ( deviceAllocationMode  resource . DeviceAllocationMode ,  count  int64 ,  allocModeFldPath ,  countFldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									switch  deviceAllocationMode  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									case  resource . DeviceAllocationModeAll : 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  count  !=  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Invalid ( countFldPath ,  count ,  fmt . Sprintf ( "must not be specified when allocationMode is '%s'" ,  deviceAllocationMode ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  resource . DeviceAllocationModeExactCount : 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  count  <=  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Invalid ( countFldPath ,  count ,  "must be greater than zero" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									default : 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . NotSupported ( allocModeFldPath ,  deviceAllocationMode ,  [ ] resource . DeviceAllocationMode { resource . DeviceAllocationModeAll ,  resource . DeviceAllocationModeExactCount } ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDeviceClass ( deviceClass  string ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  deviceClass  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath ,  "" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateDeviceClassName ( deviceClass ,  fldPath ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateSelectorSlice ( selectors  [ ] resource . DeviceSelector ,  fldPath  * field . Path ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  validateSlice ( selectors ,  resource . DeviceSelectorsMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( selector  resource . DeviceSelector ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  validateSelector ( selector ,  fldPath ,  stored ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fldPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateSelector ( selector  resource . DeviceSelector ,  fldPath  * field . Path ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  selector . CEL  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath . Child ( "cel" ) ,  "" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateCELSelector ( * selector . CEL ,  fldPath . Child ( "cel" ) ,  stored ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateCELSelector ( celSelector  resource . CELDeviceSelector ,  fldPath  * field . Path ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									envType  :=  environment . NewExpressions 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  stored  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										envType  =  environment . StoredExpressions 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-01 00:09:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( celSelector . Expression )  >  resource . CELSelectorExpressionMaxLength  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 01:11:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . TooLong ( fldPath . Child ( "expression" ) ,  ""  /*unused*/ ,  resource . CELSelectorExpressionMaxLength ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-01 00:09:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Don't bother compiling too long expressions.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-24 03:15:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  :=  dracel . GetCompiler ( ) . CompileCELExpression ( celSelector . Expression ,  dracel . Options { EnvType :  & envType } ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  result . Error  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  convertCELErrorToValidationError ( fldPath . Child ( "expression" ) ,  celSelector . Expression ,  result . Error ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-01 00:09:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  if  result . MaxCost  >  resource . CELSelectorExpressionMaxCost  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Forbidden ( fldPath . Child ( "expression" ) ,  "too complex, exceeds cost limit" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-01 00:09:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  convertCELErrorToValidationError ( fldPath  * field . Path ,  expression  string ,  err  error )  * field . Error  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  celErr  * cel . Error 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  errors . As ( err ,  & celErr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										switch  celErr . Type  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  cel . ErrorTypeRequired : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  field . Required ( fldPath ,  celErr . Detail ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  cel . ErrorTypeInvalid : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  field . Invalid ( fldPath ,  expression ,  celErr . Detail ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  cel . ErrorTypeInternal : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  field . InternalError ( fldPath ,  celErr ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  field . InternalError ( fldPath ,  fmt . Errorf ( "unsupported error type: %w" ,  err ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDeviceConstraint ( constraint  resource . DeviceConstraint ,  fldPath  * field . Path ,  requestNames  requestNames )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSet ( constraint . Requests ,  resource . DeviceRequestsMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( name  string ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  validateRequestNameRef ( name ,  fldPath ,  requestNames ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										stringKey ,  fldPath . Child ( "requests" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  constraint . MatchAttribute  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath . Child ( "matchAttribute" ) ,  "" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-30 17:53:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateFullyQualifiedName ( * constraint . MatchAttribute ,  fldPath . Child ( "matchAttribute" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDeviceClaimConfiguration ( config  resource . DeviceClaimConfiguration ,  fldPath  * field . Path ,  requestNames  requestNames ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSet ( config . Requests ,  resource . DeviceRequestsMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( name  string ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  validateRequestNameRef ( name ,  fldPath ,  requestNames ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ,  stringKey ,  fldPath . Child ( "requests" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 16:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDeviceConfiguration ( config . DeviceConfiguration ,  fldPath ,  stored ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateRequestNameRef ( name  string ,  fldPath  * field . Path ,  requestNames  requestNames )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									segments  :=  strings . Split ( name ,  "/" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( segments )  >  2  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath ,  name ,  "must be the name of a request in the claim or the name of a request and a subrequest separated by '/'" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i  :=  range  segments  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateRequestName ( segments [ i ] ,  fldPath ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ! requestNames . Has ( name )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath ,  name ,  "must be the name of a request in the claim or the name of a request and a subrequest separated by '/'" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 16:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDeviceConfiguration ( config  resource . DeviceConfiguration ,  fldPath  * field . Path ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  config . Opaque  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath . Child ( "opaque" ) ,  "" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 16:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateOpaqueConfiguration ( * config . Opaque ,  fldPath . Child ( "opaque" ) ,  stored ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 16:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateOpaqueConfiguration ( config  resource . OpaqueDeviceConfiguration ,  fldPath  * field . Path ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDriverName ( config . Driver ,  fldPath . Child ( "driver" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 21:44:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateRawExtension ( config . Parameters ,  fldPath . Child ( "parameters" ) ,  stored ,  resource . OpaqueParametersMaxLength ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateResourceClaimStatusUpdate ( status ,  oldStatus  * resource . ResourceClaimStatus ,  claimDeleted  bool ,  requestNames  requestNames ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSet ( status . ReservedFor ,  resource . ResourceClaimReservedForMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										validateResourceClaimUserReference , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( consumer  resource . ResourceClaimConsumerReference )  ( types . UID ,  string )  {  return  consumer . UID ,  "uid"  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fldPath . Child ( "reservedFor" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-04 17:03:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allocatedDevices  sets . Set [ structured . DeviceID ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  status . Allocation  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allocatedDevices  =  gatherAllocatedDevices ( & status . Allocation . Devices ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-04 17:03:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSet ( status . Devices ,  - 1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( device  resource . AllocatedDeviceStatus ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  validateDeviceStatus ( device ,  fldPath ,  allocatedDevices ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( device  resource . AllocatedDeviceStatus )  ( structured . DeviceID ,  string )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 17:49:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  structured . MakeDeviceID ( device . Driver ,  device . Pool ,  device . Device ) ,  "deviceID" 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-04 17:03:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fldPath . Child ( "devices" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Now check for invariants that must be valid for a ResourceClaim.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( status . ReservedFor )  >  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  status . Allocation  ==  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Forbidden ( fldPath . Child ( "reservedFor" ) ,  "may not be specified when `allocated` is not set" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Items may be removed from ReservedFor while the claim is meant to be deallocated,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// but not added.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-11 22:08:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  claimDeleted  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												oldSet  :=  sets . New ( oldStatus . ReservedFor ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												newSet  :=  sets . New ( status . ReservedFor ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												newItems  :=  newSet . Difference ( oldSet ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  len ( newItems )  >  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													allErrs  =  append ( allErrs ,  field . Forbidden ( fldPath . Child ( "reservedFor" ) ,  "new entries may not be added while `deallocationRequested` or `deletionTimestamp` are set" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-04 14:03:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Updates to a populated status.Allocation are not allowed.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Unmodified fields don't need to be validated again and,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in this particular case, must not be validated again because
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// validation for new results is tighter than it was before.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  oldStatus . Allocation  !=  nil  &&  status . Allocation  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  apimachineryvalidation . ValidateImmutableField ( status . Allocation ,  oldStatus . Allocation ,  fldPath . Child ( "allocation" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-04 14:03:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  if  status . Allocation  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 16:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateAllocationResult ( status . Allocation ,  fldPath . Child ( "allocation" ) ,  requestNames ,  false ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-07 23:09:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateResourceClaimUserReference ( ref  resource . ResourceClaimConsumerReference ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ref . Resource  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath . Child ( "resource" ) ,  "" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ref . Name  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath . Child ( "name" ) ,  "" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ref . UID  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath . Child ( "uid" ) ,  "" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-04 14:03:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// validateAllocationResult enforces constraints for *new* results, which in at
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// least one case (admin access) are more strict than before. Therefore it
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// may not be called to re-validate results which were stored earlier.
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateAllocationResult ( allocation  * resource . AllocationResult ,  fldPath  * field . Path ,  requestNames  requestNames ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2023-03-07 23:09:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 16:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDeviceAllocationResult ( allocation . Devices ,  fldPath . Child ( "devices" ) ,  requestNames ,  stored ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  allocation . NodeSelector  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-23 17:28:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  corevalidation . ValidateNodeSelector ( allocation . NodeSelector ,  false ,  fldPath . Child ( "nodeSelector" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-07 23:09:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDeviceAllocationResult ( allocation  resource . DeviceAllocationResult ,  fldPath  * field . Path ,  requestNames  requestNames ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSlice ( allocation . Results ,  resource . AllocationResultsMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( result  resource . DeviceRequestAllocationResult ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  validateDeviceRequestAllocationResult ( result ,  fldPath ,  requestNames ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ,  fldPath . Child ( "results" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSlice ( allocation . Config ,  2 * resource . DeviceConfigMaxSize ,  /* class + claim */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( config  resource . DeviceAllocationConfiguration ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 16:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  validateDeviceAllocationConfiguration ( config ,  fldPath ,  requestNames ,  stored ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ,  fldPath . Child ( "config" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDeviceRequestAllocationResult ( result  resource . DeviceRequestAllocationResult ,  fldPath  * field . Path ,  requestNames  requestNames )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateRequestNameRef ( result . Request ,  fldPath . Child ( "request" ) ,  requestNames ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDriverName ( result . Driver ,  fldPath . Child ( "driver" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validatePoolName ( result . Pool ,  fldPath . Child ( "pool" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDeviceName ( result . Device ,  fldPath . Child ( "device" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 03:28:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDeviceAllocationConfiguration ( config  resource . DeviceAllocationConfiguration ,  fldPath  * field . Path ,  requestNames  requestNames ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateAllocationConfigSource ( config . Source ,  fldPath . Child ( "source" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSet ( config . Requests ,  resource . DeviceRequestsMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( name  string ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  validateRequestNameRef ( name ,  fldPath ,  requestNames ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ,  stringKey ,  fldPath . Child ( "requests" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 16:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDeviceConfiguration ( config . DeviceConfiguration ,  fldPath ,  stored ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateAllocationConfigSource ( source  resource . AllocationConfigSource ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									switch  source  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  "" : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath ,  "" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  resource . AllocationConfigSourceClaim ,  resource . AllocationConfigSourceClass : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . NotSupported ( fldPath ,  source ,  [ ] resource . AllocationConfigSource { resource . AllocationConfigSourceClaim ,  resource . AllocationConfigSourceClass } ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-31 11:10:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// ValidateDeviceClass validates a DeviceClass.
  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ValidateDeviceClass ( class  * resource . DeviceClass )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  corevalidation . ValidateObjectMeta ( & class . ObjectMeta ,  false ,  corevalidation . ValidateClassName ,  field . NewPath ( "metadata" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDeviceClassSpec ( & class . Spec ,  nil ,  field . NewPath ( "spec" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-31 11:10:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// ValidateDeviceClassUpdate tests if an update to DeviceClass is valid.
  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ValidateDeviceClassUpdate ( class ,  oldClass  * resource . DeviceClass )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  corevalidation . ValidateObjectMetaUpdate ( & class . ObjectMeta ,  & oldClass . ObjectMeta ,  field . NewPath ( "metadata" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDeviceClassSpec ( & class . Spec ,  & oldClass . Spec ,  field . NewPath ( "spec" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  validateDeviceClassSpec ( spec ,  oldSpec  * resource . DeviceClassSpec ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2023-01-27 03:37:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// If the selectors are exactly as before, we treat the CEL expressions as "stored".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Any change, including merely reordering selectors, triggers validation as new
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// expressions.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stored  :=  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  oldSpec  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										stored  =  apiequality . Semantic . DeepEqual ( spec . Selectors ,  oldSpec . Selectors ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 03:37:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSlice ( spec . Selectors ,  resource . DeviceSelectorsMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( selector  resource . DeviceSelector ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  validateSelector ( selector ,  fldPath ,  stored ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fldPath . Child ( "selectors" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 16:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Same logic as above for configs.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  oldSpec  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										stored  =  apiequality . Semantic . DeepEqual ( spec . Config ,  oldSpec . Config ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSlice ( spec . Config ,  resource . DeviceConfigMaxSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( config  resource . DeviceClassConfiguration ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  validateDeviceClassConfiguration ( config ,  fldPath ,  stored ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fldPath . Child ( "config" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 03:37:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 16:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDeviceClassConfiguration ( config  resource . DeviceClassConfiguration ,  fldPath  * field . Path ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  validateDeviceConfiguration ( config . DeviceConfiguration ,  fldPath ,  stored ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// ValidateResourceClaimTemplate validates a ResourceClaimTemplate.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ValidateResourceClaimTemplate ( template  * resource . ResourceClaimTemplate )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2023-03-14 18:58:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  :=  corevalidation . ValidateObjectMeta ( & template . ObjectMeta ,  true ,  corevalidation . ValidateResourceClaimTemplateName ,  field . NewPath ( "metadata" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateResourceClaimTemplateSpec ( & template . Spec ,  field . NewPath ( "spec" ) ,  false ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateResourceClaimTemplateSpec ( spec  * resource . ResourceClaimTemplateSpec ,  fldPath  * field . Path ,  stored  bool )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									allErrs  :=  corevalidation . ValidateTemplateObjectMeta ( & spec . ObjectMeta ,  fldPath . Child ( "metadata" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateResourceClaimSpec ( & spec . Spec ,  fldPath . Child ( "spec" ) ,  stored ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// ValidateResourceClaimTemplateUpdate tests if an update to template is valid.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ValidateResourceClaimTemplateUpdate ( template ,  oldTemplate  * resource . ResourceClaimTemplate )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									allErrs  :=  corevalidation . ValidateObjectMetaUpdate ( & template . ObjectMeta ,  & oldTemplate . ObjectMeta ,  field . NewPath ( "metadata" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  apimachineryvalidation . ValidateImmutableField ( template . Spec ,  oldTemplate . Spec ,  field . NewPath ( "spec" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Because the spec is immutable, all CEL expressions in it must have been stored.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If the user tries an update, this is not true and checking is less strict, but
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// as there are errors, it doesn't matter.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateResourceClaimTemplateSpec ( & template . Spec ,  field . NewPath ( "spec" ) ,  true ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-04 21:01:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-11-06 01:04:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  validateNodeName ( name  string ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  msg  :=  range  corevalidation . ValidateNodeName ( name ,  false )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath ,  name ,  msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-07 17:14:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// ValidateResourceSlice tests if a ResourceSlice object is valid.
  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ValidateResourceSlice ( slice  * resource . ResourceSlice )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  corevalidation . ValidateObjectMeta ( & slice . ObjectMeta ,  false ,  apimachineryvalidation . NameIsDNSSubdomain ,  field . NewPath ( "metadata" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateResourceSliceSpec ( & slice . Spec ,  nil ,  field . NewPath ( "spec" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-31 11:10:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// ValidateResourceSliceUpdate tests if a ResourceSlice update is valid.
  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ValidateResourceSliceUpdate ( resourceSlice ,  oldResourceSlice  * resource . ResourceSlice )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  corevalidation . ValidateObjectMetaUpdate ( & resourceSlice . ObjectMeta ,  & oldResourceSlice . ObjectMeta ,  field . NewPath ( "metadata" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateResourceSliceSpec ( & resourceSlice . Spec ,  & oldResourceSlice . Spec ,  field . NewPath ( "spec" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  validateResourceSliceSpec ( spec ,  oldSpec  * resource . ResourceSliceSpec ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDriverName ( spec . Driver ,  fldPath . Child ( "driver" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateResourcePool ( spec . Pool ,  fldPath . Child ( "pool" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  oldSpec  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  apimachineryvalidation . ValidateImmutableField ( spec . Pool . Name ,  oldSpec . Pool . Name ,  fldPath . Child ( "pool" ,  "name" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  apimachineryvalidation . ValidateImmutableField ( spec . Driver ,  oldSpec . Driver ,  fldPath . Child ( "driver" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  apimachineryvalidation . ValidateImmutableField ( spec . NodeName ,  oldSpec . NodeName ,  fldPath . Child ( "nodeName" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-31 11:10:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									setFields  :=  make ( [ ] string ,  0 ,  3 ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  spec . NodeName  !=  ""  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-31 11:10:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										setFields  =  append ( setFields ,  "`nodeName`" ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateNodeName ( spec . NodeName ,  fldPath . Child ( "nodeName" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  spec . NodeSelector  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-31 11:10:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										setFields  =  append ( setFields ,  "`nodeSelector`" ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-23 17:28:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  corevalidation . ValidateNodeSelector ( spec . NodeSelector ,  false ,  fldPath . Child ( "nodeSelector" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  len ( spec . NodeSelector . NodeSelectorTerms )  !=  1  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// This additional constraint simplifies merging of different selectors
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// when devices are allocated from different slices.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-25 00:52:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Invalid ( fldPath . Child ( "nodeSelector" ,  "nodeSelectorTerms" ) ,  spec . NodeSelector . NodeSelectorTerms ,  "must have exactly one node selector term" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  spec . AllNodes  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-31 11:10:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										setFields  =  append ( setFields ,  "`allNodes`" ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 22:22:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-31 11:10:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									switch  len ( setFields )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									case  0 : 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath ,  "exactly one of `nodeName`, `nodeSelector`, or `allNodes` is required" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									case  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									default : 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-31 11:10:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath ,  fmt . Sprintf ( "{%s}" ,  strings . Join ( setFields ,  ", " ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"exactly one of `nodeName`, `nodeSelector`, or `allNodes` is required, but multiple fields are set" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSet ( spec . Devices ,  resource . ResourceSliceMaxDevices ,  validateDevice , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										func ( device  resource . Device )  ( string ,  string )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  device . Name ,  "name" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ,  fldPath . Child ( "devices" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateResourcePool ( pool  resource . ResourcePool ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validatePoolName ( pool . Name ,  fldPath . Child ( "name" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  pool . ResourceSliceCount  <=  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath . Child ( "resourceSliceCount" ) ,  pool . ResourceSliceCount ,  "must be greater than zero" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  pool . Generation  <  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath . Child ( "generation" ) ,  pool . Generation ,  "must be greater than or equal to zero" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDevice ( device  resource . Device ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDeviceName ( device . Name ,  fldPath . Child ( "name" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  device . Basic  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath . Child ( "basic" ) ,  "" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateBasicDevice ( * device . Basic ,  fldPath . Child ( "basic" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateBasicDevice ( device  resource . BasicDevice ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Warn about exceeding the maximum length only once. If any individual
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// field is too large, then so is the combination.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-25 00:52:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									maxKeyLen  :=  resource . DeviceMaxDomainLength  +  1  +  resource . DeviceMaxIDLength 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateMap ( device . Attributes ,  - 1 ,  maxKeyLen ,  validateQualifiedName ,  validateDeviceAttribute ,  fldPath . Child ( "attributes" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-26 22:56:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateMap ( device . Capacity ,  - 1 ,  maxKeyLen ,  validateQualifiedName ,  validateDeviceCapacity ,  fldPath . Child ( "capacity" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  combinedLen ,  max  :=  len ( device . Attributes ) + len ( device . Capacity ) ,  resource . ResourceSliceMaxAttributesAndCapacitiesPerDevice ;  combinedLen  >  max  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath ,  combinedLen ,  fmt . Sprintf ( "the total number of attributes and capacities must not exceed %d" ,  max ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  (  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									numericIdentifier  =  ` (0|[1-9]\d*) ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									preReleaseIdentifier  =  ` (0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*) ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									buildIdentifier  =  ` [0-9a-zA-Z-]+ ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									semverRe  =  regexp . MustCompile ( ` ^ `  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// dot-separated version segments (e.g. 1.2.3)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										numericIdentifier  +  ` \. `  +  numericIdentifier  +  ` \. `  +  numericIdentifier  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// optional dot-separated prerelease segments (e.g. -alpha.PRERELEASE.1)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										` (- `  +  preReleaseIdentifier  +  ` (\. `  +  preReleaseIdentifier  +  ` )*)? `  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// optional dot-separated build identifier segments (e.g. +build.id.20240305)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										` (\+ `  +  buildIdentifier  +  ` (\. `  +  buildIdentifier  +  ` )*)? `  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										` $ ` ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  validateDeviceAttribute ( attribute  resource . DeviceAttribute ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									numFields  :=  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  attribute . BoolValue  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										numFields ++ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  attribute . IntValue  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										numFields ++ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  attribute . StringValue  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  len ( * attribute . StringValue )  >  resource . DeviceAttributeMaxValueLength  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 01:11:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . TooLong ( fldPath . Child ( "string" ) ,  ""  /*unused*/ ,  resource . DeviceAttributeMaxValueLength ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										numFields ++ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  attribute . VersionValue  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										numFields ++ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ! semverRe . MatchString ( * attribute . VersionValue )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Invalid ( fldPath . Child ( "version" ) ,  * attribute . VersionValue ,  "must be a string compatible with semver.org spec 2.0.0" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  len ( * attribute . VersionValue )  >  resource . DeviceAttributeMaxValueLength  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 01:11:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . TooLong ( fldPath . Child ( "version" ) ,  ""  /*unused*/ ,  resource . DeviceAttributeMaxValueLength ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 22:22:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									switch  numFields  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									case  0 : 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath ,  "exactly one value must be specified" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									case  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Okay.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									default : 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-25 00:52:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath ,  attribute ,  "exactly one value must be specified" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-26 22:56:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateDeviceCapacity ( capacity  resource . DeviceCapacity ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Any parsed quantity is valid.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  nil 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateQualifiedName ( name  resource . QualifiedName ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  name  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath ,  "name required" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									parts  :=  strings . Split ( string ( name ) ,  "/" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									switch  len ( parts )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateCIdentifier ( parts [ 0 ] ,  fldPath ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  2 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  len ( parts [ 0 ] )  ==  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-25 00:52:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Required ( fldPath ,  "the domain must not be empty" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  validateDriverName ( parts [ 0 ] ,  fldPath ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  len ( parts [ 1 ] )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Required ( fldPath ,  "the name must not be empty" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  validateCIdentifier ( parts [ 1 ] ,  fldPath ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateFullyQualifiedName ( name  resource . FullyQualifiedName ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  validateQualifiedName ( resource . QualifiedName ( name ) ,  fldPath ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-25 00:52:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// validateQualifiedName checks that the name isn't empty and both parts are valid.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// What we need to enforce here is that there really is a domain.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  name  !=  ""  &&  ! strings . Contains ( string ( name ) ,  "/" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath ,  name ,  "must include a domain" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateCIdentifier ( id  string ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( id )  >  resource . DeviceMaxIDLength  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 01:11:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . TooLong ( fldPath ,  ""  /*unused*/ ,  resource . DeviceMaxIDLength ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  msg  :=  range  validation . IsCIdentifier ( id )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . TypeInvalid ( fldPath ,  id ,  msg ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// validateSlice ensures that a slice does not exceed a certain maximum size
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// and that all entries are valid.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// A negative maxSize disables the length check.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  validateSlice [ T  any ] ( slice  [ ] T ,  maxSize  int ,  validateItem  func ( T ,  * field . Path )  field . ErrorList ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  i ,  item  :=  range  slice  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										idxPath  :=  fldPath . Index ( i ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateItem ( item ,  idxPath ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 22:22:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  maxSize  >=  0  &&  len ( slice )  >  maxSize  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Dumping the entire field into the error message is likely to be too long,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// in particular when it is already beyond the maximum size. Instead this
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// just shows the number of entries.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-05 07:16:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . TooMany ( fldPath ,  len ( slice ) ,  maxSize ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// validateSet ensures that a slice contains no duplicates, does not
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// exceed a certain maximum size and that all entries are valid.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  validateSet [ T  any ,  K  comparable ] ( slice  [ ] T ,  maxSize  int ,  validateItem  func ( item  T ,  fldPath  * field . Path )  field . ErrorList ,  itemKey  func ( T )  ( K ,  string ) ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  :=  validateSlice ( slice ,  maxSize ,  validateItem ,  fldPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allItems  :=  sets . New [ K ] ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  i ,  item  :=  range  slice  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										idxPath  :=  fldPath . Index ( i ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										key ,  fieldName  :=  itemKey ( item ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										childPath  :=  idxPath 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  fieldName  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											childPath  =  childPath . Child ( fieldName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  allItems . Has ( key )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											allErrs  =  append ( allErrs ,  field . Duplicate ( childPath ,  key ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											allItems . Insert ( key ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// stringKey uses the item itself as a key for validateSet.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  stringKey ( item  string )  ( string ,  string )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  item ,  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// validateMap validates keys, items and the maximum length of a map.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// A negative maxSize disables the length check.
  
						 
					
						
							
								
									
										
										
										
											2024-09-25 00:52:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Keys larger than truncateKeyLen get truncated in the middle. A very
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// small limit gets increased because it is okay to include more details.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// This is not used for validation of keys, which has to be done by
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// the callback function.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  validateMap [ K  ~ string ,  T  any ] ( m  map [ K ] T ,  maxSize ,  truncateKeyLen  int ,  validateKey  func ( K ,  * field . Path )  field . ErrorList ,  validateItem  func ( T ,  * field . Path )  field . ErrorList ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  maxSize  >=  0  &&  len ( m )  >  maxSize  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-05 07:16:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . TooMany ( fldPath ,  len ( m ) ,  maxSize ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  key ,  item  :=  range  m  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-25 00:52:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										keyPath  :=  fldPath . Key ( truncateIfTooLong ( string ( key ) ,  truncateKeyLen ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateKey ( key ,  keyPath ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateItem ( item ,  keyPath ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-18 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-14 21:38:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-09-25 00:52:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  truncateIfTooLong ( str  string ,  maxLen  int )  string  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The caller was overly restrictive. Increase the length to something reasonable
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// (https://github.com/kubernetes/kubernetes/pull/127511#discussion_r1826206362).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  maxLen  <  16  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										maxLen  =  16 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( str )  <=  maxLen  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  str 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ellipsis  :=  "..." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									remaining  :=  maxLen  -  len ( ellipsis ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  str [ 0 : ( remaining + 1 ) / 2 ]  +  ellipsis  +  str [ len ( str ) - remaining / 2 : ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  validateDeviceStatus ( device  resource . AllocatedDeviceStatus ,  fldPath  * field . Path ,  allocatedDevices  sets . Set [ structured . DeviceID ] )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 01:30:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDriverName ( device . Driver ,  fldPath . Child ( "driver" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validatePoolName ( device . Pool ,  fldPath . Child ( "pool" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateDeviceName ( device . Device ,  fldPath . Child ( "device" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 17:49:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									deviceID  :=  structured . MakeDeviceID ( device . Driver ,  device . Pool ,  device . Device ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ! allocatedDevices . Has ( deviceID )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath ,  deviceID ,  "must be an allocated device in the claim" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 21:44:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( device . Conditions )  >  resource . AllocatedDeviceStatusMaxConditions  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . TooMany ( fldPath . Child ( "conditions" ) ,  len ( device . Conditions ) ,  resource . AllocatedDeviceStatusMaxConditions ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-08 05:18:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-04 17:03:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  metav1validation . ValidateConditions ( device . Conditions ,  fldPath . Child ( "conditions" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-15 01:59:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  device . Data  !=  nil  &&  len ( device . Data . Raw )  >  0  {  // Data is an optional field.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  validateRawExtension ( * device . Data ,  fldPath . Child ( "data" ) ,  false ,  resource . AllocatedDeviceStatusDataMaxLength ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-28 21:41:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateNetworkDeviceData ( device . NetworkData ,  fldPath . Child ( "networkData" ) ) ... ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-04 17:03:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// validateRawExtension validates RawExtension as in https://github.com/kubernetes/kubernetes/pull/125549/
  
						 
					
						
							
								
									
										
										
										
											2024-12-13 21:44:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  validateRawExtension ( rawExtension  runtime . RawExtension ,  fldPath  * field . Path ,  stored  bool ,  rawExtensionMaxLength  int )  field . ErrorList  {  
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  v  any 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-28 21:41:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( rawExtension . Raw )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath ,  "" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 21:44:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  if  ! stored  &&  len ( rawExtension . Raw )  >  rawExtensionMaxLength  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-07 17:35:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Don't even bother with parsing when too large.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Only applies on create. Existing parameters are grand-fathered in
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// because the limit was introduced in 1.32. This also means that it
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// can be changed in the future.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 21:44:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . TooLong ( fldPath ,  ""  /* unused */ ,  rawExtensionMaxLength ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-28 21:41:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  if  err  :=  json . Unmarshal ( rawExtension . Raw ,  & v ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 01:30:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath ,  "<value omitted>" ,  fmt . Sprintf ( "error parsing data as JSON: %v" ,  err . Error ( ) ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-28 21:41:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  if  v  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Required ( fldPath ,  "" ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  if  _ ,  isObject  :=  v . ( map [ string ] any ) ;  ! isObject  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . Invalid ( fldPath ,  "<value omitted>" ,  "parameters must be a valid JSON object" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  validateNetworkDeviceData ( networkDeviceData  * resource . NetworkDeviceData ,  fldPath  * field . Path )  field . ErrorList  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  allErrs  field . ErrorList 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  networkDeviceData  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 01:30:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 21:44:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( networkDeviceData . InterfaceName )  >  resource . NetworkDeviceDataInterfaceNameMaxLength  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . TooLong ( fldPath . Child ( "interfaceName" ) ,  ""  /* unused */ ,  resource . NetworkDeviceDataInterfaceNameMaxLength ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 01:30:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 21:44:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( networkDeviceData . HardwareAddress )  >  resource . NetworkDeviceDataHardwareAddressMaxLength  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										allErrs  =  append ( allErrs ,  field . TooLong ( fldPath . Child ( "hardwareAddress" ) ,  ""  /* unused */ ,  resource . NetworkDeviceDataHardwareAddressMaxLength ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-06 01:30:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 21:44:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allErrs  =  append ( allErrs ,  validateSet ( networkDeviceData . IPs ,  resource . NetworkDeviceDataMaxIPs , 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										func ( address  string ,  fldPath  * field . Path )  field . ErrorList  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 05:16:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  validation . IsValidInterfaceAddress ( fldPath ,  address ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ,  stringKey ,  fldPath . Child ( "ips" ) ) ... ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 17:02:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  allErrs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}