configurable pv recyclers

This commit is contained in:
markturansky
2015-09-02 23:14:26 -04:00
parent 0902f80f8b
commit 7bc55b5aea
16 changed files with 468 additions and 178 deletions

View File

@@ -169,8 +169,22 @@ func (spec *Spec) Name() string {
// The binary should still use strong typing for this value when binding CLI values before they are passed as strings
// in OtherAttributes.
type VolumeConfig struct {
// thockin: do we want to wait on this until we have an actual use case? I can change the comments above to
// reflect our intention for one-off config.
// RecyclerPodTemplate is pod template that understands how to scrub clean a persistent volume after its release.
// The template is used by plugins which override specific properties of the pod in accordance with that plugin.
// See NewPersistentVolumeRecyclerPodTemplate for the properties that are expected to be overridden.
RecyclerPodTemplate *api.Pod
// RecyclerMinimumTimeout is the minimum amount of time in seconds for the recycler pod's ActiveDeadlineSeconds attribute.
// Added to the minimum timeout is the increment per Gi of capacity.
RecyclerMinimumTimeout int
// RecyclerTimeoutIncrement is the number of seconds added to the recycler pod's ActiveDeadlineSeconds for each
// Gi of capacity in the persistent volume.
// Example: 5Gi volume x 30s increment = 150s + 30s minimum = 180s ActiveDeadlineSeconds for recycler pod
RecyclerTimeoutIncrement int
// OtherAttributes stores config as strings. These strings are opaque to the system and only understood by the binary
// hosting the plugin and the plugin itself.
OtherAttributes map[string]string
}
@@ -301,3 +315,49 @@ func (pm *VolumePluginMgr) FindRecyclablePluginBySpec(spec *Spec) (RecyclableVol
}
return nil, fmt.Errorf("no recyclable volume plugin matched")
}
// NewPersistentVolumeRecyclerPodTemplate creates a template for a recycler pod. By default, a recycler pod simply runs
// "rm -rf" on a volume and tests for emptiness. Most attributes of the template will be correct for most
// plugin implementations. The following attributes can be overridden per plugin via configuration:
//
// 1. pod.Spec.Volumes[0].VolumeSource must be overridden. Recycler implementations without a valid VolumeSource will fail.
// 2. pod.GenerateName helps distinguish recycler pods by name. Recommended. Default is "pv-recycler-".
// 3. pod.Spec.ActiveDeadlineSeconds gives the recycler pod a maximum timeout before failing. Recommended. Default is 60 seconds.
//
// See HostPath and NFS for working recycler examples
func NewPersistentVolumeRecyclerPodTemplate() *api.Pod {
timeout := int64(60)
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
GenerateName: "pv-recycler-",
Namespace: api.NamespaceDefault,
},
Spec: api.PodSpec{
ActiveDeadlineSeconds: &timeout,
RestartPolicy: api.RestartPolicyNever,
Volumes: []api.Volume{
{
Name: "vol",
// IMPORTANT! All plugins using this template MUST override pod.Spec.Volumes[0].VolumeSource
// Recycler implementations without a valid VolumeSource will fail.
VolumeSource: api.VolumeSource{},
},
},
Containers: []api.Container{
{
Name: "pv-recycler",
Image: "gcr.io/google_containers/busybox",
Command: []string{"/bin/sh"},
Args: []string{"-c", "test -e /scrub && echo $(date) > /scrub/trash.txt && rm -rf /scrub/* /scrub/.* && test -z \"$(ls -A /scrub)\" || exit 1"},
VolumeMounts: []api.VolumeMount{
{
Name: "vol",
MountPath: "/scrub",
},
},
},
},
},
}
return pod
}