mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-24 11:01:26 +00:00
added pv attrs to volumeOptions, improved tests
This commit is contained in:
parent
3bed0a2b5c
commit
a1692e06e6
@ -20,8 +20,8 @@ package unversioned
|
|||||||
// generate Swagger API documentation for its models. Please read this PR for more
|
// 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
|
// information on the implementation: https://github.com/emicklei/go-restful/pull/215
|
||||||
//
|
//
|
||||||
// TODOs are ignored from the parser. (e.g. TODO(andronat):... || TODO:...) iff
|
// TODOs are ignored from the parser (e.g. TODO(andronat):... || TODO:...) if and only if
|
||||||
// are on one line! For multiple line or blocks that you want to ignore use ---.
|
// they are on one line! For multiple line or blocks that you want to ignore use ---.
|
||||||
// Any context after a --- is ignored.
|
// Any context after a --- is ignored.
|
||||||
//
|
//
|
||||||
// Those methods can be generated by using hack/update-generated-swagger-docs.sh
|
// Those methods can be generated by using hack/update-generated-swagger-docs.sh
|
||||||
|
@ -120,6 +120,9 @@ func (plugin *hostPathPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *hostPathPlugin) NewCreater(options volume.VolumeOptions) (volume.Creater, error) {
|
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)
|
return plugin.newCreaterFunc(options, plugin.host)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,6 +255,8 @@ func (r *hostPathCreater) Create() (*api.PersistentVolume, error) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: api.PersistentVolumeSpec{
|
Spec: api.PersistentVolumeSpec{
|
||||||
|
PersistentVolumeReclaimPolicy: r.options.PersistentVolumeReclaimPolicy,
|
||||||
|
AccessModes: r.options.AccessModes,
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceStorage): resource.MustParse(fmt.Sprintf("%dMi", r.options.CapacityMB)),
|
api.ResourceName(api.ResourceStorage): resource.MustParse(fmt.Sprintf("%dMi", r.options.CapacityMB)),
|
||||||
},
|
},
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
@ -155,7 +156,7 @@ func TestCreater(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
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 {
|
if err != nil {
|
||||||
t.Errorf("Failed to make a new Creater: %v", err)
|
t.Errorf("Failed to make a new Creater: %v", err)
|
||||||
}
|
}
|
||||||
@ -166,6 +167,18 @@ func TestCreater(t *testing.T) {
|
|||||||
if pv.Spec.HostPath.Path == "" {
|
if pv.Spec.HostPath.Path == "" {
|
||||||
t.Errorf("Expected pv.Spec.HostPath.Path to not be empty: %#v", pv)
|
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)
|
os.RemoveAll(pv.Spec.HostPath.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,16 @@ type VolumeOptions struct {
|
|||||||
// This is a temporary measure in order to set the rootContext of tmpfs mounts correctly.
|
// 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.
|
// it will be replaced and expanded on by future SecurityContext work.
|
||||||
RootContext string
|
RootContext string
|
||||||
|
|
||||||
|
// The attributes below are required by volume.Creater
|
||||||
|
// perhaps CreaterVolumeOptions struct?
|
||||||
|
|
||||||
// CapacityMB is the size in MB of a volume.
|
// CapacityMB is the size in MB of a volume.
|
||||||
CapacityMB int
|
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
|
// 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)
|
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 {
|
type CreatableVolumePlugin interface {
|
||||||
VolumePlugin
|
VolumePlugin
|
||||||
// NewCreater creates a new volume.Creater which knows how to create PersistentVolumes in accordance with
|
// NewCreater creates a new volume.Creater which knows how to create PersistentVolumes in accordance with
|
||||||
|
Loading…
Reference in New Issue
Block a user