Merge pull request #5001 from brendandburns/api3

Embed VolumeSource in v1beta3 and internal.
This commit is contained in:
Tim Hockin 2015-03-04 09:50:14 -08:00
commit fdea7252a4
29 changed files with 122 additions and 96 deletions

View File

@ -38,6 +38,5 @@ spec:
name: data name: data
volumes: volumes:
- name: data - name: data
source: emptyDir: {}
emptyDir: {}

View File

@ -33,10 +33,8 @@ spec:
mountPath: /var/lib/mysql mountPath: /var/lib/mysql
volumes: volumes:
- name: mysql-persistent-storage - name: mysql-persistent-storage
source: persistentDisk:
# emptyDir: {} # This GCE PD must already exist.
persistentDisk: pdName: mysql-disk
# This GCE PD must already exist. fsType: ext4
pdName: mysql-disk
fsType: ext4

View File

@ -30,10 +30,8 @@ spec:
mountPath: /var/www/html mountPath: /var/www/html
volumes: volumes:
- name: wordpress-persistent-storage - name: wordpress-persistent-storage
source: persistentDisk:
# emptyDir: {} # This GCE PD must already exist.
persistentDisk: pdName: wordpress-disk
# This GCE PD must already exist. fsType: ext4
pdName: wordpress-disk
fsType: ext4

View File

@ -155,10 +155,10 @@ type Volume struct {
// Required: This must be a DNS_LABEL. Each volume in a pod must have // Required: This must be a DNS_LABEL. Each volume in a pod must have
// a unique name. // a unique name.
Name string `json:"name"` Name string `json:"name"`
// Source represents the location and type of a volume to mount. // The VolumeSource represents the location and type of a volume to mount.
// This is optional for now. If not specified, the Volume is implied to be an EmptyDir. // This is optional for now. If not specified, the Volume is implied to be an EmptyDir.
// This implied behavior is deprecated and will be removed in a future version. // This implied behavior is deprecated and will be removed in a future version.
Source VolumeSource `json:"source,omitempty"` VolumeSource `json:"inline,omitempty"`
} }
// VolumeSource represents the source location of a volume to mount. // VolumeSource represents the source location of a volume to mount.

View File

@ -1016,6 +1016,21 @@ func init() {
return nil return nil
}, },
func(in *newer.Volume, out *Volume, s conversion.Scope) error {
if err := s.Convert(&in.VolumeSource, &out.Source, 0); err != nil {
return err
}
out.Name = in.Name
return nil
},
func(in *Volume, out *newer.Volume, s conversion.Scope) error {
if err := s.Convert(&in.Source, &out.VolumeSource, 0); err != nil {
return err
}
out.Name = in.Name
return nil
},
// VolumeSource's HostDir is deprecated in favor of HostPath. // VolumeSource's HostDir is deprecated in favor of HostPath.
// TODO: It would be great if I could just map field names to // TODO: It would be great if I could just map field names to
// convert or else maybe say "convert all members of this // convert or else maybe say "convert all members of this

View File

