Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make unstructured items correspond to other items for storage #44293

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/apimachinery/tests/api_meta_help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func TestSetListToMatchingType(t *testing.T) {
t.Fatalf("Expected %v, got %v", e, a)
}
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))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}`),
want: &unstructured.UnstructuredList{
Object: map[string]interface{}{"apiVersion": "test", "kind": "test_list"},
Items: []*unstructured.Unstructured{
Items: []unstructured.Unstructured{
{
Object: map[string]interface{}{
"metadata": map[string]interface{}{"name": "object1"},
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func runEdit(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args
},
}
for _, info := range infos {
l.Items = append(l.Items, info.Object.(*unstructured.Unstructured))
l.Items = append(l.Items, *info.Object.(*unstructured.Unstructured))
}
originalObj = l
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
},
}
for _, info := range infos {
list.Items = append(list.Items, info.Object.(*unstructured.Unstructured))
list.Items = append(list.Items, *info.Object.(*unstructured.Unstructured))
}
obj = list
} else {
Expand Down Expand Up @@ -367,7 +367,7 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
}

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 {
errs = append(errs, err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubectl/cmd/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
cmd.Run(cmd, []string{"pods,services"})

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)
if err != nil {
panic(err)
Expand All @@ -599,12 +599,12 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
if err := encjson.Unmarshal(data, &out.Object); err != nil {
panic(err)
}
return out
return *out
}

expected := &unstructured.UnstructuredList{
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[1]),
fn(&svc.Items[0]),
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubectl/sorting_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func TestSortingPrinter(t *testing.T) {
"kind": "List",
"apiVersion": "v1",
},
Items: []*unstructured.Unstructured{
Items: []unstructured.Unstructured{
{
Object: map[string]interface{}{
"kind": "ReplicationController",
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestSortingPrinter(t *testing.T) {
"kind": "List",
"apiVersion": "v1",
},
Items: []*unstructured.Unstructured{
Items: []unstructured.Unstructured{
{
Object: map[string]interface{}{
"kind": "ReplicationController",
Expand Down Expand Up @@ -345,7 +345,7 @@ func TestSortingPrinter(t *testing.T) {
"kind": "List",
"apiVersion": "v1",
},
Items: []*unstructured.Unstructured{
Items: []unstructured.Unstructured{
{
Object: map[string]interface{}{
"kind": "ReplicationController",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ type UnstructuredList struct {
Object map[string]interface{}

// Items is a list of unstructured objects.
Items []*Unstructured `json:"items"`
Items []Unstructured `json:"items"`
}

// MarshalJSON ensures that the unstructured list object produces proper
Expand Down Expand Up @@ -642,7 +642,7 @@ func (s unstructuredJSONScheme) decodeToList(data []byte, list *UnstructuredList
unstruct.SetKind(itemKind)
unstruct.SetAPIVersion(listAPIVersion)
}
list.Items = append(list.Items, unstruct)
list.Items = append(list.Items, *unstruct)
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import "testing"
func TestUnstructuredList(t *testing.T) {
list := &UnstructuredList{
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"}}},
},
}
Expand Down
12 changes: 6 additions & 6 deletions staging/src/k8s.io/client-go/dynamic/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func TestList(t *testing.T) {
"apiVersion": "vTest",
"kind": "rTestList",
},
Items: []*unstructured.Unstructured{
getObject("vTest", "rTest", "item1"),
getObject("vTest", "rTest", "item2"),
Items: []unstructured.Unstructured{
*getObject("vTest", "rTest", "item1"),
*getObject("vTest", "rTest", "item2"),
},
},
},
Expand All @@ -108,9 +108,9 @@ func TestList(t *testing.T) {
"apiVersion": "vTest",
"kind": "rTestList",
},
Items: []*unstructured.Unstructured{
getObject("vTest", "rTest", "item1"),
getObject("vTest", "rTest", "item2"),
Items: []unstructured.Unstructured{
*getObject("vTest", "rTest", "item1"),
*getObject("vTest", "rTest", "item2"),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/integration/client/dynamic_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestDynamicClient(t *testing.T) {
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 {
t.Fatalf("unexpected error converting Unstructured to v1.Pod: %v", err)
}
Expand Down