Added PersistentVolumeController
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
"regexp"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
@@ -35,11 +34,11 @@ import (
|
||||
func ProbeVolumePlugins(volumeConfig volume.VolumeConfig) []volume.VolumePlugin {
|
||||
return []volume.VolumePlugin{
|
||||
&hostPathPlugin{
|
||||
host: nil,
|
||||
newRecyclerFunc: newRecycler,
|
||||
newDeleterFunc: newDeleter,
|
||||
newCreaterFunc: newCreater,
|
||||
config: volumeConfig,
|
||||
host: nil,
|
||||
newRecyclerFunc: newRecycler,
|
||||
newDeleterFunc: newDeleter,
|
||||
newProvisionerFunc: newProvisioner,
|
||||
config: volumeConfig,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -47,28 +46,28 @@ func ProbeVolumePlugins(volumeConfig volume.VolumeConfig) []volume.VolumePlugin
|
||||
func ProbeRecyclableVolumePlugins(recyclerFunc func(spec *volume.Spec, host volume.VolumeHost, volumeConfig volume.VolumeConfig) (volume.Recycler, error), volumeConfig volume.VolumeConfig) []volume.VolumePlugin {
|
||||
return []volume.VolumePlugin{
|
||||
&hostPathPlugin{
|
||||
host: nil,
|
||||
newRecyclerFunc: recyclerFunc,
|
||||
newCreaterFunc: newCreater,
|
||||
config: volumeConfig,
|
||||
host: nil,
|
||||
newRecyclerFunc: recyclerFunc,
|
||||
newProvisionerFunc: newProvisioner,
|
||||
config: volumeConfig,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type hostPathPlugin struct {
|
||||
host volume.VolumeHost
|
||||
// decouple creating Recyclers/Deleters/Creaters by deferring to a function. Allows for easier testing.
|
||||
newRecyclerFunc func(spec *volume.Spec, host volume.VolumeHost, volumeConfig volume.VolumeConfig) (volume.Recycler, error)
|
||||
newDeleterFunc func(spec *volume.Spec, host volume.VolumeHost) (volume.Deleter, error)
|
||||
newCreaterFunc func(options volume.VolumeOptions, host volume.VolumeHost) (volume.Creater, error)
|
||||
config volume.VolumeConfig
|
||||
// decouple creating Recyclers/Deleters/Provisioners by deferring to a function. Allows for easier testing.
|
||||
newRecyclerFunc func(spec *volume.Spec, host volume.VolumeHost, volumeConfig volume.VolumeConfig) (volume.Recycler, error)
|
||||
newDeleterFunc func(spec *volume.Spec, host volume.VolumeHost) (volume.Deleter, error)
|
||||
newProvisionerFunc func(options volume.VolumeOptions, host volume.VolumeHost) (volume.Provisioner, error)
|
||||
config volume.VolumeConfig
|
||||
}
|
||||
|
||||
var _ volume.VolumePlugin = &hostPathPlugin{}
|
||||
var _ volume.PersistentVolumePlugin = &hostPathPlugin{}
|
||||
var _ volume.RecyclableVolumePlugin = &hostPathPlugin{}
|
||||
var _ volume.DeletableVolumePlugin = &hostPathPlugin{}
|
||||
var _ volume.CreatableVolumePlugin = &hostPathPlugin{}
|
||||
var _ volume.ProvisionableVolumePlugin = &hostPathPlugin{}
|
||||
|
||||
const (
|
||||
hostPathPluginName = "kubernetes.io/host-path"
|
||||
@@ -124,11 +123,11 @@ func (plugin *hostPathPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, err
|
||||
return plugin.newDeleterFunc(spec, plugin.host)
|
||||
}
|
||||
|
||||
func (plugin *hostPathPlugin) NewCreater(options volume.VolumeOptions) (volume.Creater, error) {
|
||||
func (plugin *hostPathPlugin) NewProvisioner(options volume.VolumeOptions) (volume.Provisioner, error) {
|
||||
if len(options.AccessModes) == 0 {
|
||||
options.AccessModes = plugin.GetAccessModes()
|
||||
}
|
||||
return plugin.newCreaterFunc(options, plugin.host)
|
||||
return plugin.newProvisionerFunc(options, plugin.host)
|
||||
}
|
||||
|
||||
func newRecycler(spec *volume.Spec, host volume.VolumeHost, config volume.VolumeConfig) (volume.Recycler, error) {
|
||||
@@ -154,8 +153,8 @@ func newDeleter(spec *volume.Spec, host volume.VolumeHost) (volume.Deleter, erro
|
||||
return &hostPathDeleter{spec.Name(), path, host, volume.NewMetricsDu(path)}, nil
|
||||
}
|
||||
|
||||
func newCreater(options volume.VolumeOptions, host volume.VolumeHost) (volume.Creater, error) {
|
||||
return &hostPathCreater{options: options, host: host}, nil
|
||||
func newProvisioner(options volume.VolumeOptions, host volume.VolumeHost) (volume.Provisioner, error) {
|
||||
return &hostPathProvisioner{options: options, host: host}, nil
|
||||
}
|
||||
|
||||
// HostPath volumes represent a bare host file or directory mount.
|
||||
@@ -215,7 +214,7 @@ func (c *hostPathCleaner) TearDownAt(dir string) error {
|
||||
return fmt.Errorf("TearDownAt() does not make sense for host paths")
|
||||
}
|
||||
|
||||
// hostPathRecycler implements a dynamic provisioning Recycler for the HostPath plugin
|
||||
// hostPathRecycler implements a Recycler for the HostPath plugin
|
||||
// This implementation is meant for testing only and only works in a single node cluster
|
||||
type hostPathRecycler struct {
|
||||
name string
|
||||
@@ -246,34 +245,36 @@ func (r *hostPathRecycler) Recycle() error {
|
||||
return volume.RecycleVolumeByWatchingPodUntilCompletion(pod, r.host.GetKubeClient())
|
||||
}
|
||||
|
||||
// hostPathCreater implements a dynamic provisioning Creater for the HostPath plugin
|
||||
// hostPathProvisioner implements a Provisioner for the HostPath plugin
|
||||
// This implementation is meant for testing only and only works in a single node cluster.
|
||||
type hostPathCreater struct {
|
||||
type hostPathProvisioner struct {
|
||||
host volume.VolumeHost
|
||||
options volume.VolumeOptions
|
||||
}
|
||||
|
||||
// Create for hostPath simply creates a local /tmp/hostpath_pv/%s directory as a new PersistentVolume.
|
||||
// This Creater is meant for development and testing only and WILL NOT WORK in a multi-node cluster.
|
||||
func (r *hostPathCreater) Create() (*api.PersistentVolume, error) {
|
||||
fullpath := fmt.Sprintf("/tmp/hostpath_pv/%s", util.NewUUID())
|
||||
err := os.MkdirAll(fullpath, 0750)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// This Provisioner is meant for development and testing only and WILL NOT WORK in a multi-node cluster.
|
||||
func (r *hostPathProvisioner) Provision(pv *api.PersistentVolume) error {
|
||||
if pv.Spec.HostPath == nil {
|
||||
return fmt.Errorf("pv.Spec.HostPath cannot be nil")
|
||||
}
|
||||
return os.MkdirAll(pv.Spec.HostPath.Path, 0750)
|
||||
}
|
||||
|
||||
func (r *hostPathProvisioner) NewPersistentVolumeTemplate() (*api.PersistentVolume, error) {
|
||||
fullpath := fmt.Sprintf("/tmp/hostpath_pv/%s", util.NewUUID())
|
||||
return &api.PersistentVolume{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
GenerateName: "pv-hostpath-",
|
||||
Labels: map[string]string{
|
||||
"createdby": "hostpath dynamic provisioner",
|
||||
Annotations: map[string]string{
|
||||
"kubernetes.io/createdby": "hostpath-dynamic-provisioner",
|
||||
},
|
||||
},
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
PersistentVolumeReclaimPolicy: r.options.PersistentVolumeReclaimPolicy,
|
||||
AccessModes: r.options.AccessModes,
|
||||
Capacity: api.ResourceList{
|
||||
api.ResourceName(api.ResourceStorage): resource.MustParse(fmt.Sprintf("%dMi", r.options.CapacityMB)),
|
||||
api.ResourceName(api.ResourceStorage): r.options.Capacity,
|
||||
},
|
||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||
HostPath: &api.HostPathVolumeSource{
|
||||
|
Reference in New Issue
Block a user