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
pull/6/head
Cao Shufeng 2017-03-31 05:27:25 -04:00
parent b4c76c6aa2
commit a6db26d5b7
2 changed files with 5 additions and 3 deletions

View File

@ -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 {
list.Object["selfLink"] = listMeta.GetSelfLink()
list.Object["resourceVersion"] = listMeta.GetResourceVersion()
list.Object["metadata"] = map[string]interface{}{
"selfLink": listMeta.GetSelfLink(),
"resourceVersion": listMeta.GetResourceVersion(),
}
}
for _, item := range items {

View File

@ -603,7 +603,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
}
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{
fn(&pods.Items[0]),
fn(&pods.Items[1]),