@ -935,6 +935,22 @@ func init() {
} }
return nil return nil
}, },
func(in *newer.Volume, out *Volume, s conversion.Scope) error {
if err := s.Convert(&in.VolumeSource, &out.Source, 0); err != nil {
return err
}
out.Name = in.Name
return nil
},
func(in *Volume, out *newer.Volume, s conversion.Scope) error {
if err := s.Convert(&in.Source, &out.VolumeSource, 0); err != nil {
return err
}
out.Name = in.Name
return nil
},
func(in *newer.VolumeSource, out *VolumeSource, s conversion.Scope) error { func(in *newer.VolumeSource, out *VolumeSource, s conversion.Scope) error {
if err := s.Convert(&in.EmptyDir, &out.EmptyDir, 0); err != nil { if err := s.Convert(&in.EmptyDir, &out.EmptyDir, 0); err != nil {
return err return err

View File

@ -26,8 +26,8 @@ import (
func init() { func init() {
api.Scheme.AddDefaultingFuncs( api.Scheme.AddDefaultingFuncs(
func(obj *Volume) { func(obj *Volume) {
if util.AllPtrFieldsNil(&obj.Source) { if util.AllPtrFieldsNil(&obj.VolumeSource) {
obj.Source = VolumeSource{ obj.VolumeSource = VolumeSource{
EmptyDir: &EmptyDirVolumeSource{}, EmptyDir: &EmptyDirVolumeSource{},
} }
} }

View File

@ -65,7 +65,7 @@ func TestSetDefaulPodSpec(t *testing.T) {
if policy.Never != nil || policy.OnFailure != nil || policy.Always == nil { if policy.Never != nil || policy.OnFailure != nil || policy.Always == nil {
t.Errorf("Expected only policy.Always is set, got: %s", policy) t.Errorf("Expected only policy.Always is set, got: %s", policy)
} }
vsource := bp2.Spec.Volumes[0].Source vsource := bp2.Spec.Volumes[0].VolumeSource
if vsource.EmptyDir == nil { if vsource.EmptyDir == nil {
t.Errorf("Expected non-empty volume is set, got: %s", vsource.EmptyDir) t.Errorf("Expected non-empty volume is set, got: %s", vsource.EmptyDir)
} }

View File

@ -177,7 +177,7 @@ type Volume struct {
// Source represents the location and type of a volume to mount. // Source represents the location and type of a volume to mount.
// This is optional for now. If not specified, the Volume is implied to be an EmptyDir. // This is optional for now. If not specified, the Volume is implied to be an EmptyDir.
// This implied behavior is deprecated and will be removed in a future version. // This implied behavior is deprecated and will be removed in a future version.
Source VolumeSource `json:"source,omitempty"` VolumeSource `json:"inline,omitempty"`
} }
// VolumeSource represents the source location of a valume to mount. // VolumeSource represents the source location of a valume to mount.

View File

@ -233,7 +233,7 @@ func validateVolumes(volumes []api.Volume) (util.StringSet, errs.ValidationError
allNames := util.StringSet{} allNames := util.StringSet{}
for i, vol := range volumes { for i, vol := range volumes {
el := validateSource(&vol.Source).Prefix("source") el := validateSource(&vol.VolumeSource).Prefix("source")
if len(vol.Name) == 0 { if len(vol.Name) == 0 {
el = append(el, errs.NewFieldRequired("name", vol.Name)) el = append(el, errs.NewFieldRequired("name", vol.Name))
} else if !util.IsDNSLabel(vol.Name) { } else if !util.IsDNSLabel(vol.Name) {
@ -793,8 +793,8 @@ func ValidatePodTemplateSpec(spec *api.PodTemplateSpec, replicas int) errs.Valid
func ValidateReadOnlyPersistentDisks(volumes []api.Volume) errs.ValidationErrorList { func ValidateReadOnlyPersistentDisks(volumes []api.Volume) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{} allErrs := errs.ValidationErrorList{}
for _, vol := range volumes { for _, vol := range volumes {
if vol.Source.GCEPersistentDisk != nil { if vol.GCEPersistentDisk != nil {
if vol.Source.GCEPersistentDisk.ReadOnly == false { if vol.GCEPersistentDisk.ReadOnly == false {
allErrs = append(allErrs, errs.NewFieldInvalid("GCEPersistentDisk.ReadOnly", false, "ReadOnly must be true for replicated pods > 1, as GCE PD can only be mounted on multiple machines if it is read-only.")) allErrs = append(allErrs, errs.NewFieldInvalid("GCEPersistentDisk.ReadOnly", false, "ReadOnly must be true for replicated pods > 1, as GCE PD can only be mounted on multiple machines if it is read-only."))
} }
} }

View File

@ -147,13 +147,13 @@ func TestValidateAnnotations(t *testing.T) {
func TestValidateVolumes(t *testing.T) { func TestValidateVolumes(t *testing.T) {
successCase := []api.Volume{ successCase := []api.Volume{
{Name: "abc", Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path1"}}}, {Name: "abc", VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path1"}}},
{Name: "123", Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path2"}}}, {Name: "123", VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path2"}}},
{Name: "abc-123", Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path3"}}}, {Name: "abc-123", VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path3"}}},
{Name: "empty", Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}, {Name: "empty", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
{Name: "gcepd", Source: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{"my-PD", "ext4", 1, false}}}, {Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{"my-PD", "ext4", 1, false}}},
{Name: "gitrepo", Source: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{"my-repo", "hashstring"}}}, {Name: "gitrepo", VolumeSource: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{"my-repo", "hashstring"}}},
{Name: "secret", Source: api.VolumeSource{Secret: &api.SecretVolumeSource{api.ObjectReference{Namespace: api.NamespaceDefault, Name: "my-secret", Kind: "Secret"}}}}, {Name: "secret", VolumeSource: api.VolumeSource{Secret: &api.SecretVolumeSource{api.ObjectReference{Namespace: api.NamespaceDefault, Name: "my-secret", Kind: "Secret"}}}},
} }
names, errs := validateVolumes(successCase) names, errs := validateVolumes(successCase)
if len(errs) != 0 { if len(errs) != 0 {
@ -168,10 +168,10 @@ func TestValidateVolumes(t *testing.T) {
T errors.ValidationErrorType T errors.ValidationErrorType
F string F string
}{ }{
"zero-length name": {[]api.Volume{{Name: "", Source: emptyVS}}, errors.ValidationErrorTypeRequired, "[0].name"}, "zero-length name": {[]api.Volume{{Name: "", VolumeSource: emptyVS}}, errors.ValidationErrorTypeRequired, "[0].name"},
"name > 63 characters": {[]api.Volume{{Name: strings.Repeat("a", 64), Source: emptyVS}}, errors.ValidationErrorTypeInvalid, "[0].name"}, "name > 63 characters": {[]api.Volume{{Name: strings.Repeat("a", 64), VolumeSource: emptyVS}}, errors.ValidationErrorTypeInvalid, "[0].name"},
"name not a DNS label": {[]api.Volume{{Name: "a.b.c", Source: emptyVS}}, errors.ValidationErrorTypeInvalid, "[0].name"}, "name not a DNS label": {[]api.Volume{{Name: "a.b.c", VolumeSource: emptyVS}}, errors.ValidationErrorTypeInvalid, "[0].name"},
"name not unique": {[]api.Volume{{Name: "abc", Source: emptyVS}, {Name: "abc", Source: emptyVS}}, errors.ValidationErrorTypeDuplicate, "[1].name"}, "name not unique": {[]api.Volume{{Name: "abc", VolumeSource: emptyVS}, {Name: "abc", VolumeSource: emptyVS}}, errors.ValidationErrorTypeDuplicate, "[1].name"},
} }
for k, v := range errorCases { for k, v := range errorCases {
_, errs := validateVolumes(v.V) _, errs := validateVolumes(v.V)
@ -648,8 +648,8 @@ func TestValidateManifest(t *testing.T) {
{ {
Version: "v1beta1", Version: "v1beta1",
ID: "abc", ID: "abc",
Volumes: []api.Volume{{Name: "vol1", Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/vol1"}}}, Volumes: []api.Volume{{Name: "vol1", VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/vol1"}}},
{Name: "vol2", Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/vol2"}}}}, {Name: "vol2", VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/vol2"}}}},
Containers: []api.Container{ Containers: []api.Container{
{ {
Name: "abc", Name: "abc",
@ -699,7 +699,7 @@ func TestValidateManifest(t *testing.T) {
"invalid volume name": { "invalid volume name": {
Version: "v1beta1", Version: "v1beta1",
ID: "abc", ID: "abc",
Volumes: []api.Volume{{Name: "vol.1", Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}}, Volumes: []api.Volume{{Name: "vol.1", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}},
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
DNSPolicy: api.DNSClusterFirst, DNSPolicy: api.DNSClusterFirst,
}, },
@ -722,14 +722,14 @@ func TestValidateManifest(t *testing.T) {
func TestValidatePodSpec(t *testing.T) { func TestValidatePodSpec(t *testing.T) {
successCases := []api.PodSpec{ successCases := []api.PodSpec{
{ // Populate basic fields, leave defaults for most. { // Populate basic fields, leave defaults for most.
Volumes: []api.Volume{{Name: "vol", Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}}, Volumes: []api.Volume{{Name: "vol", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}},
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}}, Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
DNSPolicy: api.DNSClusterFirst, DNSPolicy: api.DNSClusterFirst,
}, },
{ // Populate all fields. { // Populate all fields.
Volumes: []api.Volume{ Volumes: []api.Volume{
{Name: "vol", Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}, {Name: "vol", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
}, },
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}}, Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
@ -778,7 +778,7 @@ func TestValidatePod(t *testing.T) {
{ // Basic fields. { // Basic fields.
ObjectMeta: api.ObjectMeta{Name: "123", Namespace: "ns"}, ObjectMeta: api.ObjectMeta{Name: "123", Namespace: "ns"},
Spec: api.PodSpec{ Spec: api.PodSpec{
Volumes: []api.Volume{{Name: "vol", Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}}, Volumes: []api.Volume{{Name: "vol", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}},
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}}, Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
DNSPolicy: api.DNSClusterFirst, DNSPolicy: api.DNSClusterFirst,
@ -788,7 +788,7 @@ func TestValidatePod(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "abc.123.do-re-mi", Namespace: "ns"}, ObjectMeta: api.ObjectMeta{Name: "abc.123.do-re-mi", Namespace: "ns"},
Spec: api.PodSpec{ Spec: api.PodSpec{
Volumes: []api.Volume{ Volumes: []api.Volume{
{Name: "vol", Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}, {Name: "vol", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
}, },
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}}, Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
@ -1080,7 +1080,7 @@ func TestValidateBoundPods(t *testing.T) {
{ // Basic fields. { // Basic fields.
ObjectMeta: api.ObjectMeta{Name: "123", Namespace: "ns"}, ObjectMeta: api.ObjectMeta{Name: "123", Namespace: "ns"},
Spec: api.PodSpec{ Spec: api.PodSpec{
Volumes: []api.Volume{{Name: "vol", Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}}, Volumes: []api.Volume{{Name: "vol", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}},
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}}, Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
DNSPolicy: api.DNSClusterFirst, DNSPolicy: api.DNSClusterFirst,
@ -1090,7 +1090,7 @@ func TestValidateBoundPods(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "abc.123.do-re-mi", Namespace: "ns"}, ObjectMeta: api.ObjectMeta{Name: "abc.123.do-re-mi", Namespace: "ns"},
Spec: api.PodSpec{ Spec: api.PodSpec{
Volumes: []api.Volume{ Volumes: []api.Volume{
{Name: "vol", Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}, {Name: "vol", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
}, },
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}}, Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
@ -1552,7 +1552,7 @@ func TestValidateReplicationControllerUpdate(t *testing.T) {
Spec: api.PodSpec{ Spec: api.PodSpec{
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
DNSPolicy: api.DNSClusterFirst, DNSPolicy: api.DNSClusterFirst,
Volumes: []api.Volume{{Name: "gcepd", Source: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{"my-PD", "ext4", 1, false}}}}, Volumes: []api.Volume{{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{"my-PD", "ext4", 1, false}}}},
}, },
}, },
} }
@ -1710,7 +1710,7 @@ func TestValidateReplicationController(t *testing.T) {
Labels: validSelector, Labels: validSelector,
}, },
Spec: api.PodSpec{ Spec: api.PodSpec{
Volumes: []api.Volume{{Name: "gcepd", Source: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{"my-PD", "ext4", 1, false}}}}, Volumes: []api.Volume{{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{"my-PD", "ext4", 1, false}}}},
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
DNSPolicy: api.DNSClusterFirst, DNSPolicy: api.DNSClusterFirst,
}, },

View File

@ -88,12 +88,12 @@ func TestMerge(t *testing.T) {
Spec: api.PodSpec{ Spec: api.PodSpec{
Volumes: []api.Volume{ Volumes: []api.Volume{
{ {
Name: "v1", Name: "v1",
Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}, VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}},
}, },
{ {
Name: "v2", Name: "v2",
Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}, VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}},
}, },
}, },
RestartPolicy: api.RestartPolicy{ RestartPolicy: api.RestartPolicy{

View File

@ -67,7 +67,7 @@ func ExampleManifestAndPod(id string) (v1beta1.ContainerManifest, api.BoundPod)
Volumes: []api.Volume{ Volumes: []api.Volume{
{ {
Name: "host-dir", Name: "host-dir",
Source: api.VolumeSource{ VolumeSource: api.VolumeSource{
HostPath: &api.HostPathVolumeSource{"/dir/path"}, HostPath: &api.HostPathVolumeSource{"/dir/path"},
}, },
}, },

View File

@ -1018,8 +1018,8 @@ func TestMountExternalVolumes(t *testing.T) {
Spec: api.PodSpec{ Spec: api.PodSpec{
Volumes: []api.Volume{ Volumes: []api.Volume{
{ {
Name: "vol1", Name: "vol1",
Source: api.VolumeSource{}, VolumeSource: api.VolumeSource{},
}, },
}, },
}, },

View File

@ -60,10 +60,10 @@ func (plugin *emptyDirPlugin) CanSupport(spec *api.Volume) bool {
return false return false
} }
if util.AllPtrFieldsNil(&spec.Source) { if util.AllPtrFieldsNil(&spec.VolumeSource) {
return true return true
} }
if spec.Source.EmptyDir != nil { if spec.EmptyDir != nil {
return true return true
} }
return false return false

View File

@ -36,10 +36,10 @@ func TestCanSupport(t *testing.T) {
if plug.Name() != "kubernetes.io/empty-dir" { if plug.Name() != "kubernetes.io/empty-dir" {
t.Errorf("Wrong name: %s", plug.Name()) t.Errorf("Wrong name: %s", plug.Name())
} }
if !plug.CanSupport(&api.Volume{Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}) { if !plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}) {
t.Errorf("Expected true") t.Errorf("Expected true")
} }
if !plug.CanSupport(&api.Volume{Source: api.VolumeSource{}}) { if !plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{}}) {
t.Errorf("Expected true") t.Errorf("Expected true")
} }
} }
@ -53,8 +53,8 @@ func TestPlugin(t *testing.T) {
t.Errorf("Can't find the plugin by name") t.Errorf("Can't find the plugin by name")
} }
spec := &api.Volume{ spec := &api.Volume{
Name: "vol1", Name: "vol1",
Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}, VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}},
} }
builder, err := plug.NewBuilder(spec, types.UID("poduid")) builder, err := plug.NewBuilder(spec, types.UID("poduid"))
if err != nil { if err != nil {
@ -134,11 +134,11 @@ func TestPluginLegacy(t *testing.T) {
if plug.Name() != "empty" { if plug.Name() != "empty" {
t.Errorf("Wrong name: %s", plug.Name()) t.Errorf("Wrong name: %s", plug.Name())
} }
if plug.CanSupport(&api.Volume{Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}) { if plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}) {
t.Errorf("Expected false") t.Errorf("Expected false")
} }
if _, err := plug.NewBuilder(&api.Volume{Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}, types.UID("poduid")); err == nil { if _, err := plug.NewBuilder(&api.Volume{VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}, types.UID("poduid")); err == nil {
t.Errorf("Expected failiure") t.Errorf("Expected failiure")
} }

View File

@ -64,7 +64,7 @@ func (plugin *gcePersistentDiskPlugin) CanSupport(spec *api.Volume) bool {
return false return false
} }
if spec.Source.GCEPersistentDisk != nil { if spec.GCEPersistentDisk != nil {
return true return true
} }
return false return false
@ -81,13 +81,13 @@ func (plugin *gcePersistentDiskPlugin) newBuilderInternal(spec *api.Volume, podU
return nil, fmt.Errorf("legacy mode: can not create new instances") return nil, fmt.Errorf("legacy mode: can not create new instances")
} }
pdName := spec.Source.GCEPersistentDisk.PDName pdName := spec.GCEPersistentDisk.PDName
fsType := spec.Source.GCEPersistentDisk.FSType fsType := spec.GCEPersistentDisk.FSType
partition := "" partition := ""
if spec.Source.GCEPersistentDisk.Partition != 0 { if spec.GCEPersistentDisk.Partition != 0 {
partition = strconv.Itoa(spec.Source.GCEPersistentDisk.Partition) partition = strconv.Itoa(spec.GCEPersistentDisk.Partition)
} }
readOnly := spec.Source.GCEPersistentDisk.ReadOnly readOnly := spec.GCEPersistentDisk.ReadOnly
return &gcePersistentDisk{ return &gcePersistentDisk{
podUID: podUID, podUID: podUID,

View File

@ -36,7 +36,7 @@ func TestCanSupport(t *testing.T) {
if plug.Name() != "kubernetes.io/gce-pd" { if plug.Name() != "kubernetes.io/gce-pd" {
t.Errorf("Wrong name: %s", plug.Name()) t.Errorf("Wrong name: %s", plug.Name())
} }
if !plug.CanSupport(&api.Volume{Source: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{}}}) { if !plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{}}}) {
t.Errorf("Expected true") t.Errorf("Expected true")
} }
} }
@ -73,7 +73,7 @@ func TestPlugin(t *testing.T) {
} }
spec := &api.Volume{ spec := &api.Volume{
Name: "vol1", Name: "vol1",
Source: api.VolumeSource{ VolumeSource: api.VolumeSource{
GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{ GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{
PDName: "pd", PDName: "pd",
FSType: "ext4", FSType: "ext4",
@ -140,11 +140,11 @@ func TestPluginLegacy(t *testing.T) {
if plug.Name() != "gce-pd" { if plug.Name() != "gce-pd" {
t.Errorf("Wrong name: %s", plug.Name()) t.Errorf("Wrong name: %s", plug.Name())
} }
if plug.CanSupport(&api.Volume{Source: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{}}}) { if plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{}}}) {
t.Errorf("Expected false") t.Errorf("Expected false")
} }
if _, err := plug.NewBuilder(&api.Volume{Source: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{}}}, types.UID("poduid")); err == nil { if _, err := plug.NewBuilder(&api.Volume{VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{}}}, types.UID("poduid")); err == nil {
t.Errorf("Expected failiure") t.Errorf("Expected failiure")
} }

View File

@ -63,7 +63,7 @@ func (plugin *gitRepoPlugin) CanSupport(spec *api.Volume) bool {
return false return false
} }
if spec.Source.GitRepo != nil { if spec.GitRepo != nil {
return true return true
} }
return false return false
@ -77,8 +77,8 @@ func (plugin *gitRepoPlugin) NewBuilder(spec *api.Volume, podUID types.UID) (vol
return &gitRepo{ return &gitRepo{
podUID: podUID, podUID: podUID,
volName: spec.Name, volName: spec.Name,
source: spec.Source.GitRepo.Repository, source: spec.GitRepo.Repository,
revision: spec.Source.GitRepo.Revision, revision: spec.GitRepo.Revision,
exec: exec.New(), exec: exec.New(),
plugin: plugin, plugin: plugin,
legacyMode: false, legacyMode: false,

View File

@ -49,7 +49,7 @@ func TestCanSupport(t *testing.T) {
if plug.Name() != "kubernetes.io/git-repo" { if plug.Name() != "kubernetes.io/git-repo" {
t.Errorf("Wrong name: %s", plug.Name()) t.Errorf("Wrong name: %s", plug.Name())
} }
if !plug.CanSupport(&api.Volume{Source: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{}}}) { if !plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{}}}) {
t.Errorf("Expected true") t.Errorf("Expected true")
} }
} }
@ -110,7 +110,7 @@ func TestPlugin(t *testing.T) {
} }
spec := &api.Volume{ spec := &api.Volume{
Name: "vol1", Name: "vol1",
Source: api.VolumeSource{ VolumeSource: api.VolumeSource{
GitRepo: &api.GitRepoVolumeSource{ GitRepo: &api.GitRepoVolumeSource{
Repository: "https://github.com/GoogleCloudPlatform/kubernetes.git", Repository: "https://github.com/GoogleCloudPlatform/kubernetes.git",
Revision: "2a30ce65c5ab586b98916d83385c5983edd353a1", Revision: "2a30ce65c5ab586b98916d83385c5983edd353a1",
@ -168,11 +168,11 @@ func TestPluginLegacy(t *testing.T) {
if plug.Name() != "git" { if plug.Name() != "git" {
t.Errorf("Wrong name: %s", plug.Name()) t.Errorf("Wrong name: %s", plug.Name())
} }
if plug.CanSupport(&api.Volume{Source: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{}}}) { if plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{}}}) {
t.Errorf("Expected false") t.Errorf("Expected false")
} }
if _, err := plug.NewBuilder(&api.Volume{Source: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{}}}, types.UID("poduid")); err == nil { if _, err := plug.NewBuilder(&api.Volume{VolumeSource: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{}}}, types.UID("poduid")); err == nil {
t.Errorf("Expected failiure") t.Errorf("Expected failiure")
} }

View File

@ -46,14 +46,14 @@ func (plugin *hostPathPlugin) Name() string {
} }
func (plugin *hostPathPlugin) CanSupport(spec *api.Volume) bool { func (plugin *hostPathPlugin) CanSupport(spec *api.Volume) bool {
if spec.Source.HostPath != nil { if spec.HostPath != nil {
return true return true
} }
return false return false
} }
func (plugin *hostPathPlugin) NewBuilder(spec *api.Volume, podUID types.UID) (volume.Builder, error) { func (plugin *hostPathPlugin) NewBuilder(spec *api.Volume, podUID types.UID) (volume.Builder, error) {
return &hostPath{spec.Source.HostPath.Path}, nil return &hostPath{spec.HostPath.Path}, nil
} }
func (plugin *hostPathPlugin) NewCleaner(volName string, podUID types.UID) (volume.Cleaner, error) { func (plugin *hostPathPlugin) NewCleaner(volName string, podUID types.UID) (volume.Cleaner, error) {

View File

@ -35,10 +35,10 @@ func TestCanSupport(t *testing.T) {
if plug.Name() != "kubernetes.io/host-path" { if plug.Name() != "kubernetes.io/host-path" {
t.Errorf("Wrong name: %s", plug.Name()) t.Errorf("Wrong name: %s", plug.Name())
} }
if !plug.CanSupport(&api.Volume{Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{}}}) { if !plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{}}}) {
t.Errorf("Expected true") t.Errorf("Expected true")
} }
if plug.CanSupport(&api.Volume{Source: api.VolumeSource{}}) { if plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{}}) {
t.Errorf("Expected false") t.Errorf("Expected false")
} }
} }
@ -52,8 +52,8 @@ func TestPlugin(t *testing.T) {
t.Errorf("Can't find the plugin by name") t.Errorf("Can't find the plugin by name")
} }
spec := &api.Volume{ spec := &api.Volume{
Name: "vol1", Name: "vol1",
Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/vol1"}}, VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/vol1"}},
} }
builder, err := plug.NewBuilder(spec, types.UID("poduid")) builder, err := plug.NewBuilder(spec, types.UID("poduid"))
if err != nil { if err != nil {

View File

@ -51,7 +51,7 @@ func (plugin *secretPlugin) Name() string {
} }
func (plugin *secretPlugin) CanSupport(spec *api.Volume) bool { func (plugin *secretPlugin) CanSupport(spec *api.Volume) bool {
if spec.Source.Secret != nil { if spec.Secret != nil {
return true return true
} }
@ -63,7 +63,7 @@ func (plugin *secretPlugin) NewBuilder(spec *api.Volume, podUID types.UID) (volu
} }
func (plugin *secretPlugin) newBuilderInternal(spec *api.Volume, podUID types.UID) (volume.Builder, error) { func (plugin *secretPlugin) newBuilderInternal(spec *api.Volume, podUID types.UID) (volume.Builder, error) {
return &secretVolume{spec.Name, podUID, plugin, &spec.Source.Secret.Target}, nil return &secretVolume{spec.Name, podUID, plugin, &spec.Secret.Target}, nil
} }
func (plugin *secretPlugin) NewCleaner(volName string, podUID types.UID) (volume.Cleaner, error) { func (plugin *secretPlugin) NewCleaner(volName string, podUID types.UID) (volume.Cleaner, error) {

View File

@ -50,7 +50,7 @@ func TestCanSupport(t *testing.T) {
if plugin.Name() != secretPluginName { if plugin.Name() != secretPluginName {
t.Errorf("Wrong name: %s", plugin.Name()) t.Errorf("Wrong name: %s", plugin.Name())
} }
if !plugin.CanSupport(&api.Volume{Source: api.VolumeSource{Secret: &api.SecretVolumeSource{Target: api.ObjectReference{}}}}) { if !plugin.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{Secret: &api.SecretVolumeSource{Target: api.ObjectReference{}}}}) {
t.Errorf("Expected true") t.Errorf("Expected true")
} }
} }
@ -65,7 +65,7 @@ func TestPlugin(t *testing.T) {
volumeSpec := &api.Volume{ volumeSpec := &api.Volume{
Name: testVolumeName, Name: testVolumeName,
Source: api.VolumeSource{ VolumeSource: api.VolumeSource{
Secret: &api.SecretVolumeSource{ Secret: &api.SecretVolumeSource{
Target: api.ObjectReference{ Target: api.ObjectReference{
Namespace: testNamespace, Namespace: testNamespace,

View File

@ -51,15 +51,15 @@ func (nodes ClientNodeInfo) GetNodeInfo(nodeID string) (*api.Node, error) {
} }
func isVolumeConflict(volume api.Volume, pod *api.Pod) bool { func isVolumeConflict(volume api.Volume, pod *api.Pod) bool {
if volume.Source.GCEPersistentDisk == nil { if volume.GCEPersistentDisk == nil {
return false return false
} }
pdName := volume.Source.GCEPersistentDisk.PDName pdName := volume.GCEPersistentDisk.PDName
manifest := &(pod.Spec) manifest := &(pod.Spec)
for ix := range manifest.Volumes { for ix := range manifest.Volumes {
if manifest.Volumes[ix].Source.GCEPersistentDisk != nil && if manifest.Volumes[ix].GCEPersistentDisk != nil &&
manifest.Volumes[ix].Source.GCEPersistentDisk.PDName == pdName { manifest.Volumes[ix].GCEPersistentDisk.PDName == pdName {
return true return true
} }
} }

View File

@ -276,7 +276,7 @@ func TestDiskConflicts(t *testing.T) {
volState := api.PodSpec{ volState := api.PodSpec{
Volumes: []api.Volume{ Volumes: []api.Volume{
{ {
Source: api.VolumeSource{ VolumeSource: api.VolumeSource{
GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{ GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{
PDName: "foo", PDName: "foo",
}, },
@ -287,7 +287,7 @@ func TestDiskConflicts(t *testing.T) {
volState2 := api.PodSpec{ volState2 := api.PodSpec{
Volumes: []api.Volume{ Volumes: []api.Volume{
{ {
Source: api.VolumeSource{ VolumeSource: api.VolumeSource{
GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{ GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{
PDName: "bar", PDName: "bar",
}, },

View File

@ -192,7 +192,7 @@ func testPDPod(diskName, targetHost string, readOnly bool) *api.Pod {
Volumes: []api.Volume{ Volumes: []api.Volume{
{ {
Name: "testpd", Name: "testpd",
Source: api.VolumeSource{ VolumeSource: api.VolumeSource{
GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{ GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{
PDName: diskName, PDName: diskName,
FSType: "ext4", FSType: "ext4",

View File

@ -79,7 +79,7 @@ var _ = Describe("Secrets", func() {
Volumes: []api.Volume{ Volumes: []api.Volume{
{ {
Name: volumeName, Name: volumeName,
Source: api.VolumeSource{ VolumeSource: api.VolumeSource{
Secret: &api.SecretVolumeSource{ Secret: &api.SecretVolumeSource{
Target: api.ObjectReference{ Target: api.ObjectReference{
Kind: "Secret", Kind: "Secret",

View File

@ -75,7 +75,7 @@ var _ = Describe("Services", func() {
Volumes: []api.Volume{ Volumes: []api.Volume{
{ {
Name: "results", Name: "results",
Source: api.VolumeSource{ VolumeSource: api.VolumeSource{
EmptyDir: &api.EmptyDirVolumeSource{}, EmptyDir: &api.EmptyDirVolumeSource{},
}, },
}, },