mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Fix validation for BoundPods to allow defaults
Thunking to Manifest makes a copy of the input, which is not useful for defaulting.
This commit is contained in:
parent
33fcef6b42
commit
6e8f5fea8e
@ -370,8 +370,12 @@ func ValidatePod(pod *api.Pod) errs.ValidationErrorList {
|
|||||||
allErrs := errs.ValidationErrorList{}
|
allErrs := errs.ValidationErrorList{}
|
||||||
if len(pod.Name) == 0 {
|
if len(pod.Name) == 0 {
|
||||||
allErrs = append(allErrs, errs.NewFieldRequired("name", pod.Name))
|
allErrs = append(allErrs, errs.NewFieldRequired("name", pod.Name))
|
||||||
|
} else if !util.IsDNSSubdomain(pod.Name) {
|
||||||
|
allErrs = append(allErrs, errs.NewFieldInvalid("name", pod.Name, ""))
|
||||||
}
|
}
|
||||||
if !util.IsDNSSubdomain(pod.Namespace) {
|
if len(pod.Namespace) == 0 {
|
||||||
|
allErrs = append(allErrs, errs.NewFieldRequired("namespace", pod.Namespace))
|
||||||
|
} else if !util.IsDNSSubdomain(pod.Namespace) {
|
||||||
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", pod.Namespace, ""))
|
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", pod.Namespace, ""))
|
||||||
}
|
}
|
||||||
allErrs = append(allErrs, ValidatePodSpec(&pod.Spec).Prefix("spec")...)
|
allErrs = append(allErrs, ValidatePodSpec(&pod.Spec).Prefix("spec")...)
|
||||||
@ -549,25 +553,20 @@ func ValidateReadOnlyPersistentDisks(volumes []api.Volume) errs.ValidationErrorL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ValidateBoundPod tests if required fields on a bound pod are set.
|
// ValidateBoundPod tests if required fields on a bound pod are set.
|
||||||
func ValidateBoundPod(pod *api.BoundPod) (errors []error) {
|
func ValidateBoundPod(pod *api.BoundPod) errs.ValidationErrorList {
|
||||||
if !util.IsDNSSubdomain(pod.Name) {
|
allErrs := errs.ValidationErrorList{}
|
||||||
errors = append(errors, errs.NewFieldInvalid("name", pod.Name, ""))
|
if len(pod.Name) == 0 {
|
||||||
|
allErrs = append(allErrs, errs.NewFieldRequired("name", pod.Name))
|
||||||
|
} else if !util.IsDNSSubdomain(pod.Name) {
|
||||||
|
allErrs = append(allErrs, errs.NewFieldInvalid("name", pod.Name, ""))
|
||||||
}
|
}
|
||||||
if !util.IsDNSSubdomain(pod.Namespace) {
|
if len(pod.Name) == 0 {
|
||||||
errors = append(errors, errs.NewFieldInvalid("namespace", pod.Namespace, ""))
|
allErrs = append(allErrs, errs.NewFieldRequired("namespace", pod.Namespace))
|
||||||
|
} else if !util.IsDNSSubdomain(pod.Namespace) {
|
||||||
|
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", pod.Namespace, ""))
|
||||||
}
|
}
|
||||||
containerManifest := &api.ContainerManifest{
|
allErrs = append(allErrs, ValidatePodSpec(&pod.Spec).Prefix("spec")...)
|
||||||
Version: "v1beta2",
|
return allErrs
|
||||||
ID: pod.Name,
|
|
||||||
UUID: pod.UID,
|
|
||||||
Containers: pod.Spec.Containers,
|
|
||||||
Volumes: pod.Spec.Volumes,
|
|
||||||
RestartPolicy: pod.Spec.RestartPolicy,
|
|
||||||
}
|
|
||||||
if errs := ValidateManifest(containerManifest); len(errs) != 0 {
|
|
||||||
errors = append(errors, errs...)
|
|
||||||
}
|
|
||||||
return errors
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateMinion tests if required fields in the minion are set.
|
// ValidateMinion tests if required fields in the minion are set.
|
||||||
|
Loading…
Reference in New Issue
Block a user