Skip to content

Commit

Permalink
Merge babc0e1 into 2c6c9f1
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Mar 18, 2022
2 parents 2c6c9f1 + babc0e1 commit 19d432e
Show file tree
Hide file tree
Showing 74 changed files with 372 additions and 383 deletions.
12 changes: 10 additions & 2 deletions cmd/cli-doc/cli-doc.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"errors"
"fmt"
"os"

"github.com/pkg/errors"
"github.com/redhat-developer/odo/pkg/odo/cli"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -185,7 +185,15 @@ func main() {

err := clidoc.Execute()
if err != nil {
fmt.Println(errors.Cause(err))
for {
e := errors.Unwrap(err)
if e != nil {
err = e
} else {
break
}
}
fmt.Println(err)
os.Exit(1)
}
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ require (
github.com/operator-framework/api v0.3.20
github.com/operator-framework/operator-lifecycle-manager v0.17.0
github.com/pborman/uuid v1.2.0
github.com/pkg/errors v0.9.1
github.com/posener/complete v1.1.1
github.com/redhat-developer/alizer/go v0.0.0-20220215154256-33df7feef4ae
github.com/redhat-developer/service-binding-operator v1.0.1-0.20211222115357-5b7bbba3bfb3
Expand Down
13 changes: 6 additions & 7 deletions pkg/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"sync"

"github.com/pkg/errors"
"github.com/zalando/go-keyring"

dfutil "github.com/devfile/library/pkg/util"
Expand Down Expand Up @@ -127,7 +126,7 @@ func (o *CatalogClient) SearchComponent(client kclient.ClientInterface, name str
//var result []string
//componentList, err := ListDevfileComponents(client)
//if err != nil {
// return nil, errors.Wrap(err, "unable to list components")
// return nil, fmt.Errorf("unable to list components: %w", err)
//}
//
//// do a partial search in all the components
Expand Down Expand Up @@ -189,7 +188,7 @@ func getRegistryDevfiles(preferenceClient preference.Client, registry Registry)
// Github-based registry
URL, err := convertURL(registry.URL)
if err != nil {
return nil, errors.Wrapf(err, "unable to convert URL %s", registry.URL)
return nil, fmt.Errorf("unable to convert URL %s: %w", registry.URL, err)
}
registry.URL = URL
indexLink := registry.URL + indexPath
Expand All @@ -201,14 +200,14 @@ func getRegistryDevfiles(preferenceClient preference.Client, registry Registry)
if secure {
token, e := keyring.Get(fmt.Sprintf("%s%s", dfutil.CredentialPrefix, registry.Name), registryUtil.RegistryUser)
if e != nil {
return nil, errors.Wrap(e, "unable to get secure registry credential from keyring")
return nil, fmt.Errorf("unable to get secure registry credential from keyring: %w", e)
}
request.Token = token
}

jsonBytes, err := dfutil.HTTPGetRequest(request, preferenceClient.GetRegistryCacheTime())
if err != nil {
return nil, errors.Wrapf(err, "unable to download the devfile index.json from %s", indexLink)
return nil, fmt.Errorf("unable to download the devfile index.json from %s: %w", indexLink, err)
}

var devfileIndex []indexSchema.Schema
Expand All @@ -220,12 +219,12 @@ func getRegistryDevfiles(preferenceClient preference.Client, registry Registry)
// we try once again
jsonBytes, err := dfutil.HTTPGetRequest(request, preferenceClient.GetRegistryCacheTime())
if err != nil {
return nil, errors.Wrapf(err, "unable to download the devfile index.json from %s", indexLink)
return nil, fmt.Errorf("unable to download the devfile index.json from %s: %w", indexLink, err)
}

err = json.Unmarshal(jsonBytes, &devfileIndex)
if err != nil {
return nil, errors.Wrapf(err, "unable to unmarshal the devfile index.json from %s", indexLink)
return nil, fmt.Errorf("unable to unmarshal the devfile index.json from %s: %w", indexLink, err)
}
}
return createRegistryDevfiles(registry, devfileIndex)
Expand Down
32 changes: 17 additions & 15 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package component

import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"reflect"
"strings"

"github.com/pkg/errors"

"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/api/v2/pkg/devfile"
"github.com/devfile/library/pkg/devfile/parser"
Expand Down Expand Up @@ -55,7 +54,7 @@ func GetComponentDir(path string) (string, error) {
} else {
currDir, err := os.Getwd()
if err != nil {
return "", errors.Wrapf(err, "unable to generate a random name as getting current directory failed")
return "", fmt.Errorf("unable to generate a random name as getting current directory failed: %w", err)
}
retVal = filepath.Base(currDir)
}
Expand All @@ -79,7 +78,7 @@ func GetDefaultComponentName(cfg preference.Client, componentPath string, compon
// Create a random generated name for the component to use within Kubernetes
prefix, err = GetComponentDir(componentPath)
if err != nil {
return "", errors.Wrap(err, "unable to generate random component name")
return "", fmt.Errorf("unable to generate random component name: %w", err)
}
prefix = util.TruncateString(prefix, componentRandomNamePartsMaxLen)

Expand All @@ -91,7 +90,7 @@ func GetDefaultComponentName(cfg preference.Client, componentPath string, compon
componentNameMaxRetries,
)
if err != nil {
return "", errors.Wrap(err, "unable to generate random component name")
return "", fmt.Errorf("unable to generate random component name: %w", err)
}

return util.GetDNS1123Name(componentName), nil
Expand Down Expand Up @@ -135,14 +134,14 @@ func ListDevfileComponents(client kclient.ClientInterface, selector string) (Com
// retrieve all the deployments that are associated with this application
deploymentList, err := client.GetDeploymentFromSelector(selector)
if err != nil {
return ComponentList{}, errors.Wrapf(err, "unable to list components")
return ComponentList{}, fmt.Errorf("unable to list components: %w", err)
}

// create a list of object metadata based on the component and application name (extracted from Deployment labels)
for _, elem := range deploymentList {
component, err := GetComponent(client, elem.Labels[componentlabels.KubernetesInstanceLabel], elem.Labels[applabels.ApplicationLabel], client.GetCurrentNamespace())
if err != nil {
return ComponentList{}, errors.Wrap(err, "Unable to get component")
return ComponentList{}, fmt.Errorf("Unable to get component: %w", err)
}

if !reflect.ValueOf(component).IsZero() {
Expand Down Expand Up @@ -319,7 +318,7 @@ func ListDevfileComponentsInPath(client kclient.ClientInterface, paths []string)
func Exists(client kclient.ClientInterface, componentName, applicationName string) (bool, error) {
deploymentName, err := dfutil.NamespaceOpenShiftObject(componentName, applicationName)
if err != nil {
return false, errors.Wrapf(err, "unable to create namespaced name")
return false, fmt.Errorf("unable to create namespaced name: %w", err)
}
deployment, _ := client.GetDeploymentByName(deploymentName)
if deployment != nil {
Expand Down Expand Up @@ -348,14 +347,17 @@ func GetComponent(client kclient.ClientInterface, componentName string, applicat
// getRemoteComponentMetadata provides component metadata from the cluster
func getRemoteComponentMetadata(client kclient.ClientInterface, componentName string, applicationName string, getUrls, getStorage bool) (Component, error) {
fromCluster, err := GetPushedComponent(client, componentName, applicationName)
if err != nil || fromCluster == nil {
return Component{}, errors.Wrapf(err, "unable to get remote metadata for %s component", componentName)
if err != nil {
return Component{}, fmt.Errorf("unable to get remote metadata for %s component: %w", componentName, err)
}
if fromCluster == nil {
return Component{}, nil
}

// Component Type
componentType, err := fromCluster.GetType()
if err != nil {
return Component{}, errors.Wrap(err, "unable to get source type")
return Component{}, fmt.Errorf("unable to get source type: %w", err)
}

// init component
Expand All @@ -382,7 +384,7 @@ func getRemoteComponentMetadata(client kclient.ClientInterface, componentName st
if getStorage {
appStore, e := fromCluster.GetStorage()
if e != nil {
return Component{}, errors.Wrap(e, "unable to get storage list")
return Component{}, fmt.Errorf("unable to get storage list: %w", e)
}

component.Spec.StorageSpec = appStore
Expand Down Expand Up @@ -531,11 +533,11 @@ func Log(client kclient.ClientInterface, componentName string, appName string, f

pod, err := GetOnePod(client, componentName, appName)
if err != nil {
return nil, errors.Errorf("the component %s doesn't exist on the cluster", componentName)
return nil, fmt.Errorf("the component %s doesn't exist on the cluster", componentName)
}

if pod.Status.Phase != corev1.PodRunning {
return nil, errors.Errorf("unable to show logs, component is not in running state. current status=%v", pod.Status.Phase)
return nil, fmt.Errorf("unable to show logs, component is not in running state. current status=%v", pod.Status.Phase)
}

containerName := command.Exec.Component
Expand Down Expand Up @@ -564,7 +566,7 @@ func Delete(kubeClient kclient.ClientInterface, devfileObj parser.DevfileObj, co
log.Warningf("%v", e)
return nil
} else if err != nil {
return errors.Wrapf(err, "unable to determine if component %s exists", componentName)
return fmt.Errorf("unable to determine if component %s exists: %w", componentName, err)
}

podSpinner.End(true)
Expand Down
3 changes: 1 addition & 2 deletions pkg/component/exec_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"

"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/pkg/errors"
"github.com/redhat-developer/odo/pkg/kclient"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/machineoutput"
Expand Down Expand Up @@ -114,7 +113,7 @@ func executeCommand(client kclient.ClientInterface, containerName string, podNam
// It is safe to read from cmdOutput here, as the goroutines are guaranteed to have terminated at this point.
klog.V(2).Infof("ExecuteCommand returned an an err: %v. for command '%v'. output: %v", err, command, cmdOutput)

return errors.Wrapf(err, "unable to exec command %v: \n%v", command, cmdOutput)
return fmt.Errorf("unable to exec command %v: \n%v: %w", command, cmdOutput, err)
}

return
Expand Down
13 changes: 9 additions & 4 deletions pkg/component/pushed_component.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package component

import (
"errors"
"fmt"

"github.com/pkg/errors"
componentlabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
"github.com/redhat-developer/odo/pkg/storage"
Expand Down Expand Up @@ -195,10 +195,15 @@ func GetPushedComponent(c kclient.ClientInterface, componentName, applicationNam
}

func isIgnorableError(err error) bool {
e := errors.Cause(err)
if e != nil {
err = e
for {
e := errors.Unwrap(err)
if e != nil {
err = e
} else {
break
}
}

if _, ok := err.(*kclient.DeploymentNotFoundError); ok {
return true
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/component/starter_project.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package component

import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -16,8 +18,6 @@ import (
"github.com/redhat-developer/odo/pkg/log"
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/preference/registry/util"
"github.com/redhat-developer/odo/pkg/util"

"github.com/pkg/errors"
)

const (
Expand All @@ -31,7 +31,7 @@ func checkoutProject(subDir, zipURL, path, starterToken string) error {
}
err := util.GetAndExtractZip(zipURL, path, subDir, starterToken)
if err != nil {
return errors.Wrap(err, "failed to download and extract project zip folder")
return fmt.Errorf("failed to download and extract project zip folder: %w", err)
}
return nil
}
Expand All @@ -42,7 +42,7 @@ func GetStarterProject(projects []devfilev1.StarterProject, projectPassed string
nOfProjects := len(projects)

if nOfProjects == 0 {
return nil, errors.Errorf("no starter project found in devfile.")
return nil, fmt.Errorf("no starter project found in devfile.")
}

// Determine what project to be used
Expand All @@ -65,7 +65,7 @@ func GetStarterProject(projects []devfilev1.StarterProject, projectPassed string

if !projectFound {
availableNamesString := strings.Join(availableNames, ",")
return nil, errors.Errorf("the project: %s specified in --starter does not exist, available projects: %s", projectPassed, availableNamesString)
return nil, fmt.Errorf("the project: %s specified in --starter does not exist, available projects: %s", projectPassed, availableNamesString)
}
}

Expand All @@ -82,7 +82,7 @@ func DownloadStarterProject(starterProject *devfilev1.StarterProject, decryptedT
if contextDir == "" {
path, err = os.Getwd()
if err != nil {
return errors.Wrapf(err, "Could not get the current working directory.")
return fmt.Errorf("Could not get the current working directory: %w", err)
}
} else {
path = contextDir
Expand Down Expand Up @@ -123,7 +123,7 @@ func DownloadStarterProject(starterProject *devfilev1.StarterProject, decryptedT
downloadSpinner.End(true)
}
} else {
return errors.Errorf("Project type not supported")
return errors.New("Project type not supported")
}

return nil
Expand All @@ -133,7 +133,7 @@ func DownloadStarterProject(starterProject *devfilev1.StarterProject, decryptedT
func downloadGitProject(starterProject *devfilev1.StarterProject, starterToken, path string, verbose bool) error {
remoteName, remoteUrl, revision, err := parsercommon.GetDefaultSource(starterProject.Git.GitLikeProjectSource)
if err != nil {
return errors.Wrapf(err, "unable to get default project source for starter project %s", starterProject.Name)
return fmt.Errorf("unable to get default project source for starter project %s: %w", starterProject.Name, err)
}

// convert revision to referenceName type, ref name could be a branch or tag
Expand Down
6 changes: 3 additions & 3 deletions pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package deploy

import (
"errors"
"fmt"
"strings"

"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/parser"
devfilefs "github.com/devfile/library/pkg/testingutil/filesystem"
"k8s.io/klog"

"github.com/pkg/errors"

"github.com/redhat-developer/odo/pkg/component"
componentlabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/devfile/image"
Expand Down Expand Up @@ -85,7 +85,7 @@ func (o *deployHandler) ApplyKubernetes(kubernetes v1alpha2.Component) error {
log.Infof("\nDeploying Kubernetes %s: %s", u.GetKind(), u.GetName())
isOperatorBackedService, err := service.PushKubernetesResource(o.kubeClient, u, labels, annotations)
if err != nil {
return errors.Wrap(err, "failed to create service(s) associated with the component")
return fmt.Errorf("failed to create service(s) associated with the component: %w", err)
}

if isOperatorBackedService {
Expand Down
4 changes: 2 additions & 2 deletions pkg/devfile/adapters/common/command.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package common

import (
"errors"
"fmt"
"reflect"
"strings"

devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/parser/data"
parsercommon "github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"github.com/pkg/errors"
"github.com/redhat-developer/odo/pkg/util"
"k8s.io/klog"
)
Expand All @@ -29,7 +29,7 @@ func New(devfile devfilev1.Command, knowCommands map[string]devfilev1.Command, e
if devfileCommand, ok := knowCommands[strings.ToLower(cmd)]; ok {
c, err := New(devfileCommand, knowCommands, executor)
if err != nil {
return nil, errors.Wrapf(err, "couldn't create command %s", cmd)
return nil, fmt.Errorf("couldn't create command %s: %w", cmd, err)
}
components = append(components, c)
} else {
Expand Down
Loading

0 comments on commit 19d432e

Please sign in to comment.