Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
bparees committed Feb 16, 2016
1 parent 9fa37b6 commit 3015746
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 46 deletions.
47 changes: 34 additions & 13 deletions pkg/generate/app/cmd/newapp.go
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"io"
"reflect"
"strings"
"time"

Expand All @@ -19,6 +20,7 @@ import (

authapi "github.com/openshift/origin/pkg/authorization/api"
buildapi "github.com/openshift/origin/pkg/build/api"
buildutil "github.com/openshift/origin/pkg/build/util"
"github.com/openshift/origin/pkg/client"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/dockerregistry"
Expand Down Expand Up @@ -678,19 +680,6 @@ func (c *AppConfig) buildPipelines(components app.ComponentReferences, environme
if c.NoOutput {
pipeline.Build.Output = nil
}
if err := pipeline.Validate(c.OriginNamespace); err != nil {
switch err.(type) {
case app.CircularOutputReferenceError:
if len(c.To) == 0 {
// Output reference was generated, return error.
return nil, err
}
// Output reference was explicitly provided, print warning.
fmt.Fprintf(c.ErrOut, "--> WARNING: %v\n", err)
default:
return nil, err
}
}
common = append(common, pipeline)
if err := common.Reduce(); err != nil {
return nil, fmt.Errorf("can't create a pipeline from %s: %v", common, err)
Expand Down Expand Up @@ -1105,6 +1094,19 @@ func (c *AppConfig) run(acceptors app.Acceptors) (*AppResult, error) {
}
}

err = c.checkCircularReferences(objects)
if err != nil {
if err, ok := err.(app.CircularOutputReferenceError); ok {
if len(c.To) == 0 {
// Output reference was generated, return error.
return nil, fmt.Errorf("%v, please specify a different output reference with --to", err)
}
// Output reference was explicitly provided, print warning.
fmt.Fprintf(c.ErrOut, "--> WARNING: %v\n", err)
}
return nil, err
}

return &AppResult{
List: &kapi.List{Items: objects},
Name: name,
Expand All @@ -1113,6 +1115,25 @@ func (c *AppConfig) run(acceptors app.Acceptors) (*AppResult, error) {
}, nil
}

// checkCircularReferences ensures there are no builds that can trigger themselves
// due to an imagechangetrigger that matches the output destination of the image.
func (c *AppConfig) checkCircularReferences(objects app.Objects) error {
for _, obj := range objects {
if bc, ok := obj.(*buildapi.BuildConfig); ok {
input := buildutil.GetImageStreamForStrategy(bc.Spec.Strategy)
if bc.Spec.Output.To != nil && input != nil &&
reflect.DeepEqual(input, bc.Spec.Output.To) {
ns := input.Namespace
if len(ns) == 0 {
ns = c.OriginNamespace
}
return app.CircularOutputReferenceError{Reference: fmt.Sprintf("%s/%s", ns, input.Name)}
}
}
}
return nil
}

func (c *AppConfig) Querying() bool {
return c.AsList || c.AsSearch
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/generate/app/errors.go
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"

cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"

imageapi "github.com/openshift/origin/pkg/image/api"
)

// ErrNoMatch is the error returned by new-app when no match is found for a
Expand Down Expand Up @@ -74,9 +72,9 @@ var ErrNameRequired = fmt.Errorf("you must specify a name for your app")
// CircularOutputReferenceError is the error returned by new-app when the input
// and output image stream tags are identical.
type CircularOutputReferenceError struct {
Reference imageapi.DockerImageReference
Reference string
}

func (e CircularOutputReferenceError) Error() string {
return fmt.Sprintf("the input and output image stream tags are identical (%q)", e.Reference.DockerClientDefaults())
return fmt.Sprintf("the input and output image stream tags are identical (%q)", e.Reference)
}
29 changes: 0 additions & 29 deletions pkg/generate/app/pipeline.go
Expand Up @@ -196,35 +196,6 @@ func (p *Pipeline) NeedsDeployment(env Environment, labels map[string]string, as
return nil
}

// Validate checks for logical errors in the pipeline.
func (p *Pipeline) Validate(defaultNamespace string) error {
if p == nil || p.Build == nil {
return nil
}
input, output := p.Build.Input, p.Build.Output
if input == nil || output == nil {
return nil
}
if input.AsImageStream && output.AsImageStream {
inName := input.ObjectName
inNamespace := defaultNamespace
if input.Stream != nil {
inName = input.Stream.Name
inNamespace = input.Stream.Namespace
}
outName := output.ObjectName
outNamespace := defaultNamespace
if output.Stream != nil {
outName = output.Stream.Name
outNamespace = output.Stream.Namespace
}
if inName == outName && inNamespace == outNamespace {
return CircularOutputReferenceError{Reference: output.Reference}
}
}
return nil
}

// Objects converts all the components in the pipeline into runtime objects.
func (p *Pipeline) Objects(accept, objectAccept Acceptor) (Objects, error) {
objects := Objects{}
Expand Down

0 comments on commit 3015746

Please sign in to comment.