diff --git a/examples/cassandra/v1beta3/cassandra-controller.yaml b/examples/cassandra/v1beta3/cassandra-controller.yaml index 66af9a13eb8c0..a860c96086fd9 100644 --- a/examples/cassandra/v1beta3/cassandra-controller.yaml +++ b/examples/cassandra/v1beta3/cassandra-controller.yaml @@ -38,6 +38,5 @@ spec: name: data volumes: - name: data - source: - emptyDir: {} + emptyDir: {} diff --git a/examples/mysql-wordpress-pd/v1beta3/mysql.yaml b/examples/mysql-wordpress-pd/v1beta3/mysql.yaml index 9ebc424585797..014a4429bda49 100644 --- a/examples/mysql-wordpress-pd/v1beta3/mysql.yaml +++ b/examples/mysql-wordpress-pd/v1beta3/mysql.yaml @@ -33,10 +33,8 @@ spec: mountPath: /var/lib/mysql volumes: - name: mysql-persistent-storage - source: - # emptyDir: {} - persistentDisk: - # This GCE PD must already exist. - pdName: mysql-disk - fsType: ext4 + persistentDisk: + # This GCE PD must already exist. + pdName: mysql-disk + fsType: ext4 diff --git a/examples/mysql-wordpress-pd/v1beta3/wordpress.yaml b/examples/mysql-wordpress-pd/v1beta3/wordpress.yaml index 3ee5b12f75600..4912763e307cf 100644 --- a/examples/mysql-wordpress-pd/v1beta3/wordpress.yaml +++ b/examples/mysql-wordpress-pd/v1beta3/wordpress.yaml @@ -30,10 +30,8 @@ spec: mountPath: /var/www/html volumes: - name: wordpress-persistent-storage - source: - # emptyDir: {} - persistentDisk: - # This GCE PD must already exist. - pdName: wordpress-disk - fsType: ext4 + persistentDisk: + # This GCE PD must already exist. + pdName: wordpress-disk + fsType: ext4 diff --git a/pkg/api/types.go b/pkg/api/types.go index bd1eb008cbb5c..272a370674f38 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -155,10 +155,10 @@ type Volume struct { // Required: This must be a DNS_LABEL. Each volume in a pod must have // a unique 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 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. diff --git a/pkg/api/v1beta1/conversion.go b/pkg/api/v1beta1/conversion.go index ad816ecc57865..715b08b82ae83 100644 --- a/pkg/api/v1beta1/conversion.go +++ b/pkg/api/v1beta1/conversion.go @@ -1016,6 +1016,21 @@ func init() { 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. // TODO: It would be great if I could just map field names to // convert or else maybe say "convert all members of this diff --git a/pkg/api/v1beta2/conversion.go b/pkg/api/v1beta2/conversion.go index 2ce1a1c85e5e0..df1d6f794e751 100644 --- a/pkg/api/v1beta2/conversion.go +++ b/pkg/api/v1beta2/conversion.go @@ -935,6 +935,22 @@ func init() { } 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 { if err := s.Convert(&in.EmptyDir, &out.EmptyDir, 0); err != nil { return err diff --git a/pkg/api/v1beta3/defaults.go b/pkg/api/v1beta3/defaults.go index 543ee228b4a4b..6c2baf7af6947 100644 --- a/pkg/api/v1beta3/defaults.go +++ b/pkg/api/v1beta3/defaults.go @@ -26,8 +26,8 @@ import ( func init() { api.Scheme.AddDefaultingFuncs( func(obj *Volume) { - if util.AllPtrFieldsNil(&obj.Source) { - obj.Source = VolumeSource{ + if util.AllPtrFieldsNil(&obj.VolumeSource) { + obj.VolumeSource = VolumeSource{ EmptyDir: &EmptyDirVolumeSource{}, } } diff --git a/pkg/api/v1beta3/defaults_test.go b/pkg/api/v1beta3/defaults_test.go index 4ddce88714515..fe4bd8ec70333 100644 --- a/pkg/api/v1beta3/defaults_test.go +++ b/pkg/api/v1beta3/defaults_test.go @@ -65,7 +65,7 @@ func TestSetDefaulPodSpec(t *testing.T) { if policy.Never != nil || policy.OnFailure != nil || policy.Always == nil { 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 { t.Errorf("Expected non-empty volume is set, got: %s", vsource.EmptyDir) } diff --git a/pkg/api/v1beta3/types.go b/pkg/api/v1beta3/types.go index 30787a3adb02c..bd93a78356a00 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -177,7 +177,7 @@ type Volume struct { // 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 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. diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index 44e00be24be51..b68da23275349 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -233,7 +233,7 @@ func validateVolumes(volumes []api.Volume) (util.StringSet, errs.ValidationError allNames := util.StringSet{} for i, vol := range volumes { - el := validateSource(&vol.Source).Prefix("source") + el := validateSource(&vol.VolumeSource).Prefix("source") if len(vol.Name) == 0 { el = append(el, errs.NewFieldRequired("name", 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 { allErrs := errs.ValidationErrorList{} for _, vol := range volumes { - if vol.Source.GCEPersistentDisk != nil { - if vol.Source.GCEPersistentDisk.ReadOnly == false { + if vol.GCEPersistentDisk != nil { + 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.")) } } diff --git a/pkg/api/validation/validation_test.go b/pkg/api/validation/validation_test.go index fdda8adb9c752..54fc64d377871 100644 --- a/pkg/api/validation/validation_test.go +++ b/pkg/api/validation/validation_test.go @@ -147,13 +147,13 @@ func TestValidateAnnotations(t *testing.T) { func TestValidateVolumes(t *testing.T) { successCase := []api.Volume{ - {Name: "abc", Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path1"}}}, - {Name: "123", Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path2"}}}, - {Name: "abc-123", Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path3"}}}, - {Name: "empty", Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}, - {Name: "gcepd", Source: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{"my-PD", "ext4", 1, false}}}, - {Name: "gitrepo", Source: 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: "abc", VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path1"}}}, + {Name: "123", VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path2"}}}, + {Name: "abc-123", VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/path3"}}}, + {Name: "empty", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}, + {Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{"my-PD", "ext4", 1, false}}}, + {Name: "gitrepo", VolumeSource: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{"my-repo", "hashstring"}}}, + {Name: "secret", VolumeSource: api.VolumeSource{Secret: &api.SecretVolumeSource{api.ObjectReference{Namespace: api.NamespaceDefault, Name: "my-secret", Kind: "Secret"}}}}, } names, errs := validateVolumes(successCase) if len(errs) != 0 { @@ -168,10 +168,10 @@ func TestValidateVolumes(t *testing.T) { T errors.ValidationErrorType F string }{ - "zero-length name": {[]api.Volume{{Name: "", Source: emptyVS}}, errors.ValidationErrorTypeRequired, "[0].name"}, - "name > 63 characters": {[]api.Volume{{Name: strings.Repeat("a", 64), Source: emptyVS}}, errors.ValidationErrorTypeInvalid, "[0].name"}, - "name not a DNS label": {[]api.Volume{{Name: "a.b.c", Source: emptyVS}}, errors.ValidationErrorTypeInvalid, "[0].name"}, - "name not unique": {[]api.Volume{{Name: "abc", Source: emptyVS}, {Name: "abc", Source: emptyVS}}, errors.ValidationErrorTypeDuplicate, "[1].name"}, + "zero-length name": {[]api.Volume{{Name: "", VolumeSource: emptyVS}}, errors.ValidationErrorTypeRequired, "[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", VolumeSource: emptyVS}}, errors.ValidationErrorTypeInvalid, "[0].name"}, + "name not unique": {[]api.Volume{{Name: "abc", VolumeSource: emptyVS}, {Name: "abc", VolumeSource: emptyVS}}, errors.ValidationErrorTypeDuplicate, "[1].name"}, } for k, v := range errorCases { _, errs := validateVolumes(v.V) @@ -648,8 +648,8 @@ func TestValidateManifest(t *testing.T) { { Version: "v1beta1", ID: "abc", - Volumes: []api.Volume{{Name: "vol1", Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/vol1"}}}, - {Name: "vol2", Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/vol2"}}}}, + Volumes: []api.Volume{{Name: "vol1", VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/vol1"}}}, + {Name: "vol2", VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/mnt/vol2"}}}}, Containers: []api.Container{ { Name: "abc", @@ -699,7 +699,7 @@ func TestValidateManifest(t *testing.T) { "invalid volume name": { Version: "v1beta1", 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{}}, DNSPolicy: api.DNSClusterFirst, }, @@ -722,14 +722,14 @@ func TestValidateManifest(t *testing.T) { func TestValidatePodSpec(t *testing.T) { successCases := []api.PodSpec{ { // 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"}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, DNSPolicy: api.DNSClusterFirst, }, { // Populate all fields. 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"}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, @@ -778,7 +778,7 @@ func TestValidatePod(t *testing.T) { { // Basic fields. ObjectMeta: api.ObjectMeta{Name: "123", Namespace: "ns"}, 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"}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, DNSPolicy: api.DNSClusterFirst, @@ -788,7 +788,7 @@ func TestValidatePod(t *testing.T) { ObjectMeta: api.ObjectMeta{Name: "abc.123.do-re-mi", Namespace: "ns"}, Spec: api.PodSpec{ 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"}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, @@ -1080,7 +1080,7 @@ func TestValidateBoundPods(t *testing.T) { { // Basic fields. ObjectMeta: api.ObjectMeta{Name: "123", Namespace: "ns"}, 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"}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, DNSPolicy: api.DNSClusterFirst, @@ -1090,7 +1090,7 @@ func TestValidateBoundPods(t *testing.T) { ObjectMeta: api.ObjectMeta{Name: "abc.123.do-re-mi", Namespace: "ns"}, Spec: api.PodSpec{ 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"}}, RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, @@ -1552,7 +1552,7 @@ func TestValidateReplicationControllerUpdate(t *testing.T) { Spec: api.PodSpec{ RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, 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, }, 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{}}, DNSPolicy: api.DNSClusterFirst, }, diff --git a/pkg/kubectl/cmd/util/helpers_test.go b/pkg/kubectl/cmd/util/helpers_test.go index 8966ab5a5b0dc..7b7111a03b319 100644 --- a/pkg/kubectl/cmd/util/helpers_test.go +++ b/pkg/kubectl/cmd/util/helpers_test.go @@ -88,12 +88,12 @@ func TestMerge(t *testing.T) { Spec: api.PodSpec{ Volumes: []api.Volume{ { - Name: "v1", - Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}, + Name: "v1", + VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}, }, { - Name: "v2", - Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}, + Name: "v2", + VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}, }, }, RestartPolicy: api.RestartPolicy{ diff --git a/pkg/kubelet/config/file_test.go b/pkg/kubelet/config/file_test.go index 6155086d06587..16777ec943cc4 100644 --- a/pkg/kubelet/config/file_test.go +++ b/pkg/kubelet/config/file_test.go @@ -67,7 +67,7 @@ func ExampleManifestAndPod(id string) (v1beta1.ContainerManifest, api.BoundPod) Volumes: []api.Volume{ { Name: "host-dir", - Source: api.VolumeSource{ + VolumeSource: api.VolumeSource{ HostPath: &api.HostPathVolumeSource{"/dir/path"}, }, }, diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index f7576072076ee..d3858699e03c0 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -1018,8 +1018,8 @@ func TestMountExternalVolumes(t *testing.T) { Spec: api.PodSpec{ Volumes: []api.Volume{ { - Name: "vol1", - Source: api.VolumeSource{}, + Name: "vol1", + VolumeSource: api.VolumeSource{}, }, }, }, diff --git a/pkg/kubelet/volume/empty_dir/empty_dir.go b/pkg/kubelet/volume/empty_dir/empty_dir.go index 2df9540f054cb..d48fae9e5a042 100644 --- a/pkg/kubelet/volume/empty_dir/empty_dir.go +++ b/pkg/kubelet/volume/empty_dir/empty_dir.go @@ -60,10 +60,10 @@ func (plugin *emptyDirPlugin) CanSupport(spec *api.Volume) bool { return false } - if util.AllPtrFieldsNil(&spec.Source) { + if util.AllPtrFieldsNil(&spec.VolumeSource) { return true } - if spec.Source.EmptyDir != nil { + if spec.EmptyDir != nil { return true } return false diff --git a/pkg/kubelet/volume/empty_dir/empty_dir_test.go b/pkg/kubelet/volume/empty_dir/empty_dir_test.go index 7e543d4e4ab71..15c1e335e8770 100644 --- a/pkg/kubelet/volume/empty_dir/empty_dir_test.go +++ b/pkg/kubelet/volume/empty_dir/empty_dir_test.go @@ -36,10 +36,10 @@ func TestCanSupport(t *testing.T) { if plug.Name() != "kubernetes.io/empty-dir" { 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") } - if !plug.CanSupport(&api.Volume{Source: api.VolumeSource{}}) { + if !plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{}}) { t.Errorf("Expected true") } } @@ -53,8 +53,8 @@ func TestPlugin(t *testing.T) { t.Errorf("Can't find the plugin by name") } spec := &api.Volume{ - Name: "vol1", - Source: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}, + Name: "vol1", + VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}, } builder, err := plug.NewBuilder(spec, types.UID("poduid")) if err != nil { @@ -134,11 +134,11 @@ func TestPluginLegacy(t *testing.T) { if plug.Name() != "empty" { 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") } - 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") } diff --git a/pkg/kubelet/volume/gce_pd/gce_pd.go b/pkg/kubelet/volume/gce_pd/gce_pd.go index ff05add1f3343..413514a24f31f 100644 --- a/pkg/kubelet/volume/gce_pd/gce_pd.go +++ b/pkg/kubelet/volume/gce_pd/gce_pd.go @@ -64,7 +64,7 @@ func (plugin *gcePersistentDiskPlugin) CanSupport(spec *api.Volume) bool { return false } - if spec.Source.GCEPersistentDisk != nil { + if spec.GCEPersistentDisk != nil { return true } 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") } - pdName := spec.Source.GCEPersistentDisk.PDName - fsType := spec.Source.GCEPersistentDisk.FSType + pdName := spec.GCEPersistentDisk.PDName + fsType := spec.GCEPersistentDisk.FSType partition := "" - if spec.Source.GCEPersistentDisk.Partition != 0 { - partition = strconv.Itoa(spec.Source.GCEPersistentDisk.Partition) + if spec.GCEPersistentDisk.Partition != 0 { + partition = strconv.Itoa(spec.GCEPersistentDisk.Partition) } - readOnly := spec.Source.GCEPersistentDisk.ReadOnly + readOnly := spec.GCEPersistentDisk.ReadOnly return &gcePersistentDisk{ podUID: podUID, diff --git a/pkg/kubelet/volume/gce_pd/gce_pd_test.go b/pkg/kubelet/volume/gce_pd/gce_pd_test.go index dd79592cf39fa..1ee50b49862da 100644 --- a/pkg/kubelet/volume/gce_pd/gce_pd_test.go +++ b/pkg/kubelet/volume/gce_pd/gce_pd_test.go @@ -36,7 +36,7 @@ func TestCanSupport(t *testing.T) { if plug.Name() != "kubernetes.io/gce-pd" { 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") } } @@ -73,7 +73,7 @@ func TestPlugin(t *testing.T) { } spec := &api.Volume{ Name: "vol1", - Source: api.VolumeSource{ + VolumeSource: api.VolumeSource{ GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{ PDName: "pd", FSType: "ext4", @@ -140,11 +140,11 @@ func TestPluginLegacy(t *testing.T) { if plug.Name() != "gce-pd" { 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") } - 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") } diff --git a/pkg/kubelet/volume/git_repo/git_repo.go b/pkg/kubelet/volume/git_repo/git_repo.go index 1409444ba2241..5ac06b7d5c7c6 100644 --- a/pkg/kubelet/volume/git_repo/git_repo.go +++ b/pkg/kubelet/volume/git_repo/git_repo.go @@ -63,7 +63,7 @@ func (plugin *gitRepoPlugin) CanSupport(spec *api.Volume) bool { return false } - if spec.Source.GitRepo != nil { + if spec.GitRepo != nil { return true } return false @@ -77,8 +77,8 @@ func (plugin *gitRepoPlugin) NewBuilder(spec *api.Volume, podUID types.UID) (vol return &gitRepo{ podUID: podUID, volName: spec.Name, - source: spec.Source.GitRepo.Repository, - revision: spec.Source.GitRepo.Revision, + source: spec.GitRepo.Repository, + revision: spec.GitRepo.Revision, exec: exec.New(), plugin: plugin, legacyMode: false, diff --git a/pkg/kubelet/volume/git_repo/git_repo_test.go b/pkg/kubelet/volume/git_repo/git_repo_test.go index 507a8593206b3..626b50ecdfa2e 100644 --- a/pkg/kubelet/volume/git_repo/git_repo_test.go +++ b/pkg/kubelet/volume/git_repo/git_repo_test.go @@ -49,7 +49,7 @@ func TestCanSupport(t *testing.T) { if plug.Name() != "kubernetes.io/git-repo" { 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") } } @@ -110,7 +110,7 @@ func TestPlugin(t *testing.T) { } spec := &api.Volume{ Name: "vol1", - Source: api.VolumeSource{ + VolumeSource: api.VolumeSource{ GitRepo: &api.GitRepoVolumeSource{ Repository: "https://github.com/GoogleCloudPlatform/kubernetes.git", Revision: "2a30ce65c5ab586b98916d83385c5983edd353a1", @@ -168,11 +168,11 @@ func TestPluginLegacy(t *testing.T) { if plug.Name() != "git" { 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") } - 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") } diff --git a/pkg/kubelet/volume/host_path/host_path.go b/pkg/kubelet/volume/host_path/host_path.go index 9e34e3e75b356..2f06a62b324e7 100644 --- a/pkg/kubelet/volume/host_path/host_path.go +++ b/pkg/kubelet/volume/host_path/host_path.go @@ -46,14 +46,14 @@ func (plugin *hostPathPlugin) Name() string { } func (plugin *hostPathPlugin) CanSupport(spec *api.Volume) bool { - if spec.Source.HostPath != nil { + if spec.HostPath != nil { return true } return false } 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) { diff --git a/pkg/kubelet/volume/host_path/host_path_test.go b/pkg/kubelet/volume/host_path/host_path_test.go index d0824bbf8ae23..22b64984d3d28 100644 --- a/pkg/kubelet/volume/host_path/host_path_test.go +++ b/pkg/kubelet/volume/host_path/host_path_test.go @@ -35,10 +35,10 @@ func TestCanSupport(t *testing.T) { if plug.Name() != "kubernetes.io/host-path" { 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") } - if plug.CanSupport(&api.Volume{Source: api.VolumeSource{}}) { + if plug.CanSupport(&api.Volume{VolumeSource: api.VolumeSource{}}) { t.Errorf("Expected false") } } @@ -52,8 +52,8 @@ func TestPlugin(t *testing.T) { t.Errorf("Can't find the plugin by name") } spec := &api.Volume{ - Name: "vol1", - Source: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/vol1"}}, + Name: "vol1", + VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{"/vol1"}}, } builder, err := plug.NewBuilder(spec, types.UID("poduid")) if err != nil { diff --git a/pkg/kubelet/volume/secret/secret.go b/pkg/kubelet/volume/secret/secret.go index 1db22edb93822..73d6fc4ab29b4 100644 --- a/pkg/kubelet/volume/secret/secret.go +++ b/pkg/kubelet/volume/secret/secret.go @@ -51,7 +51,7 @@ func (plugin *secretPlugin) Name() string { } func (plugin *secretPlugin) CanSupport(spec *api.Volume) bool { - if spec.Source.Secret != nil { + if spec.Secret != nil { 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) { - 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) { diff --git a/pkg/kubelet/volume/secret/secret_test.go b/pkg/kubelet/volume/secret/secret_test.go index 6b6c6f8306ac4..057840e415fdb 100644 --- a/pkg/kubelet/volume/secret/secret_test.go +++ b/pkg/kubelet/volume/secret/secret_test.go @@ -50,7 +50,7 @@ func TestCanSupport(t *testing.T) { if plugin.Name() != secretPluginName { 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") } } @@ -65,7 +65,7 @@ func TestPlugin(t *testing.T) { volumeSpec := &api.Volume{ Name: testVolumeName, - Source: api.VolumeSource{ + VolumeSource: api.VolumeSource{ Secret: &api.SecretVolumeSource{ Target: api.ObjectReference{ Namespace: testNamespace, diff --git a/pkg/scheduler/predicates.go b/pkg/scheduler/predicates.go index 6572fbeae6781..b394120497fab 100644 --- a/pkg/scheduler/predicates.go +++ b/pkg/scheduler/predicates.go @@ -51,15 +51,15 @@ func (nodes ClientNodeInfo) GetNodeInfo(nodeID string) (*api.Node, error) { } func isVolumeConflict(volume api.Volume, pod *api.Pod) bool { - if volume.Source.GCEPersistentDisk == nil { + if volume.GCEPersistentDisk == nil { return false } - pdName := volume.Source.GCEPersistentDisk.PDName + pdName := volume.GCEPersistentDisk.PDName manifest := &(pod.Spec) for ix := range manifest.Volumes { - if manifest.Volumes[ix].Source.GCEPersistentDisk != nil && - manifest.Volumes[ix].Source.GCEPersistentDisk.PDName == pdName { + if manifest.Volumes[ix].GCEPersistentDisk != nil && + manifest.Volumes[ix].GCEPersistentDisk.PDName == pdName { return true } } diff --git a/pkg/scheduler/predicates_test.go b/pkg/scheduler/predicates_test.go index 717092b2e5dbf..4a1f8de258ad6 100644 --- a/pkg/scheduler/predicates_test.go +++ b/pkg/scheduler/predicates_test.go @@ -276,7 +276,7 @@ func TestDiskConflicts(t *testing.T) { volState := api.PodSpec{ Volumes: []api.Volume{ { - Source: api.VolumeSource{ + VolumeSource: api.VolumeSource{ GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{ PDName: "foo", }, @@ -287,7 +287,7 @@ func TestDiskConflicts(t *testing.T) { volState2 := api.PodSpec{ Volumes: []api.Volume{ { - Source: api.VolumeSource{ + VolumeSource: api.VolumeSource{ GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{ PDName: "bar", }, diff --git a/test/e2e/pd.go b/test/e2e/pd.go index c74b2389deabf..5d1245b29ee3a 100644 --- a/test/e2e/pd.go +++ b/test/e2e/pd.go @@ -192,7 +192,7 @@ func testPDPod(diskName, targetHost string, readOnly bool) *api.Pod { Volumes: []api.Volume{ { Name: "testpd", - Source: api.VolumeSource{ + VolumeSource: api.VolumeSource{ GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{ PDName: diskName, FSType: "ext4", diff --git a/test/e2e/secrets.go b/test/e2e/secrets.go index 122ed734dacf6..bf2e6f749b501 100644 --- a/test/e2e/secrets.go +++ b/test/e2e/secrets.go @@ -79,7 +79,7 @@ var _ = Describe("Secrets", func() { Volumes: []api.Volume{ { Name: volumeName, - Source: api.VolumeSource{ + VolumeSource: api.VolumeSource{ Secret: &api.SecretVolumeSource{ Target: api.ObjectReference{ Kind: "Secret", diff --git a/test/e2e/service.go b/test/e2e/service.go index 1a90003de582a..406efba9ec154 100644 --- a/test/e2e/service.go +++ b/test/e2e/service.go @@ -75,7 +75,7 @@ var _ = Describe("Services", func() { Volumes: []api.Volume{ { Name: "results", - Source: api.VolumeSource{ + VolumeSource: api.VolumeSource{ EmptyDir: &api.EmptyDirVolumeSource{}, }, },