diff --git a/pkg/generate/app/cmd/newapp.go b/pkg/generate/app/cmd/newapp.go index ae836c03bf9c..42d3409eea68 100644 --- a/pkg/generate/app/cmd/newapp.go +++ b/pkg/generate/app/cmd/newapp.go @@ -2,6 +2,7 @@ package cmd import ( "encoding/json" + "errors" "fmt" "io" "reflect" @@ -17,7 +18,7 @@ import ( kclient "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/kubectl/resource" "k8s.io/kubernetes/pkg/runtime" - "k8s.io/kubernetes/pkg/util/errors" + kutilerrors "k8s.io/kubernetes/pkg/util/errors" authapi "github.com/openshift/origin/pkg/authorization/api" buildapi "github.com/openshift/origin/pkg/build/api" @@ -42,7 +43,7 @@ const ( // ErrNoDockerfileDetected is the error returned when the requested build strategy is Docker // and no Dockerfile is detected in the repository. -var ErrNoDockerfileDetected = fmt.Errorf("No Dockerfile was found in the repository and the requested build strategy is 'docker'") +var ErrNoDockerfileDetected = errors.New("No Dockerfile was found in the repository and the requested build strategy is 'docker'") // GenerationInputs control how new-app creates output // TODO: split these into finer grained structs @@ -131,7 +132,7 @@ func (e ErrRequiresExplicitAccess) Error() string { } // ErrNoInputs is returned when no inputs are specified -var ErrNoInputs = fmt.Errorf("no inputs provided") +var ErrNoInputs = errors.New("no inputs provided") // AppResult contains the results of an application type AppResult struct { @@ -260,7 +261,7 @@ func (c *AppConfig) validateBuilders(components app.ComponentReferences) error { continue } } - return errors.NewAggregate(errs) + return kutilerrors.NewAggregate(errs) } func validateEnforcedName(name string) error { @@ -428,7 +429,7 @@ func (c *AppConfig) installComponents(components app.ComponentReferences, env ap var ok bool name, ok = imageRef.SuggestName() if !ok { - return nil, "", fmt.Errorf("can't suggest a valid name, please specify a name with --name") + return nil, "", errors.New("can't suggest a valid name, please specify a name with --name") } } imageRef.ObjectName = name @@ -495,10 +496,10 @@ func (c *AppConfig) RunQuery() (*QueryResult, error) { if c.AsList { if c.AsSearch { - return nil, fmt.Errorf("--list and --search can't be used together") + return nil, errors.New("--list and --search can't be used together") } if c.HasArguments() { - return nil, fmt.Errorf("--list can't be used with arguments") + return nil, errors.New("--list can't be used with arguments") } c.Components = append(c.Components, "*") } @@ -509,7 +510,7 @@ func (c *AppConfig) RunQuery() (*QueryResult, error) { } components, repositories, errs := b.Result() if len(errs) > 0 { - return nil, errors.NewAggregate(errs) + return nil, kutilerrors.NewAggregate(errs) } if len(components) == 0 && !c.AsList { @@ -517,16 +518,16 @@ func (c *AppConfig) RunQuery() (*QueryResult, error) { } if len(repositories) > 0 { - errs = append(errs, fmt.Errorf("--search can't be used with source code")) + errs = append(errs, errors.New("--search can't be used with source code")) } if len(environment) > 0 { - errs = append(errs, fmt.Errorf("--search can't be used with --env")) + errs = append(errs, errors.New("--search can't be used with --env")) } if len(parameters) > 0 { - errs = append(errs, fmt.Errorf("--search can't be used with --param")) + errs = append(errs, errors.New("--search can't be used with --param")) } if len(errs) > 0 { - return nil, errors.NewAggregate(errs) + return nil, kutilerrors.NewAggregate(errs) } if err := components.Search(); err != nil { @@ -574,7 +575,7 @@ func (c *AppConfig) validate() (cmdutil.Environment, cmdutil.Environment, error) } errs = append(errs, paramsErrs...) - return env, params, errors.NewAggregate(errs) + return env, params, kutilerrors.NewAggregate(errs) } // Run executes the provided config to generate objects. @@ -621,10 +622,10 @@ func (c *AppConfig) Run() (*AppResult, error) { } if len(components.ImageComponentRefs().Group()) > 1 && len(c.Name) > 0 { - return nil, fmt.Errorf("only one component or source repository can be used when specifying a name") + return nil, errors.New("only one component or source repository can be used when specifying a name") } if len(components.UseSource()) > 1 && len(c.To) > 0 { - return nil, fmt.Errorf("only one component with source can be used when specifying an output image reference") + return nil, errors.New("only one component with source can be used when specifying an output image reference") } env := app.Environment(environment) @@ -647,7 +648,7 @@ func (c *AppConfig) Run() (*AppResult, error) { pipelines, err := c.buildPipelines(components.ImageComponentRefs(), env) if err != nil { if err == app.ErrNameRequired { - return nil, fmt.Errorf("can't suggest a valid name, please specify a name with --name") + return nil, errors.New("can't suggest a valid name, please specify a name with --name") } return nil, err } @@ -730,7 +731,7 @@ func (c *AppConfig) Run() (*AppResult, error) { func (c *AppConfig) followRefToDockerImage(ref *kapi.ObjectReference, isContext *imageapi.ImageStream, objects app.Objects) (*kapi.ObjectReference, error) { if ref == nil { - return nil, fmt.Errorf("Unable to follow nil") + return nil, errors.New("Unable to follow nil") } if ref.Kind == "DockerImage" { diff --git a/pkg/generate/app/cmd/resolve.go b/pkg/generate/app/cmd/resolve.go index 433d054d095d..c2e746aa148b 100644 --- a/pkg/generate/app/cmd/resolve.go +++ b/pkg/generate/app/cmd/resolve.go @@ -1,11 +1,12 @@ package cmd import ( + "errors" "fmt" "strings" "github.com/golang/glog" - "k8s.io/kubernetes/pkg/util/errors" + kutilerrors "k8s.io/kubernetes/pkg/util/errors" "github.com/openshift/origin/pkg/generate/app" dockerfileutil "github.com/openshift/origin/pkg/util/docker/dockerfile" @@ -97,7 +98,7 @@ func Resolve(r *Resolvers, c *ComponentInputs, g *GenerationInputs) (*ResolvedCo } components, repositories, errs := b.Result() if len(errs) > 0 { - return nil, errors.NewAggregate(errs) + return nil, kutilerrors.NewAggregate(errs) } // TODO: the second half of this method is potentially splittable - each chunk below amends or qualifies @@ -110,11 +111,11 @@ func Resolve(r *Resolvers, c *ComponentInputs, g *GenerationInputs) (*ResolvedCo } if len(g.Strategy) != 0 && len(repositories) == 0 && !g.BinaryBuild { - return nil, fmt.Errorf("when --strategy is specified you must provide at least one source code location") + return nil, errors.New("when --strategy is specified you must provide at least one source code location") } if g.BinaryBuild && (len(repositories) > 0 || components.HasSource()) { - return nil, fmt.Errorf("specifying binary builds and source repositories at the same time is not allowed") + return nil, errors.New("specifying binary builds and source repositories at the same time is not allowed") } // Add source components if source-image points to another location @@ -186,21 +187,21 @@ func AddSourceRepositoriesToRefBuilder(b *app.ReferenceBuilder, repos []string, } if len(g.Dockerfile) > 0 { if len(g.Strategy) != 0 && g.Strategy != "docker" { - return nil, fmt.Errorf("when directly referencing a Dockerfile, the strategy must must be 'docker'") + return nil, errors.New("when directly referencing a Dockerfile, the strategy must must be 'docker'") } if err := AddDockerfileToSourceRepositories(b, g.Dockerfile); err != nil { return nil, err } } _, result, errs := b.Result() - return result, errors.NewAggregate(errs) + return result, kutilerrors.NewAggregate(errs) } // AddDockerfile adds a Dockerfile passed in the command line to the reference // builder. func AddDockerfileToSourceRepositories(b *app.ReferenceBuilder, dockerfile string) error { _, repos, errs := b.Result() - if err := errors.NewAggregate(errs); err != nil { + if err := kutilerrors.NewAggregate(errs); err != nil { return err } switch len(repos) { @@ -220,7 +221,7 @@ func AddDockerfileToSourceRepositories(b *app.ReferenceBuilder, dockerfile strin } default: // Invalid. - return fmt.Errorf("--dockerfile cannot be used with multiple source repositories") + return errors.New("--dockerfile cannot be used with multiple source repositories") } return nil } @@ -239,7 +240,7 @@ func DetectSource(repositories []*app.SourceRepository, d app.Detector, g *Gener continue } } - return errors.NewAggregate(errs) + return kutilerrors.NewAggregate(errs) } // AddComponentInputsToRefBuilder set up the components to be used by the reference builder. @@ -353,7 +354,7 @@ func AddImageSourceRepository(sourceRepos app.SourceRepositories, r app.Resolver sourceRepos[0].SetSourceImage(compRef) sourceRepos[0].SetSourceImagePath(sourcePath, destPath) default: - return nil, nil, fmt.Errorf("--image-source cannot be used with multiple source repositories") + return nil, nil, errors.New("--image-source cannot be used with multiple source repositories") } return compRef, sourceRepos, nil @@ -367,7 +368,7 @@ func detectPartialMatches(components app.ComponentReferences) error { errs = append(errs, fmt.Errorf("component %q had only a partial match of %q - if this is the value you want to use, specify it explicitly", input.From, input.ResolvedMatch.Name)) } } - return errors.NewAggregate(errs) + return kutilerrors.NewAggregate(errs) } // InferBuildTypes infers build status and mismatches between source and docker builders @@ -398,13 +399,13 @@ func InferBuildTypes(components app.ComponentReferences, g *GenerationInputs) (a switch { case input.ExpectToBuild && input.ResolvedMatch.IsTemplate(): // TODO: harder - break the template pieces and check if source code can be attached (look for a build config, build image, etc) - errs = append(errs, fmt.Errorf("template with source code explicitly attached is not supported - you must either specify the template and source code separately or attach an image to the source code using the '[image]~[code]' form")) + errs = append(errs, errors.New("template with source code explicitly attached is not supported - you must either specify the template and source code separately or attach an image to the source code using the '[image]~[code]' form")) continue } } if len(components) == 0 && g.BinaryBuild { if len(g.Name) == 0 { - return nil, fmt.Errorf("you must provide a --name when you don't specify a source repository or base image") + return nil, errors.New("you must provide a --name when you don't specify a source repository or base image") } ref := &app.ComponentInput{ From: "--binary", @@ -416,7 +417,7 @@ func InferBuildTypes(components app.ComponentReferences, g *GenerationInputs) (a components = append(components, ref) } - return components, errors.NewAggregate(errs) + return components, kutilerrors.NewAggregate(errs) } // EnsureHasSource ensure every builder component has source code associated with it. It takes a list of component references @@ -470,7 +471,7 @@ func EnsureHasSource(components app.ComponentReferences, repositories app.Source input.ExpectToBuild = true } case g.ExpectToBuild: - return fmt.Errorf("you must specify at least one source repository URL, provide a Dockerfile, or indicate you wish to use binary builds") + return errors.New("you must specify at least one source repository URL, provide a Dockerfile, or indicate you wish to use binary builds") default: for _, component := range components { component.Input().ExpectToBuild = false @@ -529,5 +530,5 @@ func AddMissingComponentsToRefBuilder( result = append(result, refs...) } } - return result, errors.NewAggregate(errs) + return result, kutilerrors.NewAggregate(errs) } diff --git a/pkg/generate/app/sourcelookup.go b/pkg/generate/app/sourcelookup.go index fdc4a99a3157..52fa75789f06 100644 --- a/pkg/generate/app/sourcelookup.go +++ b/pkg/generate/app/sourcelookup.go @@ -1,6 +1,7 @@ package app import ( + "errors" "fmt" "io/ioutil" "net/url" @@ -38,7 +39,7 @@ func NewDockerfileFromFile(path string) (Dockerfile, error) { func NewDockerfile(contents string) (Dockerfile, error) { if len(contents) == 0 { - return nil, fmt.Errorf("Dockerfile is empty") + return nil, errors.New("Dockerfile is empty") } node, err := parser.Parse(strings.NewReader(contents)) if err != nil { @@ -428,7 +429,7 @@ type SourceRepositoryEnumerator struct { // ErrNoLanguageDetected is the error returned when no language can be detected by all // source code detectors. -var ErrNoLanguageDetected = fmt.Errorf("No language matched the source repository") +var ErrNoLanguageDetected = errors.New("No language matched the source repository") // Detect extracts source code information about the provided source repository func (e SourceRepositoryEnumerator) Detect(dir string, dockerStrategy bool) (*SourceRepositoryInfo, error) { @@ -506,7 +507,7 @@ func StrategyAndSourceForRepository(repo *SourceRepository, image *ImageRef) (*B return strategy, source, nil } -// CloneAndCheckoutSources clones the remote repository using either regulare +// CloneAndCheckoutSources clones the remote repository using either regular // git clone operation or shallow git clone, based on the "ref" provided (you // cannot shallow clone using the 'ref'). // This function will return the full path to the buildable sources, including diff --git a/pkg/generate/git/repository.go b/pkg/generate/git/repository.go index d288ff99b39f..e1d496f801a9 100644 --- a/pkg/generate/git/repository.go +++ b/pkg/generate/git/repository.go @@ -3,6 +3,7 @@ package git import ( "bufio" "bytes" + "errors" "fmt" "io" "os" @@ -56,7 +57,7 @@ const ( // ErrGitNotAvailable will be returned if the git call fails because a git binary // could not be found -var ErrGitNotAvailable = fmt.Errorf("git binary not available") +var ErrGitNotAvailable = errors.New("git binary not available") // SourceInfo stores information about the source code type SourceInfo struct { @@ -270,7 +271,7 @@ func (r *repository) Archive(location, ref, format string, w io.Writer) error { // Checkout switches to the given ref for the git repository func (r *repository) Checkout(location string, ref string) error { if r.shallow { - return fmt.Errorf("cannot checkout ref on shallow clone") + return errors.New("cannot checkout ref on shallow clone") } _, _, err := r.git(location, "checkout", ref) return err