Commit a6db26d5 authored by Cao Shufeng's avatar Cao Shufeng

Reorganize the output of "kubectl get -o json"

"resourceVersion" and "selfLink" are members of "metadata" rather than the list. This change reorganize the struct to provide consistency with other places. Before this change: "kind": "List", "metadata": {}, "resourceVersion": "", "selfLink": "" After this change: "kind": "List", "metadata": { "resourceVersion": "", "selfLink": "" } Reference: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go#L57
parent b4c76c6a
...@@ -362,8 +362,10 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [ ...@@ -362,8 +362,10 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
}, },
} }
if listMeta, err := meta.ListAccessor(obj); err == nil { if listMeta, err := meta.ListAccessor(obj); err == nil {
list.Object["selfLink"] = listMeta.GetSelfLink() list.Object["metadata"] = map[string]interface{}{
list.Object["resourceVersion"] = listMeta.GetResourceVersion() "selfLink": listMeta.GetSelfLink(),
"resourceVersion": listMeta.GetResourceVersion(),
}
} }
for _, item := range items { for _, item := range items {
......
...@@ -603,7 +603,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) { ...@@ -603,7 +603,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
} }
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]),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment