From dd9ed71429999bd267db53c9533a6224ff48e719 Mon Sep 17 00:00:00 2001 From: Morten Torkildsen Date: Thu, 18 Oct 2018 15:17:09 -0700 Subject: [PATCH] fix(helm): Update status output to include resource details (#4791) Update of the client-go package changed the status output to only include the age of resources. The new printer in client-go only formats the output to include details of specific resources if the internal representation of resources are passed into the printer. This PR updates helm to convert resources to the internal type before printing. Closes #4712 Signed-off-by: Morten Torkildsen --- pkg/kube/client.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 67960ac46..6509a1583 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -163,7 +163,7 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) { return "", err } - var objPods = make(map[string][]v1.Pod) + var objPods = make(map[string][]core.Pod) missing := []string{} err = perform(infos, func(info *resource.Info) error { @@ -178,7 +178,15 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) { // versions per cluster, but this certainly won't hurt anything, so let's be safe. gvk := info.ResourceMapping().GroupVersionKind vk := gvk.Version + "/" + gvk.Kind - objs[vk] = append(objs[vk], asVersioned(info)) + internalObj, err := asInternal(info) + if err != nil { + c.Log("Warning: conversion to internal type failed: %v", err) + // Add the unstructured object in this situation. It will still get listed, just + // with less information. + objs[vk] = append(objs[vk], info.Object) + } else { + objs[vk] = append(objs[vk], internalObj) + } //Get the relation pods objPods, err = c.getSelectRelationPod(info, objPods) @@ -682,7 +690,7 @@ func isPodComplete(event watch.Event) (bool, error) { //get a kubernetes resources' relation pods // kubernetes resource used select labels to relate pods -func (c *Client) getSelectRelationPod(info *resource.Info, objPods map[string][]v1.Pod) (map[string][]v1.Pod, error) { +func (c *Client) getSelectRelationPod(info *resource.Info, objPods map[string][]core.Pod) (map[string][]core.Pod, error) { if info == nil { return objPods, nil } @@ -705,7 +713,9 @@ func (c *Client) getSelectRelationPod(info *resource.Info, objPods map[string][] return objPods, err } - for _, pod := range pods.Items { + for _, externalPod := range pods.Items { + pod := core.Pod{} + legacyscheme.Scheme.Convert(&externalPod, &pod, nil) if pod.APIVersion == "" { pod.APIVersion = "v1" } @@ -722,7 +732,7 @@ func (c *Client) getSelectRelationPod(info *resource.Info, objPods map[string][] return objPods, nil } -func isFoundPod(podItem []v1.Pod, pod v1.Pod) bool { +func isFoundPod(podItem []core.Pod, pod core.Pod) bool { for _, value := range podItem { if (value.Namespace == pod.Namespace) && (value.Name == pod.Name) { return true @@ -734,3 +744,8 @@ func isFoundPod(podItem []v1.Pod, pod v1.Pod) bool { func asVersioned(info *resource.Info) runtime.Object { return cmdutil.AsDefaultVersionedOrOriginal(info.Object, info.Mapping) } + +func asInternal(info *resource.Info) (runtime.Object, error) { + groupVersioner := info.Mapping.GroupVersionKind.GroupKind().WithVersion(runtime.APIVersionInternal).GroupVersion() + return legacyscheme.Scheme.ConvertToVersion(info.Object, groupVersioner) +}