mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
api: extend validation of dynamic resource allocation fields in PodSpec
The generated ResourceClaim name and the names of the ResourceClaimTemplate and ResourceClaim referenced by a pod must be valid according to the resource API, otherwise the pod cannot start. Checking this was removed from the original implementation out of concerns about validating fields in core against limitations imposed by a separate, alpha API. But as this was pointed out again in https://github.com/kubernetes/kubernetes/pull/116254#discussion_r1134010324 it gets added back. The same strings that worked before still work now. In particular, the constraints for a spec.resourceClaim.name are still the same (DNS label).
This commit is contained in:
@@ -25,21 +25,13 @@ import (
|
||||
"k8s.io/kubernetes/pkg/apis/resource"
|
||||
)
|
||||
|
||||
// validateResourceClaimName can be used to check whether the given
|
||||
// name for a ResourceClaim is valid.
|
||||
var validateResourceClaimName = apimachineryvalidation.NameIsDNSSubdomain
|
||||
|
||||
// validateResourceClaimTemplateName can be used to check whether the given
|
||||
// name for a ResourceClaimTemplate is valid.
|
||||
var validateResourceClaimTemplateName = apimachineryvalidation.NameIsDNSSubdomain
|
||||
|
||||
// validateResourceDriverName reuses the validation of a CSI driver because
|
||||
// the allowed values are exactly the same.
|
||||
var validateResourceDriverName = corevalidation.ValidateCSIDriverName
|
||||
|
||||
// ValidateClaim validates a ResourceClaim.
|
||||
func ValidateClaim(resourceClaim *resource.ResourceClaim) field.ErrorList {
|
||||
allErrs := corevalidation.ValidateObjectMeta(&resourceClaim.ObjectMeta, true, validateResourceClaimName, field.NewPath("metadata"))
|
||||
allErrs := corevalidation.ValidateObjectMeta(&resourceClaim.ObjectMeta, true, corevalidation.ValidateResourceClaimName, field.NewPath("metadata"))
|
||||
allErrs = append(allErrs, validateResourceClaimSpec(&resourceClaim.Spec, field.NewPath("spec"))...)
|
||||
return allErrs
|
||||
}
|
||||
@@ -304,7 +296,7 @@ func validatePodSchedulingClaim(status resource.ResourceClaimSchedulingStatus, f
|
||||
|
||||
// ValidateClaimTemplace validates a ResourceClaimTemplate.
|
||||
func ValidateClaimTemplate(template *resource.ResourceClaimTemplate) field.ErrorList {
|
||||
allErrs := corevalidation.ValidateObjectMeta(&template.ObjectMeta, true, validateResourceClaimTemplateName, field.NewPath("metadata"))
|
||||
allErrs := corevalidation.ValidateObjectMeta(&template.ObjectMeta, true, corevalidation.ValidateResourceClaimTemplateName, field.NewPath("metadata"))
|
||||
allErrs = append(allErrs, validateResourceClaimTemplateSpec(&template.Spec, field.NewPath("spec"))...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user