Merge pull request #4623 from adamreese/dev-v3-driver-errors

ref(driver): refactor out function type errors
pull/4714/head
Adam Reese 6 years ago committed by GitHub
commit d6ba48d07e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,7 +19,6 @@ package main
import (
"fmt"
"io"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -125,9 +124,7 @@ func (o *upgradeOptions) run(out io.Writer) error {
if o.install {
// If a release does not exist, install it. If another error occurs during
// the check, ignore the error and continue with the upgrade.
_, err := o.client.ReleaseHistory(o.release, 1)
if err != nil && strings.Contains(err.Error(), driver.ErrReleaseNotFound(o.release).Error()) {
if _, err := o.client.ReleaseHistory(o.release, 1); err == driver.ErrReleaseNotFound {
fmt.Fprintf(out, "Release %q does not exist. Installing it now.\n", o.release)
io := &installOptions{
chartPath: chartPath,

@ -66,7 +66,7 @@ func (cfgmaps *ConfigMaps) Get(key string) (*rspb.Release, error) {
obj, err := cfgmaps.impl.Get(key, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
return nil, ErrReleaseNotFound(key)
return nil, ErrReleaseNotFound
}
cfgmaps.Log("get: failed to get %q: %s", key, err)
@ -132,7 +132,7 @@ func (cfgmaps *ConfigMaps) Query(labels map[string]string) ([]*rspb.Release, err
}
if len(list.Items) == 0 {
return nil, ErrReleaseNotFound(labels["name"])
return nil, ErrReleaseNotFound
}
var results []*rspb.Release
@ -165,7 +165,7 @@ func (cfgmaps *ConfigMaps) Create(key string, rls *rspb.Release) error {
// push the configmap object out into the kubiverse
if _, err := cfgmaps.impl.Create(obj); err != nil {
if apierrors.IsAlreadyExists(err) {
return ErrReleaseExists(key)
return ErrReleaseExists
}
cfgmaps.Log("create: failed to create: %s", err)
@ -203,7 +203,7 @@ func (cfgmaps *ConfigMaps) Delete(key string) (rls *rspb.Release, err error) {
// fetch the release to check existence
if rls, err = cfgmaps.Get(key); err != nil {
if apierrors.IsNotFound(err) {
return nil, ErrReleaseExists(rls.Name)
return nil, ErrReleaseExists
}
cfgmaps.Log("delete: failed to get release %q: %s", key, err)

@ -24,11 +24,11 @@ import (
var (
// ErrReleaseNotFound indicates that a release is not found.
ErrReleaseNotFound = func(release string) error { return errors.Errorf("release: %q not found", release) }
ErrReleaseNotFound = errors.New("release: not found")
// ErrReleaseExists indicates that a release already exists.
ErrReleaseExists = func(release string) error { return errors.Errorf("release: %q already exists", release) }
ErrReleaseExists = errors.New("release: already exists")
// ErrInvalidKey indicates that a release key could not be parsed.
ErrInvalidKey = func(release string) error { return errors.Errorf("release: %q invalid key", release) }
ErrInvalidKey = errors.Errorf("release: invalid key")
)
// Creator is the interface that wraps the Create method.

@ -53,16 +53,16 @@ func (mem *Memory) Get(key string) (*rspb.Release, error) {
case 2:
name, ver := elems[0], elems[1]
if _, err := strconv.Atoi(ver); err != nil {
return nil, ErrInvalidKey(key)
return nil, ErrInvalidKey
}
if recs, ok := mem.cache[name]; ok {
if r := recs.Get(key); r != nil {
return r.rls, nil
}
}
return nil, ErrReleaseNotFound(key)
return nil, ErrReleaseNotFound
default:
return nil, ErrInvalidKey(key)
return nil, ErrInvalidKey
}
}
@ -131,7 +131,7 @@ func (mem *Memory) Update(key string, rls *rspb.Release) error {
rs.Replace(key, newRecord(key, rls))
return nil
}
return ErrReleaseNotFound(rls.Name)
return ErrReleaseNotFound
}
// Delete deletes a release or returns ErrReleaseNotFound.
@ -141,12 +141,12 @@ func (mem *Memory) Delete(key string) (*rspb.Release, error) {
elems := strings.Split(key, ".v")
if len(elems) != 2 {
return nil, ErrInvalidKey(key)
return nil, ErrInvalidKey
}
name, ver := elems[0], elems[1]
if _, err := strconv.Atoi(ver); err != nil {
return nil, ErrInvalidKey(key)
return nil, ErrInvalidKey
}
if recs, ok := mem.cache[name]; ok {
if r := recs.Remove(key); r != nil {
@ -155,7 +155,7 @@ func (mem *Memory) Delete(key string) (*rspb.Release, error) {
return r.rls, nil
}
}
return nil, ErrReleaseNotFound(key)
return nil, ErrReleaseNotFound
}
// wlock locks mem for writing

@ -36,7 +36,7 @@ func (rs *records) Add(r *record) error {
}
if rs.Exists(r.key) {
return ErrReleaseExists(r.key)
return ErrReleaseExists
}
*rs = append(*rs, r)

@ -66,7 +66,7 @@ func (secrets *Secrets) Get(key string) (*rspb.Release, error) {
obj, err := secrets.impl.Get(key, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
return nil, ErrReleaseNotFound(key)
return nil, ErrReleaseNotFound
}
return nil, errors.Wrapf(err, "get: failed to get %q", key)
}
@ -123,7 +123,7 @@ func (secrets *Secrets) Query(labels map[string]string) ([]*rspb.Release, error)
}
if len(list.Items) == 0 {
return nil, ErrReleaseNotFound(labels["name"])
return nil, ErrReleaseNotFound
}
var results []*rspb.Release
@ -155,7 +155,7 @@ func (secrets *Secrets) Create(key string, rls *rspb.Release) error {
// push the secret object out into the kubiverse
if _, err := secrets.impl.Create(obj); err != nil {
if apierrors.IsAlreadyExists(err) {
return ErrReleaseExists(rls.Name)
return ErrReleaseExists
}
return errors.Wrap(err, "create: failed to create")
@ -187,7 +187,7 @@ func (secrets *Secrets) Delete(key string) (rls *rspb.Release, err error) {
// fetch the release to check existence
if rls, err = secrets.Get(key); err != nil {
if apierrors.IsNotFound(err) {
return nil, ErrReleaseExists(rls.Name)
return nil, ErrReleaseExists
}
return nil, errors.Wrapf(err, "delete: failed to get release %q", key)

Loading…
Cancel
Save