-
Notifications
You must be signed in to change notification settings - Fork 102
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ package kudo | |||||
import ( | ||||||
"encoding/json" | ||||||
"fmt" | ||||||
"os" | ||||||
"strings" | ||||||
"time" | ||||||
|
||||||
|
@@ -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" | ||||||
|
@@ -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) { | ||||||
return nil, err | ||||||
} | ||||||
return nil, fmt.Errorf("operators crd: %w", err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're at it: I'm not sure what
Suggested change
? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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{ | ||||||
|
@@ -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 | ||||||
} | ||||||
|
@@ -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 | ||||||
} | ||||||
|
@@ -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 | ||||||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.