Skip to content

Supporting helm3 to show up resource names that were deployed as part… - #7728

Closed
sarvaniy wants to merge 7 commits into
helm:mainfrom
sarvaniy:master
Closed

sarvaniy wants to merge 7 commits into
helm:mainfrom
sarvaniy:master

Conversation

@sarvaniy

@sarvaniy sarvaniy commented Mar 4, 2020

Copy link
Copy Markdown

… of release in helm status command

@helm-bot helm-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 4, 2020
@bacongobbler

Copy link
Copy Markdown
Member

Hi @sarvaniy. Would you mind looking into the failing tests?

@bacongobbler

Copy link
Copy Markdown
Member

If I'm reading the code correctly... This is just a port of Helm 2's implementation of helm status, and it includes the same issues present in #6896.

><> ./bin/helm status wordpress-1583444922
NAME: wordpress-1583444922
LAST DEPLOYED: Thu Mar  5 13:48:43 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
RESOURCES: 
==> v1/StatefulSet
NAME                           AGE
wordpress-1583444922-mariadb   14s

==> v1/Secret
NAME                           AGE
wordpress-1583444922-mariadb   14s
wordpress-1583444922   14s

==> v1/ConfigMap
NAME                           AGE
wordpress-1583444922-mariadb   14s
wordpress-1583444922-mariadb-tests   14s

==> v1/PersistentVolumeClaim
NAME                   AGE
wordpress-1583444922   14s

==> v1/Service
NAME                           AGE
wordpress-1583444922-mariadb   14s
wordpress-1583444922   14s

Compare that to the output of helm get manifest wordpress-1583444922 | kubectl get -f -:

NAME                                  TYPE     DATA   AGE
secret/wordpress-1583444922-mariadb   Opaque   2      7m5s
secret/wordpress-1583444922           Opaque   1      7m5s

NAME                                           DATA   AGE
configmap/wordpress-1583444922-mariadb         1      7m5s
configmap/wordpress-1583444922-mariadb-tests   1      7m5s

NAME                                         STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/wordpress-1583444922   Bound    pvc-3f235358-5fa8-4756-ad63-e82baea0e11f   10Gi       RWO            standard       7m5s

NAME                                   TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE
service/wordpress-1583444922-mariadb   ClusterIP      10.96.24.123   <none>        3306/TCP                     7m5s
service/wordpress-1583444922           LoadBalancer   10.96.42.32    <pending>     80:31619/TCP,443:30839/TCP   7m5s

NAME                                   READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/wordpress-1583444922   1/1     1            1           7m5s

NAME                                            READY   AGE
statefulset.apps/wordpress-1583444922-mariadb   1/1     7m5s

Can you please look further into the implementation details of kubectl get such that the output of helm status matches the output of kubectl get?

Comment thread pkg/kube/client.go Outdated
return &Result{Created: resources}, nil
}

func (c *Client) Get(rel *release.Release) (string, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should accept a ResourceList similar to Create and Update. It should be the job of the client to call .Build to retrieve a result and pass that along to Get.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bacongobbler

Hi,
I had modified the code as per your suggestion. I had gone through "kubectl get" implementation in depper. I found that Transformrequests is used to get the status of resources instead of rely on packages internal to kubernetes/kubernetes.

I had modified the code and tested, it worked fine. Could you please review it. You can check the resources output in below conservations.

@bacongobbler

Copy link
Copy Markdown
Member

I started playing around with this to see what we can do.

import (
	"context"
	"encoding/json"
	"fmt"
	"io"
	"strings"
	"sync"
	"time"

	jsonpatch "github.com/evanphx/json-patch"
	"github.com/pkg/errors"
	batch "k8s.io/api/batch/v1"
	v1 "k8s.io/api/core/v1"
	apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
	apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
	apierrors "k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/api/meta"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/fields"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/types"
	"k8s.io/apimachinery/pkg/util/strategicpatch"
	"k8s.io/apimachinery/pkg/watch"
	"k8s.io/cli-runtime/pkg/genericclioptions"
	genericprinters "k8s.io/cli-runtime/pkg/printers"
	"k8s.io/cli-runtime/pkg/resource"
	"k8s.io/client-go/kubernetes/scheme"
	cachetools "k8s.io/client-go/tools/cache"
	watchtools "k8s.io/client-go/tools/watch"
	cmdutil "k8s.io/kubectl/pkg/cmd/util"
	"k8s.io/kubernetes/pkg/printers"
	"k8s.io/kubernetes/pkg/printers/internalversion"
)

...

func (c *Client) Get(resources ResourceList) (string, error) {
	builder := strings.Builder{}
	printer := genericprinters.NewTablePrinter(genericprinters.PrintOptions{})
	generator := printers.NewTablePrinter()
	internalversion.AddHandlers(generator)
	err := resources.Visit(func(info *resource.Info, err error) error {
		if err != nil {
			return err
		}

		obj := AsVersioned(info)
		if err != nil {
			if !apierrors.IsNotFound(err) {
				return errors.Wrap(err, "could not get information about the resource")
			}
			return err
		}
		tbl, err := generator.PrintTable(obj, printers.PrintOptions{})
		if err != nil {
			return err
		}
		if err := printer.PrintObj(tbl, &builder); err != nil {
			return fmt.Errorf("failed to print object %s: %v", info.Name, err)
		}
		if _, err := builder.WriteString("\n"); err != nil {
			return err
		}
		return nil
	})
	return builder.String(), err
}

In order to get this to work, this code would need to rely on packages internal to kubernetes/kubernetes, in particular the TableGenerator as part of k8s.io/kubernetes/pkg/printers: https://github.com/kubernetes/kubernetes/blob/master/pkg/printers/tablegenerator.go

I'm not sure this can reasonably be achieved without reintroducing the entire kubernetes client library code, which we went to great lengths to remove in Helm 3.

For now, helm get manifest | kubectl get -f - works just fine.

Let us know if you find out something different.

@sarvaniy

sarvaniy commented Mar 6, 2020

Copy link
Copy Markdown
Author

@bacongobbler Thanks for update, as you suggest I will try to look into kubectl get implementation in deeper.

… of release in helm status command

Signed-off-by: sarvani mounika <[email protected]>
@sarvaniy

sarvaniy commented Mar 9, 2020 •

Copy link
Copy Markdown
Author

@bacongobbler Hi, I had gone through "kubectl get" implementation in depper. I found that Transformrequests is used to get the status of resources instead of rely on packages internal to kubernetes/kubernetes.

I had modified the code and tested, it worked fine.

example:
helm status prometheus -n monitoring

NAME: prometheus
LAST DEPLOYED: Wed Dec 11 15:59:46 2019
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
RESOURCES:
==> v1/ServiceAccount
NAME SECRETS AGE
prometheus-alertmanager 1 88d
prometheus-kube-state-metrics 1 88d
prometheus-node-exporter 1 88d
prometheus-pushgateway 1 88d
prometheus-server 1 88d

==> v1beta1/ClusterRole
NAME AGE
prometheus-alertmanager 88d
prometheus-kube-state-metrics 88d
prometheus-pushgateway 88d
prometheus-server 88d

==> v1beta1/ClusterRoleBinding
prometheus-alertmanager 88d
prometheus-kube-state-metrics 88d
prometheus-pushgateway 88d
prometheus-server 88d

==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
prometheus-alertmanager ClusterIP 10.109.247.218 80/TCP 88d
prometheus-kube-state-metrics ClusterIP None 80/TCP 88d
prometheus-node-exporter ClusterIP None 9100/TCP 88d
prometheus-pushgateway ClusterIP 10.101.68.104 9091/TCP 88d
prometheus-server ClusterIP 10.99.38.220 80/TCP 88d

==> v1/DaemonSet
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
prometheus-node-exporter 8 8 8 8 8 88d

==> v1/Deployment
NAME READY UP-TO-DATE AVAILABLE AGE
prometheus-alertmanager 1/1 1 1 88d
prometheus-kube-state-metrics 1/1 1 1 88d
prometheus-pushgateway 1/1 1 1 88d
prometheus-server 1/1 1 1 88d

==> v1/ConfigMap
NAME DATA AGE
prometheus-alertmanager 1 88d
prometheus-server 5 88d

==> v1/PersistentVolumeClaim
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
prometheus-alertmanager Bound pvc-29b9c900-1c59-11ea-8152-0cc47af2ef34 2Gi RWO basic 88d
prometheus-server Bound pvc-29b9c4c1-1c59-11ea-8152-0cc47af2ef34 8Gi RWO basic 88d

TEST SUITE: None
NOTES:
The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster:
prometheus-server.monitoring.svc.cluster.local

Get the Prometheus server URL by running these commands in the same shell:
export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace monitoring port-forward $POD_NAME 9090

The Prometheus alertmanager can be accessed via port 80 on the following DNS name from within your cluster:
prometheus-alertmanager.monitoring.svc.cluster.local

Get the Alertmanager URL by running these commands in the same shell:
export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus,component=alertmanager" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace monitoring port-forward $POD_NAME 9093
#################################################################################

WARNING: Pod Security Policy has been moved to a global property.
use .Values.podSecurityPolicy.enabled with pod-based
annotations
(e.g. .Values.nodeExporter.podSecurityPolicy.annotations)

#################################################################################

The Prometheus PushGateway can be accessed via port 9091 on the following DNS name from within your cluster:
prometheus-pushgateway.monitoring.svc.cluster.local

Get the PushGateway URL by running these commands in the same shell:
export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus,component=pushgateway" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace monitoring port-forward $POD_NAME 9091

For more information on running Prometheus, visit:
https://prometheus.io/

And I had Commited the same tested code.

@mattfarina mattfarina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like that this is being worked on. I know of tools that use this and parse the information.

But, to make it better with JSON/YAML output I think there can be a better option... see below...

Comment thread pkg/kube/client.go Outdated
req.Param("includeObject", "Object")
}

func (c *Client) Get(resources ResourceList) (string, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is used with the normal display this would be fine. But, if JSON or YAML is the output the complex string is going to end up inside a key and not be easily parsed.

I would suggest getting the output should be different per type and a print time operation depending on the output format. This would be more useful for getting this information in a machine format.

@sarvaniy sarvaniy Mar 11, 2020 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Matt,

Commited code is worked fine for different output formats like yaml and json as well.
I think that in helm2 also the output is same, for "helm status" command with different output formats like yaml, json.

Below is the genearted output without format and with different format cases in helm3

Without output format case

helm status firsthelm-0-1579514513

NAME: firsthelm-0-1579514513
LAST DEPLOYED: Mon Jan 20 05:01:57 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
RESOURCES:
==> v1/Service
NAME                     TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
firsthelm-0-1579514513   ClusterIP   10.96.41.237   <none>        80/TCP    50d

==> v1/Deployment
NAME                     READY   UP-TO-DATE   AVAILABLE   AGE
firsthelm-0-1579514513   1/1     1            1           50d


NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=firsthelm,app.kubernetes.io/instance=firsthelm-0-1579514513" -o jsonpath="{.items[0].metadata.name}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl port-forward $POD_NAME 8080:80

With yaml as output format

helm status firsthelm-0-1579514513 -o yaml

Resources: |2+

  ==> v1/Service
  NAME                     TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
  firsthelm-0-1579514513   ClusterIP   10.96.41.237   <none>        80/TCP    50d

  ==> v1/Deployment
  NAME                     READY   UP-TO-DATE   AVAILABLE   AGE
  firsthelm-0-1579514513   1/1     1            1           50d

hooks:
- events:
  - test
  kind: Pod
  last_run:
    completed_at: ""
    phase: ""
    started_at: ""
  manifest: |-
    apiVersion: v1
    kind: Pod
    metadata:
      name: "firsthelm-0-1579514513-test-connection"
      labels:
        app.kubernetes.io/name: firsthelm
        helm.sh/chart: firsthelm-0.1.0
        app.kubernetes.io/instance: firsthelm-0-1579514513
        app.kubernetes.io/version: "1.0"
        app.kubernetes.io/managed-by: Helm
      annotations:
        "helm.sh/hook": test-success
    spec:
      containers:
        - name: wget
          image: busybox
          command: ['wget']
          args:  ['firsthelm-0-1579514513:80']
      restartPolicy: Never
  name: firsthelm-0-1579514513-test-connection
  path: firsthelm/templates/tests/test-connection.yaml
info:
  deleted: ""
  description: Install complete
  first_deployed: "2020-01-20T05:01:57.370835613-05:00"
  last_deployed: "2020-01-20T05:01:57.370835613-05:00"
  notes: |
    1. Get the application URL by running these commands:
      export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=firsthelm,app.kubernetes.io/instance=firsthelm-0-1579514513" -o jsonpath="{.items[0].metadata.name}")
      echo "Visit http://127.0.0.1:8080 to use your application"
      kubectl port-forward $POD_NAME 8080:80
  status: deployed
manifest: |
  ---
  # Source: firsthelm/templates/service.yaml
  apiVersion: v1
  kind: Service
  metadata:
    name: firsthelm-0-1579514513
    labels:
      app.kubernetes.io/name: firsthelm
      helm.sh/chart: firsthelm-0.1.0
      app.kubernetes.io/instance: firsthelm-0-1579514513
      app.kubernetes.io/version: "1.0"
      app.kubernetes.io/managed-by: Helm
  spec:
    type: ClusterIP
    ports:
      - port: 80
        targetPort: http
        protocol: TCP
        name: http
    selector:
      app.kubernetes.io/name: firsthelm
      app.kubernetes.io/instance: firsthelm-0-1579514513
  ---
  # Source: firsthelm/templates/deployment.yaml
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: firsthelm-0-1579514513
    labels:
      app.kubernetes.io/name: firsthelm
      helm.sh/chart: firsthelm-0.1.0
      app.kubernetes.io/instance: firsthelm-0-1579514513
      app.kubernetes.io/version: "1.0"
      app.kubernetes.io/managed-by: Helm
  spec:
    replicas: 1
    selector:
      matchLabels:
        app.kubernetes.io/name: firsthelm
        app.kubernetes.io/instance: firsthelm-0-1579514513
    template:
      metadata:
        labels:
          app.kubernetes.io/name: firsthelm
          app.kubernetes.io/instance: firsthelm-0-1579514513
      spec:
        containers:
          - name: firsthelm
            image: "nginx:stable"
            imagePullPolicy: IfNotPresent
            ports:
              - name: http
                containerPort: 80
                protocol: TCP
            livenessProbe:
              httpGet:
                path: /
                port: http
            readinessProbe:
              httpGet:
                path: /
                port: http
            resources:
              {}
name: firsthelm-0-1579514513
namespace: default
version: 1

With json as output format

helm status firsthelm-0-1579514513 -o json

{"name":"firsthelm-0-1579514513","info":{"first_deployed":"2020-01-20T05:01:57.370835613-05:00","last_deployed":"2020-01-20T05:01:57.370835613-05:00","deleted":"","description":"Install complete","status":"deployed","notes":"1. Get the application URL by running these commands:\n  export POD_NAME=$(kubectl get pods --namespace default -l \"app.kubernetes.io/name=firsthelm,app.kubernetes.io/instance=firsthelm-0-1579514513\" -o jsonpath=\"{.items[0].metadata.name}\")\n  echo \"Visit http://127.0.0.1:8080 to use your application\"\n  kubectl port-forward $POD_NAME 8080:80\n"},"manifest":"---\n# Source: firsthelm/templates/service.yaml\napiVersion: v1\nkind: Service\nmetadata:\n  name: firsthelm-0-1579514513\n  labels:\n    app.kubernetes.io/name: firsthelm\n    helm.sh/chart: firsthelm-0.1.0\n    app.kubernetes.io/instance: firsthelm-0-1579514513\n    app.kubernetes.io/version: \"1.0\"\n    app.kubernetes.io/managed-by: Helm\nspec:\n  type: ClusterIP\n  ports:\n    - port: 80\n      targetPort: http\n      protocol: TCP\n      name: http\n  selector:\n    app.kubernetes.io/name: firsthelm\n    app.kubernetes.io/instance: firsthelm-0-1579514513\n---\n# Source: firsthelm/templates/deployment.yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: firsthelm-0-1579514513\n  labels:\n    app.kubernetes.io/name: firsthelm\n    helm.sh/chart: firsthelm-0.1.0\n    app.kubernetes.io/instance: firsthelm-0-1579514513\n    app.kubernetes.io/version: \"1.0\"\n    app.kubernetes.io/managed-by: Helm\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app.kubernetes.io/name: firsthelm\n      app.kubernetes.io/instance: firsthelm-0-1579514513\n  template:\n    metadata:\n      labels:\n        app.kubernetes.io/name: firsthelm\n        app.kubernetes.io/instance: firsthelm-0-1579514513\n    spec:\n      containers:\n        - name: firsthelm\n          image: \"nginx:stable\"\n          imagePullPolicy: IfNotPresent\n          ports:\n            - name: http\n              containerPort: 80\n              protocol: TCP\n          livenessProbe:\n            httpGet:\n              path: /\n              port: http\n          readinessProbe:\n            httpGet:\n              path: /\n              port: http\n          resources:\n            {}\n","hooks":[{"name":"firsthelm-0-1579514513-test-connection","kind":"Pod","path":"firsthelm/templates/tests/test-connection.yaml","manifest":"apiVersion: v1\nkind: Pod\nmetadata:\n  name: \"firsthelm-0-1579514513-test-connection\"\n  labels:\n    app.kubernetes.io/name: firsthelm\n    helm.sh/chart: firsthelm-0.1.0\n    app.kubernetes.io/instance: firsthelm-0-1579514513\n    app.kubernetes.io/version: \"1.0\"\n    app.kubernetes.io/managed-by: Helm\n  annotations:\n    \"helm.sh/hook\": test-success\nspec:\n  containers:\n    - name: wget\n      image: busybox\n      command: ['wget']\n      args:  ['firsthelm-0-1579514513:80']\n  restartPolicy: Never","events":["test"],"last_run":{"started_at":"","completed_at":"","phase":""}}],"version":1,"namespace":"default","Resources":"\n==\u003e v1/Service\nNAME                     TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE\nfirsthelm-0-1579514513   ClusterIP   10.96.41.237   \u003cnone\u003e        80/TCP    50d\n\n==\u003e v1/Deployment\nNAME                     READY   UP-TO-DATE   AVAILABLE   AGE\nfirsthelm-0-1579514513   1/1     1            1           50d\n\n"}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The release part of this is a string of the output. Instead, we should have that as structured metadata. It doesn't need to be the same as the output of kubectl get po --output json. I would expect the structure to be a JSON object that represents the table as JSON.

Right now (in Helm v2) machines need to use a regex to parse the content of the status information. That includes getting information about things like pods. If this was represented as JSON/YAML when the output was JSON or YAML it would make machines using this easier.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sarvaniy this seems to require fixing, are you able to do that?

@sarvaniy

Copy link
Copy Markdown
Author

@bacongobbler , @mattfarina

Hi All,

Could you please review the code and comments. Thanks in advance

@sarvaniy

Copy link
Copy Markdown
Author

@bacongobbler , @mattfarina

Hi All,

    Could you please review the code and comments. Thanks in advance

@mattfarina mattfarina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the continued work on this. I just worked out how to do this with Helm v2 (see PR link in comments). Helm v2 has a simpler situation as the JSON/YAML output we expect to be different. I commented on the previous thread about that as well.

Comment thread pkg/kube/client.go Outdated
group := metav1beta1.GroupName
version := metav1beta1.SchemeGroupVersion.Version

tableParam := fmt.Sprintf("application/json;as=Table;v=%s;g=%s, application/json", version, group)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also accept the v1 as well as the v1beta1. You can see the work I did for Helm v2 on this at #7785.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Matt,

Thanks for the explanation. As you suggest, i made changes inorder to support both metav1 and metav1beta1 cases. I had gone through the above PR link and used the structured metadata for JSON/YAML. Everything is working fine.

Below are the code-snippet changes.

func transformRequests(req *rest.Request) {
        tableParam := strings.Join([]string{
                fmt.Sprintf("application/json;as=Table;v=%s;g=%s", metav1.SchemeGroupVersion.Version, metav1.GroupName),
                fmt.Sprintf("application/json;as=Table;v=%s;g=%s", metav1beta1.SchemeGroupVersion.Version, metav1beta1.GroupName),
                "application/json",
        }, ",")
        req.SetHeader("Accept", tableParam)

        // if sorting, ensure we receive the full object in order to introspect its fields via jsonpath
        req.Param("includeObject", "Object")
}

func sortTableSlice(objs []runtime.Object) []runtime.Object {
        if len(objs) < 2 {
                return objs
        }

        ntbl := &metav1.Table{}
        // Sort the list of objects
        var newObjs []runtime.Object
        namesCache := make(map[string]runtime.Object, len(objs))
        var names []string
        for _, obj := range objs {
                unstr, ok := obj.(*unstructured.Unstructured)
                if !ok {
                        return objs
                }
                if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstr.Object, ntbl); err != nil {
                        return objs
                }
                namesCache[ntbl.GetSelfLink()] = obj
                names = append(names, ntbl.GetSelfLink())
        }
        sort.Strings(names)
        for _, name := range names {
                newObjs = append(newObjs, namesCache[name])
        }
        return newObjs
}


func (c *Client) Get(resources ResourceList) (string, error) {
        buf := new(bytes.Buffer)
        printFlags := get.NewHumanPrintFlags()
        typePrinter, _ := printFlags.ToPrinter("")
        printer := &get.TablePrinter{Delegate: typePrinter}
        objs := make(map[string][]runtime.Object)
        err := resources.Visit(func(info *resource.Info, err error) error {
                if err != nil {
                        return err
                }
                gvk := info.ResourceMapping().GroupVersionKind
                vk := gvk.Version + "/" + gvk.Kind
                obj, err := getResource(info)
                if err != nil {
                        return err
                }
                objs[vk] = append(objs[vk], obj)
                return nil
        })
        if err != nil {
                return "", err
        }
        var sortingkeys []string
        for key := range objs {
                sortingkeys = append(sortingkeys, key)
        }
        // Sort alphabetically by version/kind keys
        sort.Strings(sortingkeys)
        for _, t := range sortingkeys {
                if _, err = fmt.Fprintf(buf, "==> %s\n", t); err != nil {
                        return "", err
                }
                vk := objs[t]
                vk = sortTableSlice(vk)
                for _, resource := range vk {
                        if err := printer.PrintObj(resource, buf); err != nil {
                                c.Log("failed to print object type %s: %v", t, err)
                                return "", err
                        }
                }
                if _, err := buf.WriteString("\n"); err != nil {
                        return "", err
                }
        }
        return buf.String(), nil
}

func getResource(info *resource.Info) (runtime.Object, error) {
        obj, err := resource.NewHelper(info.Client, info.Mapping).Get(info.Namespace, info.Name, false)
        if err != nil {
                return nil, err
        }
        return obj, nil
}

Could you please look into it and let me know is this okay or not. If yes, then i will commit the code changes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part looks ok. Once I have the PR to review in a full code editor I can do a better review. I look forward to seeing your changes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Matt,

I had commited the changes. Could you please review the code.

mattfarina added a commit to mattfarina/helm that referenced this pull request Mar 25, 2020
Latest() should not have been added Validate

Closes helm#7728

Signed-off-by: Matt Farina <[email protected]>
@sarvaniy

Copy link
Copy Markdown
Author

Hi Matt,
Could you please look into the PR comments, based on that I will commit my code. Thanks in advance

@sarvaniy

sarvaniy commented Mar 27, 2020 via email

Copy link
Copy Markdown
Author

@sarvaniy

sarvaniy commented Mar 27, 2020 via email

Copy link
Copy Markdown
Author

accept both v1 and v1beta

Signed-off-by: sarvani mounika <[email protected]>
@helm-bot helm-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 28, 2020
@sarvaniy

Copy link
Copy Markdown
Author

Hi Matt,

I had commited the changes. Could you please review the code.

Thanks.

@sarvaniy

sarvaniy commented Apr 2, 2020

Copy link
Copy Markdown
Author

Hi Matt,

I had commited the changes. Could you please review the code.

Thanks.

@svolence

Copy link
Copy Markdown

Hi Matt,

I had commited the changes. Could you please review the code.

Thanks.

merged now ?

@sarvaniy

Copy link
Copy Markdown
Author

Hi svolence,

Just now , i had resolved the merge conflicts, you can merge it. Thanks for the response.

Signed-off-by: yakkala sarvani mounika <[email protected]>
@Jinkxed

Jinkxed commented Mar 30, 2021

Copy link
Copy Markdown

Hopefully this PR doesn't die. This is something I and others would still love to have. Very much missed from helm2.

@koulq

koulq commented Apr 28, 2021

Copy link
Copy Markdown

@sarvaniy hi,pod display repeats if statefulset resources are available.
image

@dbsanfte

Copy link
Copy Markdown

This feature in Helm 2 enables a lot of cool workflows like ensuring that all Helm-installed chart objects are still present in the cluster. This has saved us a few times after devs accidentally deleted a deployment :D

Helm 3 really, really needs this.

@bacongobbler

Copy link
Copy Markdown
Member

Throwing this onto the 3.6.0 milestone for (re-)review.

