Commit 158f6b78 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #52246 from dixudx/suspect_hostpathtype_nil_ptr

Automatic merge from submit-queue. 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>.. suspect nil HostPathType **What this PR does / why we need it**: Nil `HostPathType` is suspicious. @luxas Will help re-verify. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #52242 **Special notes for your reviewer**: /assign @luxas @thockin **Release note**: ```release-note None ```
parents 939ae0a9 29249e08
...@@ -993,7 +993,7 @@ var supportedHostPathTypes = sets.NewString( ...@@ -993,7 +993,7 @@ var supportedHostPathTypes = sets.NewString(
func validateHostPathType(hostPathType *api.HostPathType, fldPath *field.Path) field.ErrorList { func validateHostPathType(hostPathType *api.HostPathType, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{} allErrs := field.ErrorList{}
if !supportedHostPathTypes.Has(string(*hostPathType)) { if hostPathType != nil && !supportedHostPathTypes.Has(string(*hostPathType)) {
allErrs = append(allErrs, field.NotSupported(fldPath, hostPathType, supportedHostPathTypes.List())) allErrs = append(allErrs, field.NotSupported(fldPath, hostPathType, supportedHostPathTypes.List()))
} }
......
...@@ -106,8 +106,14 @@ func (plugin *hostPathPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, opts vo ...@@ -106,8 +106,14 @@ func (plugin *hostPathPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, opts vo
} }
path := hostPathVolumeSource.Path path := hostPathVolumeSource.Path
pathType := new(v1.HostPathType)
if hostPathVolumeSource.Type == nil {
*pathType = v1.HostPathUnset
} else {
pathType = hostPathVolumeSource.Type
}
return &hostPathMounter{ return &hostPathMounter{
hostPath: &hostPath{path: path, pathType: hostPathVolumeSource.Type, containerized: opts.Containerized}, hostPath: &hostPath{path: path, pathType: pathType, containerized: opts.Containerized},
readOnly: readOnly, readOnly: readOnly,
}, nil }, nil
} }
......
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