added pv attrs to volumeOptions, improved tests

pull/6/head
markturansky 2015-09-18 09:15:48 -04:00
parent 3bed0a2b5c
commit a1692e06e6
4 changed files with 30 additions and 4 deletions

View File

@ -20,8 +20,8 @@ package unversioned
// generate Swagger API documentation for its models. Please read this PR for more
// information on the implementation: https://github.com/emicklei/go-restful/pull/215
//
// TODOs are ignored from the parser. (e.g. TODO(andronat):... || TODO:...) iff
// are on one line! For multiple line or blocks that you want to ignore use ---.
// TODOs are ignored from the parser (e.g. TODO(andronat):... || TODO:...) if and only if
// they are on one line! For multiple line or blocks that you want to ignore use ---.
// Any context after a --- is ignored.
//
// Those methods can be generated by using hack/update-generated-swagger-docs.sh

View File

@ -120,6 +120,9 @@ func (plugin *hostPathPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, err
}
func (plugin *hostPathPlugin) NewCreater(options volume.VolumeOptions) (volume.Creater, error) {
if len(options.AccessModes) == 0 {
options.AccessModes = plugin.GetAccessModes()
}
return plugin.newCreaterFunc(options, plugin.host)
}
@ -252,6 +255,8 @@ func (r *hostPathCreater) Create() (*api.PersistentVolume, error) {
},
},
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)),
},

View File

@ -22,6 +22,7 @@ import (
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/types"
@ -155,7 +156,7 @@ func TestCreater(t *testing.T) {
if err != nil {
t.Errorf("Can't find the plugin by name")
}
creater, err := plug.NewCreater(volume.VolumeOptions{CapacityMB: 100})
creater, err := plug.NewCreater(volume.VolumeOptions{CapacityMB: 100, PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimDelete})
if err != nil {
t.Errorf("Failed to make a new Creater: %v", err)
}
@ -166,6 +167,18 @@ func TestCreater(t *testing.T) {
if pv.Spec.HostPath.Path == "" {
t.Errorf("Expected pv.Spec.HostPath.Path to not be empty: %#v", pv)
}
expectedCapacity := resource.NewQuantity(100*1024*1024, resource.BinarySI)
actualCapacity := pv.Spec.Capacity[api.ResourceStorage]
expectedAmt := expectedCapacity.Value()
actualAmt := actualCapacity.Value()
if expectedAmt != actualAmt {
t.Errorf("Expected capacity %+v but got %+v", expectedAmt, actualAmt)
}
if pv.Spec.PersistentVolumeReclaimPolicy != api.PersistentVolumeReclaimDelete {
t.Errorf("Expected reclaim policy %+v but got %+v", api.PersistentVolumeReclaimDelete, pv.Spec.PersistentVolumeReclaimPolicy)
}
os.RemoveAll(pv.Spec.HostPath.Path)
}

View File

@ -38,8 +38,16 @@ type VolumeOptions struct {
// This is a temporary measure in order to set the rootContext of tmpfs mounts correctly.
// it will be replaced and expanded on by future SecurityContext work.
RootContext string
// The attributes below are required by volume.Creater
// perhaps CreaterVolumeOptions struct?
// CapacityMB is the size in MB of a volume.
CapacityMB int
// AccessModes of a volume
AccessModes []api.PersistentVolumeAccessMode
// Reclamation policy for a persistent volume
PersistentVolumeReclaimPolicy api.PersistentVolumeReclaimPolicy
}
// VolumePlugin is an interface to volume plugins that can be used on a
@ -98,7 +106,7 @@ type DeletableVolumePlugin interface {
NewDeleter(spec *Spec) (Deleter, error)
}
// CreatableVolumePlugin is an extended interface of VolumePlugin and is used to create persistent volumes for the cluster.
// CreatableVolumePlugin is an extended interface of VolumePlugin and is used to create volumes for the cluster.
type CreatableVolumePlugin interface {
VolumePlugin
// NewCreater creates a new volume.Creater which knows how to create PersistentVolumes in accordance with