mirror of https://github.com/k3s-io/k3s
Merge pull request #44293 from deads2k/api-08-unstructureditems
Automatic merge from submit-queue (batch tested with PRs 43545, 44293, 44221, 43888) make unstructured items correspond to other items for storage "normal" `Items` elements include the struct itself, not a pointer to the struct. Some of the deeper bits of storage rely on this behavior in reflective paths. This updates the `UnstructuredList` to be "normal". @kubernetes/sig-api-machinery-pr-reviewspull/6/head
commit
867159416f
|
@ -316,7 +316,7 @@ func TestSetListToMatchingType(t *testing.T) {
|
||||||
t.Fatalf("Expected %v, got %v", e, a)
|
t.Fatalf("Expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
for i := range list {
|
for i := range list {
|
||||||
if e, a := list[i], pl.Items[i]; e != a {
|
if e, a := list[i], &pl.Items[i]; !reflect.DeepEqual(e, a) {
|
||||||
t.Fatalf("%d: unmatched: %s", i, diff.ObjectDiff(e, a))
|
t.Fatalf("%d: unmatched: %s", i, diff.ObjectDiff(e, a))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ func TestDecode(t *testing.T) {
|
||||||
json: []byte(`{"items": [{"metadata": {"name": "object1"}, "apiVersion": "test", "kind": "test_kind"}, {"metadata": {"name": "object2"}, "apiVersion": "test", "kind": "test_kind"}], "apiVersion": "test", "kind": "test_list"}`),
|
json: []byte(`{"items": [{"metadata": {"name": "object1"}, "apiVersion": "test", "kind": "test_kind"}, {"metadata": {"name": "object2"}, "apiVersion": "test", "kind": "test_kind"}], "apiVersion": "test", "kind": "test_list"}`),
|
||||||
want: &unstructured.UnstructuredList{
|
want: &unstructured.UnstructuredList{
|
||||||
Object: map[string]interface{}{"apiVersion": "test", "kind": "test_list"},
|
Object: map[string]interface{}{"apiVersion": "test", "kind": "test_list"},
|
||||||
Items: []*unstructured.Unstructured{
|
Items: []unstructured.Unstructured{
|
||||||
{
|
{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
"metadata": map[string]interface{}{"name": "object1"},
|
"metadata": map[string]interface{}{"name": "object1"},
|
||||||
|
|
|
@ -182,7 +182,7 @@ func runEdit(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
l.Items = append(l.Items, info.Object.(*unstructured.Unstructured))
|
l.Items = append(l.Items, *info.Object.(*unstructured.Unstructured))
|
||||||
}
|
}
|
||||||
originalObj = l
|
originalObj = l
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,7 +339,7 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
list.Items = append(list.Items, info.Object.(*unstructured.Unstructured))
|
list.Items = append(list.Items, *info.Object.(*unstructured.Unstructured))
|
||||||
}
|
}
|
||||||
obj = list
|
obj = list
|
||||||
} else {
|
} else {
|
||||||
|
@ -367,7 +367,7 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
list.Items = append(list.Items, item.(*unstructured.Unstructured))
|
list.Items = append(list.Items, *item.(*unstructured.Unstructured))
|
||||||
}
|
}
|
||||||
if err := printer.PrintObj(list, out); err != nil {
|
if err := printer.PrintObj(list, out); err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
|
|
|
@ -590,7 +590,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
|
||||||
cmd.Run(cmd, []string{"pods,services"})
|
cmd.Run(cmd, []string{"pods,services"})
|
||||||
|
|
||||||
actual := tf.CommandPrinter.(*testPrinter).Objects
|
actual := tf.CommandPrinter.(*testPrinter).Objects
|
||||||
fn := func(obj runtime.Object) *unstructured.Unstructured {
|
fn := func(obj runtime.Object) unstructured.Unstructured {
|
||||||
data, err := runtime.Encode(api.Codecs.LegacyCodec(schema.GroupVersion{Version: "v1"}), obj)
|
data, err := runtime.Encode(api.Codecs.LegacyCodec(schema.GroupVersion{Version: "v1"}), obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -599,12 +599,12 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
|
||||||
if err := encjson.Unmarshal(data, &out.Object); err != nil {
|
if err := encjson.Unmarshal(data, &out.Object); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return out
|
return *out
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := &unstructured.UnstructuredList{
|
expected := &unstructured.UnstructuredList{
|
||||||
Object: map[string]interface{}{"kind": "List", "apiVersion": "v1", "metadata": map[string]interface{}{}, "selfLink": "", "resourceVersion": ""},
|
Object: map[string]interface{}{"kind": "List", "apiVersion": "v1", "metadata": map[string]interface{}{}, "selfLink": "", "resourceVersion": ""},
|
||||||
Items: []*unstructured.Unstructured{
|
Items: []unstructured.Unstructured{
|
||||||
fn(&pods.Items[0]),
|
fn(&pods.Items[0]),
|
||||||
fn(&pods.Items[1]),
|
fn(&pods.Items[1]),
|
||||||
fn(&svc.Items[0]),
|
fn(&svc.Items[0]),
|
||||||
|
|
|
@ -275,7 +275,7 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
"kind": "List",
|
"kind": "List",
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
},
|
},
|
||||||
Items: []*unstructured.Unstructured{
|
Items: []unstructured.Unstructured{
|
||||||
{
|
{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
"kind": "ReplicationController",
|
"kind": "ReplicationController",
|
||||||
|
@ -308,7 +308,7 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
"kind": "List",
|
"kind": "List",
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
},
|
},
|
||||||
Items: []*unstructured.Unstructured{
|
Items: []unstructured.Unstructured{
|
||||||
{
|
{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
"kind": "ReplicationController",
|
"kind": "ReplicationController",
|
||||||
|
@ -345,7 +345,7 @@ func TestSortingPrinter(t *testing.T) {
|
||||||
"kind": "List",
|
"kind": "List",
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
},
|
},
|
||||||
Items: []*unstructured.Unstructured{
|
Items: []unstructured.Unstructured{
|
||||||
{
|
{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
"kind": "ReplicationController",
|
"kind": "ReplicationController",
|
||||||
|
|
|
@ -471,7 +471,7 @@ type UnstructuredList struct {
|
||||||
Object map[string]interface{}
|
Object map[string]interface{}
|
||||||
|
|
||||||
// Items is a list of unstructured objects.
|
// Items is a list of unstructured objects.
|
||||||
Items []*Unstructured `json:"items"`
|
Items []Unstructured `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON ensures that the unstructured list object produces proper
|
// MarshalJSON ensures that the unstructured list object produces proper
|
||||||
|
@ -672,7 +672,7 @@ func (s unstructuredJSONScheme) decodeToList(data []byte, list *UnstructuredList
|
||||||
unstruct.SetKind(itemKind)
|
unstruct.SetKind(itemKind)
|
||||||
unstruct.SetAPIVersion(listAPIVersion)
|
unstruct.SetAPIVersion(listAPIVersion)
|
||||||
}
|
}
|
||||||
list.Items = append(list.Items, unstruct)
|
list.Items = append(list.Items, *unstruct)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import "testing"
|
||||||
func TestUnstructuredList(t *testing.T) {
|
func TestUnstructuredList(t *testing.T) {
|
||||||
list := &UnstructuredList{
|
list := &UnstructuredList{
|
||||||
Object: map[string]interface{}{"kind": "List", "apiVersion": "v1"},
|
Object: map[string]interface{}{"kind": "List", "apiVersion": "v1"},
|
||||||
Items: []*Unstructured{
|
Items: []Unstructured{
|
||||||
{Object: map[string]interface{}{"kind": "Pod", "apiVersion": "v1", "metadata": map[string]interface{}{"name": "test"}}},
|
{Object: map[string]interface{}{"kind": "Pod", "apiVersion": "v1", "metadata": map[string]interface{}{"name": "test"}}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,9 +90,9 @@ func TestList(t *testing.T) {
|
||||||
"apiVersion": "vTest",
|
"apiVersion": "vTest",
|
||||||
"kind": "rTestList",
|
"kind": "rTestList",
|
||||||
},
|
},
|
||||||
Items: []*unstructured.Unstructured{
|
Items: []unstructured.Unstructured{
|
||||||
getObject("vTest", "rTest", "item1"),
|
*getObject("vTest", "rTest", "item1"),
|
||||||
getObject("vTest", "rTest", "item2"),
|
*getObject("vTest", "rTest", "item2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -108,9 +108,9 @@ func TestList(t *testing.T) {
|
||||||
"apiVersion": "vTest",
|
"apiVersion": "vTest",
|
||||||
"kind": "rTestList",
|
"kind": "rTestList",
|
||||||
},
|
},
|
||||||
Items: []*unstructured.Unstructured{
|
Items: []unstructured.Unstructured{
|
||||||
getObject("vTest", "rTest", "item1"),
|
*getObject("vTest", "rTest", "item1"),
|
||||||
getObject("vTest", "rTest", "item2"),
|
*getObject("vTest", "rTest", "item2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -106,7 +106,7 @@ func TestDynamicClient(t *testing.T) {
|
||||||
t.Fatalf("expected one pod, got %d", len(unstructuredList.Items))
|
t.Fatalf("expected one pod, got %d", len(unstructuredList.Items))
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := unstructuredToPod(unstructuredList.Items[0])
|
got, err := unstructuredToPod(&unstructuredList.Items[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error converting Unstructured to v1.Pod: %v", err)
|
t.Fatalf("unexpected error converting Unstructured to v1.Pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue