Skip to content
Snippets Groups Projects
Commit 50819747 authored by Jeremy Scott's avatar Jeremy Scott Committed by Derek Su
Browse files

Allow default volume type to be specified in the storage class

parent 08483f70
No related branches found
No related tags found
No related merge requests found
...@@ -282,20 +282,15 @@ func (p *LocalPathProvisioner) Provision(ctx context.Context, opts pvController. ...@@ -282,20 +282,15 @@ func (p *LocalPathProvisioner) Provision(ctx context.Context, opts pvController.
fs := v1.PersistentVolumeFilesystem fs := v1.PersistentVolumeFilesystem
var pvs v1.PersistentVolumeSource var pvs v1.PersistentVolumeSource
if val, ok := opts.PVC.GetAnnotations()["volumeType"]; ok && strings.ToLower(val) == "local" { if pvcVal, ok := opts.PVC.GetAnnotations()["volumeType"]; ok {
pvs = v1.PersistentVolumeSource{ // volume type specified in PVC
Local: &v1.LocalVolumeSource{ pvs = createPersistentVolumeSource(pvcVal, path)
Path: path, } else if scVal, ok := opts.StorageClass.GetAnnotations()["defaultVolumeType"]; ok {
}, // default volume type provided for storage class
} pvs = createPersistentVolumeSource(scVal, path)
} else { } else {
hostPathType := v1.HostPathDirectoryOrCreate // volume type unspecified, we default to hostPath
pvs = v1.PersistentVolumeSource{ pvs = createPersistentVolumeSource("hostPath", path)
HostPath: &v1.HostPathVolumeSource{
Path: path,
Type: &hostPathType,
},
}
} }
var nodeAffinity *v1.VolumeNodeAffinity var nodeAffinity *v1.VolumeNodeAffinity
...@@ -655,3 +650,24 @@ func canonicalizeConfig(data *ConfigData) (cfg *Config, err error) { ...@@ -655,3 +650,24 @@ func canonicalizeConfig(data *ConfigData) (cfg *Config, err error) {
} }
return cfg, nil return cfg, nil
} }
func createPersistentVolumeSource(volumeType string, path string) v1.PersistentVolumeSource {
var pvs v1.PersistentVolumeSource
switch strings.ToLower(volumeType) {
case "local":
pvs = v1.PersistentVolumeSource{
Local: &v1.LocalVolumeSource{
Path: path,
},
}
default:
hostPathType := v1.HostPathDirectoryOrCreate
pvs = v1.PersistentVolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: path,
Type: &hostPathType,
},
}
}
return pvs
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment