mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #5001 from brendandburns/api3
Embed VolumeSource in v1beta3 and internal.
This commit is contained in:
commit
fdea7252a4
@ -38,6 +38,5 @@ spec:
|
||||
name: data
|
||||
volumes:
|
||||
- name: data
|
||||
source:
|
||||
emptyDir: {}
|
||||
emptyDir: {}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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{},
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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."))
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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{
|
||||
|
@ -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"},
|
||||
},
|
||||
},
|
||||
|
@ -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{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
},
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -75,7 +75,7 @@ var _ = Describe("Services", func() {
|
||||
Volumes: []api.Volume{
|
||||
{
|
||||
Name: "results",
|
||||
Source: api.VolumeSource{
|
||||
VolumeSource: api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user