diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index 81a9e01904f8d..55830e26f4f1f 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -993,7 +993,7 @@ var supportedHostPathTypes = sets.NewString( func validateHostPathType(hostPathType *api.HostPathType, fldPath *field.Path) 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())) } diff --git a/pkg/volume/host_path/host_path.go b/pkg/volume/host_path/host_path.go index 0b5f4b906a665..0ca43cc858576 100644 --- a/pkg/volume/host_path/host_path.go +++ b/pkg/volume/host_path/host_path.go @@ -106,8 +106,14 @@ func (plugin *hostPathPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, opts vo } path := hostPathVolumeSource.Path + pathType := new(v1.HostPathType) + if hostPathVolumeSource.Type == nil { + *pathType = v1.HostPathUnset + } else { + pathType = hostPathVolumeSource.Type + } return &hostPathMounter{ - hostPath: &hostPath{path: path, pathType: hostPathVolumeSource.Type, containerized: opts.Containerized}, + hostPath: &hostPath{path: path, pathType: pathType, containerized: opts.Containerized}, readOnly: readOnly, }, nil }