Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better error handling when working with kube and kudo. #1097

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions pkg/kudoctl/util/kudo/kudo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kudo
import (
"encoding/json"
"fmt"
"os"
"strings"
"time"

Expand All @@ -12,7 +13,6 @@ import (
"github.com/kudobuilder/kudo/pkg/util/kudo"
"github.com/kudobuilder/kudo/pkg/version"

"github.com/pkg/errors"
v1core "k8s.io/api/core/v1"
extensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -56,17 +56,30 @@ func NewClient(kubeConfigPath string, requestTimeout int64) (*Client, error) {

_, err = extensionsClientset.CustomResourceDefinitions().Get("operators.kudo.dev", v1.GetOptions{})
if err != nil {
return nil, errors.WithMessage(err, "operators")
// timeout is not a wrappable error, timeout is an underlying issue that is NOT CRD specific, there is no value in wrapping or converting as well.
// best to provide the actual error for proper reporting.
if os.IsTimeout(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that we don't wrap the timeout error but to what end? Where do you do anything with it?

Copy link
Member Author

Choose a reason for hiding this comment

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

The intention is to do something with it :). I was wrongly of the opinion that this was such a simple and not debatable change that I could land this quickly and move on to using it.

return nil, err
}
return nil, fmt.Errorf("operators crd: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're at it: I'm not sure what "operators crd: adds to the error message. Maybe smth. like:

Suggested change
return nil, fmt.Errorf("operators crd: %w", err)
return nil, fmt.Errorf("failed to fetch operators.kudo.dev CRD: %w", err)

?

Copy link
Member Author

Choose a reason for hiding this comment

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

this request for change is not consistent with the actual change. The message that you are wanting to change was original there. Lets focus on the change.

}

_, err = extensionsClientset.CustomResourceDefinitions().Get("operatorversions.kudo.dev", v1.GetOptions{})
if err != nil {
return nil, errors.WithMessage(err, "operatorversions")
// timeout details above for first CRD
if os.IsTimeout(err) {
return nil, err
}
return nil, fmt.Errorf("operatorversions crd: %w", err)
}

_, err = extensionsClientset.CustomResourceDefinitions().Get("instances.kudo.dev", v1.GetOptions{})
if err != nil {
return nil, errors.WithMessage(err, "instances")
// timeout details above for first CRD
if os.IsTimeout(err) {
return nil, err
}
return nil, fmt.Errorf("instances crd: %w", err)
}

return &Client{
Expand Down Expand Up @@ -208,7 +221,11 @@ func (c *Client) OperatorVersionsInstalled(operatorName, namespace string) ([]st
func (c *Client) InstallOperatorObjToCluster(obj *v1beta1.Operator, namespace string) (*v1beta1.Operator, error) {
createdObj, err := c.clientset.KudoV1beta1().Operators(namespace).Create(obj)
if err != nil {
return nil, errors.WithMessage(err, "installing Operator")
// we do NOT wrap timeouts
if os.IsTimeout(err) {
return nil, err
}
return nil, fmt.Errorf("installing Operator: %w", err)
}
return createdObj, nil
}
Expand All @@ -217,7 +234,11 @@ func (c *Client) InstallOperatorObjToCluster(obj *v1beta1.Operator, namespace st
func (c *Client) InstallOperatorVersionObjToCluster(obj *v1beta1.OperatorVersion, namespace string) (*v1beta1.OperatorVersion, error) {
createdObj, err := c.clientset.KudoV1beta1().OperatorVersions(namespace).Create(obj)
if err != nil {
return nil, errors.WithMessage(err, "installing OperatorVersion")
// we do NOT wrap timeouts
if os.IsTimeout(err) {
return nil, err
}
return nil, fmt.Errorf("installing OperatorVersion: %w", err)
}
return createdObj, nil
}
Expand All @@ -226,7 +247,11 @@ func (c *Client) InstallOperatorVersionObjToCluster(obj *v1beta1.OperatorVersion
func (c *Client) InstallInstanceObjToCluster(obj *v1beta1.Instance, namespace string) (*v1beta1.Instance, error) {
createdObj, err := c.clientset.KudoV1beta1().Instances(namespace).Create(obj)
if err != nil {
return nil, errors.WithMessage(err, "installing Instance")
// we do NOT wrap timeouts
if os.IsTimeout(err) {
return nil, err
}
return nil, fmt.Errorf("installing Instance: %w", err)
}
clog.V(2).Printf("instance %v created in namespace %v", createdObj.Name, namespace)
return createdObj, nil
Expand Down