Unverified Commit 84914c6a authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #61984 from mikedanese/fix4

Automatic merge from submit-queue (batch tested with PRs 63492, 62379, 61984, 63805, 63807). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. validation: improve ProjectedVolume validation errors * only report "may not specify more than 1 volume type" once * fix incorrectly reported field paths * continue to traverse into projections to report further errors. @kubernetes/sig-storage-pr-reviews ```release-note NONE ```
parents cad48800 a5d2ca8c
...@@ -984,74 +984,64 @@ func validateProjectionSources(projection *core.ProjectedVolumeSource, projectio ...@@ -984,74 +984,64 @@ func validateProjectionSources(projection *core.ProjectedVolumeSource, projectio
allErrs := field.ErrorList{} allErrs := field.ErrorList{}
allPaths := sets.String{} allPaths := sets.String{}
for _, source := range projection.Sources { for i, source := range projection.Sources {
numSources := 0 numSources := 0
if source.Secret != nil { srcPath := fldPath.Child("sources").Index(i)
if numSources > 0 { if projPath := srcPath.Child("secret"); source.Secret != nil {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("secret"), "may not specify more than 1 volume type")) numSources++
} else { if len(source.Secret.Name) == 0 {
numSources++ allErrs = append(allErrs, field.Required(projPath.Child("name"), ""))
if len(source.Secret.Name) == 0 { }
allErrs = append(allErrs, field.Required(fldPath.Child("name"), "")) itemsPath := projPath.Child("items")
} for i, kp := range source.Secret.Items {
itemsPath := fldPath.Child("items") itemPath := itemsPath.Index(i)
for i, kp := range source.Secret.Items { allErrs = append(allErrs, validateKeyToPath(&kp, itemPath)...)
itemPath := itemsPath.Index(i) if len(kp.Path) > 0 {
allErrs = append(allErrs, validateKeyToPath(&kp, itemPath)...) curPath := kp.Path
if len(kp.Path) > 0 { if !allPaths.Has(curPath) {
curPath := kp.Path allPaths.Insert(curPath)
if !allPaths.Has(curPath) { } else {
allPaths.Insert(curPath) allErrs = append(allErrs, field.Invalid(fldPath, source.Secret.Name, "conflicting duplicate paths"))
} else {
allErrs = append(allErrs, field.Invalid(fldPath, source.Secret.Name, "conflicting duplicate paths"))
}
} }
} }
} }
} }
if source.ConfigMap != nil { if projPath := srcPath.Child("configMap"); source.ConfigMap != nil {
if numSources > 0 { numSources++
allErrs = append(allErrs, field.Forbidden(fldPath.Child("configMap"), "may not specify more than 1 volume type")) if len(source.ConfigMap.Name) == 0 {
} else { allErrs = append(allErrs, field.Required(projPath.Child("name"), ""))
numSources++ }
if len(source.ConfigMap.Name) == 0 { itemsPath := projPath.Child("items")
allErrs = append(allErrs, field.Required(fldPath.Child("name"), "")) for i, kp := range source.ConfigMap.Items {
} itemPath := itemsPath.Index(i)
itemsPath := fldPath.Child("items") allErrs = append(allErrs, validateKeyToPath(&kp, itemPath)...)
for i, kp := range source.ConfigMap.Items { if len(kp.Path) > 0 {
itemPath := itemsPath.Index(i) curPath := kp.Path
allErrs = append(allErrs, validateKeyToPath(&kp, itemPath)...) if !allPaths.Has(curPath) {
if len(kp.Path) > 0 { allPaths.Insert(curPath)
curPath := kp.Path } else {
if !allPaths.Has(curPath) { allErrs = append(allErrs, field.Invalid(fldPath, source.ConfigMap.Name, "conflicting duplicate paths"))
allPaths.Insert(curPath)
} else {
allErrs = append(allErrs, field.Invalid(fldPath, source.ConfigMap.Name, "conflicting duplicate paths"))
}
} }
} }
} }
} }
if source.DownwardAPI != nil { if projPath := srcPath.Child("downwardAPI"); source.DownwardAPI != nil {
if numSources > 0 { numSources++
allErrs = append(allErrs, field.Forbidden(fldPath.Child("downwardAPI"), "may not specify more than 1 volume type")) for _, file := range source.DownwardAPI.Items {
} else { allErrs = append(allErrs, validateDownwardAPIVolumeFile(&file, projPath)...)
numSources++ if len(file.Path) > 0 {
for _, file := range source.DownwardAPI.Items { curPath := file.Path
allErrs = append(allErrs, validateDownwardAPIVolumeFile(&file, fldPath.Child("downwardAPI"))...) if !allPaths.Has(curPath) {
if len(file.Path) > 0 { allPaths.Insert(curPath)
curPath := file.Path } else {
if !allPaths.Has(curPath) { allErrs = append(allErrs, field.Invalid(fldPath, curPath, "conflicting duplicate paths"))
allPaths.Insert(curPath)
} else {
allErrs = append(allErrs, field.Invalid(fldPath, curPath, "conflicting duplicate paths"))
}
} }
} }
} }
} }
if numSources > 1 {
allErrs = append(allErrs, field.Forbidden(srcPath, "may not specify more than 1 volume type"))
}
} }
return allErrs return allErrs
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment