Skip to content

Commit

Permalink
prevent go panic when output not specified for build config
Browse files Browse the repository at this point in the history
  • Loading branch information
gabemontero committed Nov 18, 2015
1 parent 0411059 commit 61fc0d1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/api/graph/test/bc-missing-output.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: BuildConfig
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp: 2015-11-18T14:41:17Z
labels:
app: gitauthtest
template: gitserver
name: gitauthtest
namespace: devproj
resourceVersion: "634"
selfLink: /oapi/v1/namespaces/devproj/buildconfigs/gitauthtest
uid: 6d487478-8e02-11e5-9cf2-3c970e88b00e
spec:
output: {}
resources: {}
source:
git:
uri: http://gitserver-tokenauth.linux.xip.io/ruby-hello-world
sourceSecret:
name: builder-token-nbme5
type: Git
strategy:
sourceStrategy:
from:
kind: ImageStreamTag
name: ruby:latest
namespace: openshift
type: Source
triggers: []
status:
lastVersion: 1
10 changes: 10 additions & 0 deletions pkg/build/graph/analysis/bc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ func TestPushableBuild(t *testing.T) {
}
}

func TestBuildConfigNoOutput(t *testing.T) {
g, _, err := osgraphtest.BuildGraph("../../../api/graph/test/bc-missing-output.yaml")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

// we were getting go panics with nil refs cause output destinations are not required for BuildConfigs
buildedges.AddAllInputOutputEdges(g)
}

func TestCircularDeps(t *testing.T) {
g, _, err := osgraphtest.BuildGraph("../../../api/graph/test/circular.yaml")
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/build/graph/edges.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func imageRefNode(g osgraph.MutableUniqueGraph, ref *kapi.ObjectReference, bc *b

// AddOutputEdges links the build config to its output image node.
func AddOutputEdges(g osgraph.MutableUniqueGraph, node *buildgraph.BuildConfigNode) {
if node.BuildConfig.Spec.Output.To == nil {
return
}
out := imageRefNode(g, node.BuildConfig.Spec.Output.To, node.BuildConfig)
g.AddEdge(node, out, BuildOutputEdgeKind)
}
Expand Down

0 comments on commit 61fc0d1

Please sign in to comment.