Skip to content

Commit

Permalink
better error handling when working with kube and kudo. (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
kensipe authored Nov 26, 2019
1 parent 2b075cf commit 912bfd4
Showing 1 changed file with 32 additions and 7 deletions.
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) {
return nil, err
}
return nil, fmt.Errorf("operators crd: %w", err)
}

_, 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

0 comments on commit 912bfd4

Please sign in to comment.