Skip to content

Commit

Permalink
refactor: remove remaining use of IsKeyNotFoundError
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Mar 23, 2020
1 parent b37eabb commit 006f7e0
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions pkg/hal/cli/component/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/sha1"
"fmt"
"github.com/mholt/archiver"
"github.com/pkg/errors"
"github.com/spf13/cobra"
component "halkyon.io/api/component/v1beta1"
"halkyon.io/api/v1beta1"
Expand All @@ -14,9 +13,8 @@ import (
"halkyon.io/hal/pkg/log"
"io"
"io/ioutil"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record/util"
ktemplates "k8s.io/kubectl/pkg/util/templates"
"os"
"path/filepath"
Expand Down Expand Up @@ -52,13 +50,11 @@ func (o *pushOptions) Validate() (err error) {

func (o *pushOptions) Run() error {
// first check that the component exists:
c := k8s.GetClient()
name := o.GetTargetedComponentName()
components := c.HalkyonComponentClient.Components(c.Namespace)
comp, err := components.Get(name, v1.GetOptions{})
comp, err := Entity.GetTyped(name)
if err != nil {
// check error to see if it means that the component doesn't exist yet
if util.IsKeyNotFoundError(errors.Cause(err)) {
if errors.IsNotFound(err) {
return fmt.Errorf("no component named '%s' exists, please create it first", name)
} else {
return err
Expand Down Expand Up @@ -130,7 +126,7 @@ func (o *pushOptions) Run() error {

// update the component revision
patch := fmt.Sprintf(`{"spec":{"revision":"%s"}}`, revision)
_, err = components.Patch(name, types.MergePatchType, []byte(patch))
_, err = Entity.client.Patch(name, types.MergePatchType, []byte(patch))
if err != nil {
return err
}
Expand Down Expand Up @@ -240,7 +236,7 @@ func (o *pushOptions) waitUntilReady(c *component.Component) (*component.Compone
func errorIfFailedOrUnknown(c *component.Component) error {
switch c.Status.Reason {
case v1beta1.ReasonFailed:
return errors.Errorf("status of component %s is %s: %s", c.Name, c.Status.Reason, c.Status.Message)
return fmt.Errorf("status of component %s is %s: %s", c.Name, c.Status.Reason, c.Status.Message)
default:
return nil
}
Expand Down

0 comments on commit 006f7e0

Please sign in to comment.