diff --git a/pkg/api/conversion.go b/pkg/api/conversion.go index 6e18834ba52..39dfb653d88 100644 --- a/pkg/api/conversion.go +++ b/pkg/api/conversion.go @@ -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 + }, ) } diff --git a/pkg/api/conversion_test.go b/pkg/api/conversion_test.go index bcfebe8470f..11e2e71868e 100644 --- a/pkg/api/conversion_test.go +++ b/pkg/api/conversion_test.go @@ -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) + } +} diff --git a/pkg/api/types.go b/pkg/api/types.go index 9e3f61845e9..646c006150b 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -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. diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index 74468ce3961..007dbb502b4 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -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.