@technosophos

Copy link
Copy Markdown
Member

This adds a method to an Interface, which is defined as a breaking change by the Go authors. To refactor that, we'd have to add another interface that just has the Get method on it. See the Go documentation:

https://blog.golang.org/module-compatibility#TOC_3.

@mattfarina

Copy link
Copy Markdown
Collaborator

Unfortunately, this can't be merged. The go.sum file is out of date. It used to lead to dirty builds that are not caught by CI. As of Go 1.16 is leads to failures. If we merge this the tip of main will fail tests. go mod tidy will fix this. Moving to the next patch release.

@mattfarina mattfarina modified the milestones: 3.6.0, 3.6.1 May 17, 2021
@koulq

koulq commented Jun 11, 2021

Copy link
Copy Markdown

This function will affect helm rollback. Executing helm rollback will delete the resource and cannot be recovered

image

@bacongobbler

Copy link
Copy Markdown
Member

@koulq can you look through this PR and identify what might be causing that issue? How does it affect helm rollback?

@mattfarina mattfarina modified the milestones: 3.6.3, 3.6.4 Jul 14, 2021
@Jinkxed

Jinkxed commented Aug 4, 2021

Copy link
Copy Markdown

@koulq any help here on identifying this or what's causing it? We would love to see this get over the finish line.

@bridgetkromhout bridgetkromhout modified the milestones: 3.6.4, 3.7.0 Aug 16, 2021
@bacongobbler

bacongobbler commented Aug 17, 2021 •

Copy link
Copy Markdown
Member

Unfortunately, it looks like this PR has become stale since the last time we provided feedback. As a result we won't be able to merge it into Helm 3.7 in its current state. Several others have found bugs with the implementation that need further inspection.

So, if someone wants to take over the work here and re-submit a new pull request with the changes suggested earlier, there is a slim chance we could bring this into Helm 3.7.

Removing from Helm 3.7's milestone for now.

@bacongobbler bacongobbler removed this from the 3.7.0 milestone Aug 17, 2021
@bridgetkromhout bridgetkromhout added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Feb 10, 2022
SoujanyaMangipudi added a commit to SoujanyaMangipudi/helm that referenced this pull request Apr 28, 2022
…oyed as part of release in helm status command

Creating a new PR based on this existing stale PR helm#7728

Signed-off-by: SoujanyaMangipudi <[email protected]>
SoujanyaMangipudi added a commit to SoujanyaMangipudi/helm that referenced this pull request Apr 28, 2022
…oyed as part of release in helm status command

Creating a new PR based on this existing stale PR helm#7728

Signed-off-by: SoujanyaMangipudi <[email protected]>
Signed-off-by: Soujanya Mangipudi <[email protected]>
SoujanyaMangipudi added a commit to SoujanyaMangipudi/helm that referenced this pull request Apr 29, 2022
…oyed as part of release in helm status command

Creating a new PR based on this existing stale PR helm#7728

Signed-off-by: SoujanyaMangipudi <[email protected]>
Signed-off-by: Soujanya Mangipudi <[email protected]>
SoujanyaMangipudi added a commit to SoujanyaMangipudi/helm that referenced this pull request Apr 29, 2022
…oyed as part of release in helm status command

Creating a new PR based on this existing stale PR helm#7728

Signed-off-by: Soujanya Mangipudi <[email protected]>
SoujanyaMangipudi added a commit to SoujanyaMangipudi/helm that referenced this pull request Sep 9, 2022
…oyed as part of release in helm status command

Creating a new PR based on this existing stale PR helm#7728

Signed-off-by: Soujanya Mangipudi <[email protected]>

# Conflicts:
#	go.sum
SoujanyaMangipudi added a commit to SoujanyaMangipudi/helm that referenced this pull request Sep 9, 2022
…oyed as part of release in helm status command

Creating a new PR based on this existing stale PR helm#7728

Signed-off-by: Soujanya Mangipudi <[email protected]>

# Conflicts:
#	go.sum
@mattfarina

Copy link
Copy Markdown
Collaborator

Closing as an alternative PR for this has been merged.

@mattfarina mattfarina closed this Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.