From a90182e3b2dba2172a7ee0a2680de0c7b09ec4ed Mon Sep 17 00:00:00 2001 From: Martin Hickey Date: Mon, 25 May 2020 17:12:39 +0000 Subject: [PATCH 1/2] Add more informative error message for removed k8s APIs Signed-off-by: Martin Hickey --- pkg/kube/client.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 20edb3ba0..988b30be3 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -484,13 +484,30 @@ type UpdateOptions struct { func (c *Client) UpdateWithOptions(namespace string, originalReader, targetReader io.Reader, opts UpdateOptions) error { original, err := c.BuildUnstructured(namespace, originalReader) if err != nil { - return fmt.Errorf("failed decoding reader into objects: %s", err) + // Checking for removed Kubernetes API error so can provide a more informative error message to the user + // Ref: https://github.com/helm/helm/issues/7219 + if strings.Contains(err.Error(), "unable to recognize \"\": no matches for kind") { + return fmt.Errorf("current release manifest contains removed kubernetes api(s) for this "+ + "kubernetes version and it is therefore unable to build the kubernetes "+ + "objects for performing the diff. error from kubernetes: %s", err) + } else { + return fmt.Errorf("failed decoding reader into objects: %s", err) + } } c.Log("building resources from updated manifest") target, err := c.BuildUnstructured(namespace, targetReader) if err != nil { - return fmt.Errorf("failed decoding reader into objects: %s", err) + // Checking for removed Kubernetes API error so can provide a more informative error message to the user + // Ref: https://github.com/helm/helm/issues/7219 + if strings.Contains(err.Error(), "unable to recognize \"\": no matches for kind") { + return fmt.Errorf("new release manifest contains removed kubernetes api(s) for this "+ + "kubernetes version and it is therefore unable to build the kubernetes "+ + "objects for deployment. error from kubernetes: %s", err) + + } else { + return fmt.Errorf("failed decoding reader into objects: %s", err) + } } newlyCreatedResources := []*resource.Info{} From 059aeed8c73b3c026f6b1ff9125304afb23b92bb Mon Sep 17 00:00:00 2001 From: Martin Hickey Date: Wed, 17 Jun 2020 17:20:52 +0000 Subject: [PATCH 2/2] Update after review Review comment: - https://github.com/helm/helm/pull/8198/files#r435237511 Signed-off-by: Martin Hickey --- pkg/kube/client.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 988b30be3..ee48a0a31 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -68,6 +68,8 @@ import ( // MissingGetHeader is added to Get's output when a resource is not found. const MissingGetHeader = "==> MISSING\nKIND\t\tNAME\n" +const KubsAPIErrorMsg = "unable to recognize \"\": no matches for kind" + // ErrNoObjectsVisited indicates that during a visit operation, no matching objects were found. var ErrNoObjectsVisited = goerrors.New("no objects visited") @@ -486,7 +488,7 @@ func (c *Client) UpdateWithOptions(namespace string, originalReader, targetReade if err != nil { // Checking for removed Kubernetes API error so can provide a more informative error message to the user // Ref: https://github.com/helm/helm/issues/7219 - if strings.Contains(err.Error(), "unable to recognize \"\": no matches for kind") { + if strings.Contains(err.Error(), KubsAPIErrorMsg) { return fmt.Errorf("current release manifest contains removed kubernetes api(s) for this "+ "kubernetes version and it is therefore unable to build the kubernetes "+ "objects for performing the diff. error from kubernetes: %s", err) @@ -500,7 +502,7 @@ func (c *Client) UpdateWithOptions(namespace string, originalReader, targetReade if err != nil { // Checking for removed Kubernetes API error so can provide a more informative error message to the user // Ref: https://github.com/helm/helm/issues/7219 - if strings.Contains(err.Error(), "unable to recognize \"\": no matches for kind") { + if strings.Contains(err.Error(), KubsAPIErrorMsg) { return fmt.Errorf("new release manifest contains removed kubernetes api(s) for this "+ "kubernetes version and it is therefore unable to build the kubernetes "+ "objects for deployment. error from kubernetes: %s", err)