Merge pull request #1102 from lavalamp/fixApi

Fix incorrect tag in MinionList
This commit is contained in:
Clayton Coleman 2014-08-29 10:54:15 -04:00
commit 821f9bd5e7
4 changed files with 101 additions and 2 deletions

View File

@ -61,6 +61,23 @@ func init() {
}
return nil
},
// MinionList.Items had a wrong name in v1beta1
func(in *MinionList, out *v1beta1.MinionList) error {
Convert(&in.JSONBase, &out.JSONBase)
Convert(&in.Items, &out.Items)
out.Minions = out.Items
return nil
},
func(in *v1beta1.MinionList, out *MinionList) error {
Convert(&in.JSONBase, &out.JSONBase)
if len(in.Items) == 0 {
Convert(&in.Minions, &out.Items)
} else {
Convert(&in.Items, &out.Items)
}
return nil
},
)
}

View File

@ -110,3 +110,82 @@ func TestVolumeMountConversionToNew(t *testing.T) {
}
}
}
func TestMinionListConversionToNew(t *testing.T) {
oldMinion := func(id string) v1beta1.Minion {
return v1beta1.Minion{JSONBase: v1beta1.JSONBase{ID: id}}
}
newMinion := func(id string) Minion {
return Minion{JSONBase: JSONBase{ID: id}}
}
oldMinions := []v1beta1.Minion{
oldMinion("foo"),
oldMinion("bar"),
}
newMinions := []Minion{
newMinion("foo"),
newMinion("bar"),
}
table := []struct {
oldML *v1beta1.MinionList
newML *MinionList
}{
{
oldML: &v1beta1.MinionList{Items: oldMinions},
newML: &MinionList{Items: newMinions},
}, {
oldML: &v1beta1.MinionList{Minions: oldMinions},
newML: &MinionList{Items: newMinions},
}, {
oldML: &v1beta1.MinionList{
Items: oldMinions,
Minions: []v1beta1.Minion{oldMinion("baz")},
},
newML: &MinionList{Items: newMinions},
},
}
for _, item := range table {
got := &MinionList{}
err := Convert(item.oldML, got)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if e, a := item.newML, got; !reflect.DeepEqual(e, a) {
t.Errorf("Expected: %#v, got %#v", e, a)
}
}
}
func TestMinionListConversionToOld(t *testing.T) {
oldMinion := func(id string) v1beta1.Minion {
return v1beta1.Minion{JSONBase: v1beta1.JSONBase{ID: id}}
}
newMinion := func(id string) Minion {
return Minion{JSONBase: JSONBase{ID: id}}
}
oldMinions := []v1beta1.Minion{
oldMinion("foo"),
oldMinion("bar"),
}
newMinions := []Minion{
newMinion("foo"),
newMinion("bar"),
}
newML := &MinionList{Items: newMinions}
oldML := &v1beta1.MinionList{
Items: oldMinions,
Minions: oldMinions,
}
got := &v1beta1.MinionList{}
err := Convert(newML, got)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if e, a := oldML, got; !reflect.DeepEqual(e, a) {
t.Errorf("Expected: %#v, got %#v", e, a)
}
}

View File

@ -339,7 +339,7 @@ type Minion struct {
// MinionList is a list of minions.
type MinionList struct {
JSONBase `json:",inline" yaml:",inline"`
Items []Minion `json:"minions,omitempty" yaml:"minions,omitempty"`
Items []Minion `json:"items,omitempty" yaml:"items,omitempty"`
}
// Binding is written by a scheduler to cause a pod to be bound to a host.

View File

@ -349,7 +349,10 @@ type Minion struct {
// MinionList is a list of minions.
type MinionList struct {
JSONBase `json:",inline" yaml:",inline"`
Items []Minion `json:"minions,omitempty" yaml:"minions,omitempty"`
// DEPRECATED: the below Minions is due to a naming mistake and
// will be replaced with Items in the future.
Minions []Minion `json:"minions,omitempty" yaml:"minions,omitempty"`
Items []Minion `json:"items,omitempty" yaml:"items,omitempty"`
}
// Binding is written by a scheduler to cause a pod to be bound to a host.