From a1692e06e6b6808bd780b662e0ba1e68d6eec8af Mon Sep 17 00:00:00 2001 From: markturansky Date: Fri, 18 Sep 2015 09:15:48 -0400 Subject: [PATCH] added pv attrs to volumeOptions, improved tests --- .../unversioned/types_swagger_doc_generated.go | 4 ++-- pkg/volume/host_path/host_path.go | 5 +++++ pkg/volume/host_path/host_path_test.go | 15 ++++++++++++++- pkg/volume/plugins.go | 10 +++++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/pkg/api/unversioned/types_swagger_doc_generated.go b/pkg/api/unversioned/types_swagger_doc_generated.go index 7351e012388..cc10ee12f62 100644 --- a/pkg/api/unversioned/types_swagger_doc_generated.go +++ b/pkg/api/unversioned/types_swagger_doc_generated.go @@ -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 diff --git a/pkg/volume/host_path/host_path.go b/pkg/volume/host_path/host_path.go index f7fe41e3218..e74320acf98 100644 --- a/pkg/volume/host_path/host_path.go +++ b/pkg/volume/host_path/host_path.go @@ -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)), }, diff --git a/pkg/volume/host_path/host_path_test.go b/pkg/volume/host_path/host_path_test.go index e8e79a02d31..68a5f8ec4b1 100644 --- a/pkg/volume/host_path/host_path_test.go +++ b/pkg/volume/host_path/host_path_test.go @@ -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) } diff --git a/pkg/volume/plugins.go b/pkg/volume/plugins.go index 15cf6bd99a6..1c8b1d48230 100644 --- a/pkg/volume/plugins.go +++ b/pkg/volume/plugins.go @@ -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