mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
set default HostPathType to empty
This commit is contained in:
parent
6f74af94ef
commit
d0a4af133b
@ -357,8 +357,8 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
|
||||
},
|
||||
func(obj *api.HostPathVolumeSource, c fuzz.Continue) {
|
||||
c.FuzzNoCustom(obj)
|
||||
types := []api.HostPathType{api.HostPathDirectoryOrCreate, api.HostPathDirectory, api.HostPathFileOrCreate,
|
||||
api.HostPathFile, api.HostPathSocket, api.HostPathCharDev, api.HostPathBlockDev}
|
||||
types := []api.HostPathType{api.HostPathUnset, api.HostPathDirectoryOrCreate, api.HostPathDirectory,
|
||||
api.HostPathFileOrCreate, api.HostPathFile, api.HostPathSocket, api.HostPathCharDev, api.HostPathBlockDev}
|
||||
typeVol := types[c.Rand.Intn(len(types))]
|
||||
if obj.Path != "" && obj.Type == nil {
|
||||
obj.Type = &typeVol
|
||||
|
@ -600,6 +600,8 @@ const (
|
||||
type HostPathType string
|
||||
|
||||
const (
|
||||
// For backwards compatible, leave it empty if unset
|
||||
HostPathUnset HostPathType = ""
|
||||
// If nothing exists at the given path, an empty directory will be created there
|
||||
// as needed with file mode 0755, having the same group and ownership with Kubelet.
|
||||
HostPathDirectoryOrCreate HostPathType = "DirectoryOrCreate"
|
||||
@ -623,7 +625,7 @@ const (
|
||||
type HostPathVolumeSource struct {
|
||||
// If the path is a symlink, it will follow the link to the real path.
|
||||
Path string
|
||||
// Defaults to DirectoryOrCreate
|
||||
// Defaults to ""
|
||||
Type *HostPathType
|
||||
}
|
||||
|
||||
|
@ -371,7 +371,7 @@ func SetDefaults_ScaleIOVolumeSource(obj *v1.ScaleIOVolumeSource) {
|
||||
}
|
||||
|
||||
func SetDefaults_HostPathVolumeSource(obj *v1.HostPathVolumeSource) {
|
||||
typeVol := v1.HostPathDirectoryOrCreate
|
||||
typeVol := v1.HostPathUnset
|
||||
if obj.Type == nil {
|
||||
obj.Type = &typeVol
|
||||
}
|
||||
|
@ -1277,3 +1277,25 @@ func TestSetDefaultSchedulerName(t *testing.T) {
|
||||
t.Errorf("Expected scheduler name: %+v\ngot: %+v\n", v1.DefaultSchedulerName, output.Spec.SchedulerName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultHostPathVolumeSource(t *testing.T) {
|
||||
s := v1.PodSpec{}
|
||||
s.Volumes = []v1.Volume{
|
||||
{
|
||||
VolumeSource: v1.VolumeSource{
|
||||
HostPath: &v1.HostPathVolumeSource{Path: "foo"},
|
||||
},
|
||||
},
|
||||
}
|
||||
pod := &v1.Pod{
|
||||
Spec: s,
|
||||
}
|
||||
output := roundTrip(t, runtime.Object(pod))
|
||||
pod2 := output.(*v1.Pod)
|
||||
defaultType := pod2.Spec.Volumes[0].VolumeSource.HostPath.Type
|
||||
expectedType := v1.HostPathUnset
|
||||
|
||||
if defaultType == nil || *defaultType != expectedType {
|
||||
t.Errorf("Expected v1.HostPathVolumeSource default type %v, got %v", expectedType, defaultType)
|
||||
}
|
||||
}
|
||||
|
@ -976,6 +976,7 @@ func validateProjectedVolumeSource(projection *api.ProjectedVolumeSource, fldPat
|
||||
}
|
||||
|
||||
var supportedHostPathTypes = sets.NewString(
|
||||
string(api.HostPathUnset),
|
||||
string(api.HostPathDirectoryOrCreate),
|
||||
string(api.HostPathDirectory),
|
||||
string(api.HostPathFileOrCreate),
|
||||
|
@ -214,6 +214,9 @@ func (b *hostPathMounter) SetUp(fsGroup *int64) error {
|
||||
return fmt.Errorf("invalid HostPath `%s`: %v", b.GetPath(), err)
|
||||
}
|
||||
|
||||
if *b.pathType == v1.HostPathUnset {
|
||||
return nil
|
||||
}
|
||||
return checkType(b.GetPath(), b.pathType)
|
||||
}
|
||||
|
||||
|
@ -554,7 +554,7 @@ func TestHostPathTypeCheckerInternal(t *testing.T) {
|
||||
isFile: false,
|
||||
exists: false,
|
||||
validpathType: newHostPathTypeList(string(v1.HostPathFileOrCreate)),
|
||||
invalidpathType: newHostPathTypeList(string(v1.HostPathFile), string(v1.HostPathDirectory),
|
||||
invalidpathType: newHostPathTypeList(string(v1.HostPathDirectory),
|
||||
string(v1.HostPathSocket), string(v1.HostPathCharDev), string(v1.HostPathBlockDev)),
|
||||
},
|
||||
{
|
||||
|
@ -684,6 +684,8 @@ const (
|
||||
type HostPathType string
|
||||
|
||||
const (
|
||||
// For backwards compatible, leave it empty if unset
|
||||
HostPathUnset HostPathType = ""
|
||||
// If nothing exists at the given path, an empty directory will be created there
|
||||
// as needed with file mode 0755, having the same group and ownership with Kubelet.
|
||||
HostPathDirectoryOrCreate HostPathType = "DirectoryOrCreate"
|
||||
@ -710,7 +712,7 @@ type HostPathVolumeSource struct {
|
||||
// More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath
|
||||
Path string `json:"path" protobuf:"bytes,1,opt,name=path"`
|
||||
// Type for HostPath Volume
|
||||
// Defaults to DirectoryOrCreate
|
||||
// Defaults to ""
|
||||
// More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath
|
||||
// +optional
|
||||
Type *HostPathType `json:"type,omitempty" protobuf:"bytes,2,opt,name=type"`
|
||||
|
Loading…
Reference in New Issue
Block a user